1
+ require ( './helper' ) ;
2
+
3
+ var fs = require ( 'fs' ) ;
4
+ var path = require ( 'path' ) ;
5
+ var specsDir = path . join ( __dirname , 'spec/specs' ) ;
6
+
7
+ var skipTests = {
8
+ comments : [
9
+ 'Standalone Without Newline'
10
+ ] ,
11
+ delimiters : [
12
+ 'Standalone Without Newline'
13
+ ] ,
14
+ inverted : [
15
+ 'Standalone Without Newline'
16
+ ] ,
17
+ partials : [
18
+ 'Standalone Without Previous Line' ,
19
+ 'Standalone Without Newline' ,
20
+ 'Standalone Indentation'
21
+ ] ,
22
+ sections : [
23
+ 'Standalone Without Newline'
24
+ ] ,
25
+ '~lambdas' : [
26
+ 'Interpolation' ,
27
+ 'Interpolation - Expansion' ,
28
+ 'Interpolation - Alternate Delimiters' ,
29
+ 'Interpolation - Multiple Calls' ,
30
+ 'Escaping' ,
31
+ 'Section - Expansion' ,
32
+ 'Section - Alternate Delimiters'
33
+ ]
34
+ } ;
35
+
36
+ // You can run the skiped tests by setting the NOSKIP environment variable to
37
+ // true (e.g. NOSKIP=true mocha test/mustache-spec-test.js)
38
+ var noSkip = process . env . NOSKIP ;
39
+
40
+ // You can put the name of a specific test file to run in the TEST environment
41
+ // variable (e.g. TEST=interpolation mocha test/mustache-spec-test.js)
42
+ var fileToRun = process . env . TEST ;
43
+
44
+ // Mustache should work on node 0.6 that doesn't have fs.exisisSync
45
+ function existsDir ( path ) {
46
+ try {
47
+ return fs . statSync ( path ) . isDirectory ( ) ;
48
+ } catch ( x ) {
49
+ return false ;
50
+ }
51
+ }
52
+
53
+ var specFiles ;
54
+ if ( fileToRun ) {
55
+ specFiles = [ fileToRun ] ;
56
+ } else if ( existsDir ( specsDir ) ) {
57
+ specFiles = fs . readdirSync ( specsDir ) . filter ( function ( file ) {
58
+ return ( / \. j s o n $ / ) . test ( file ) ;
59
+ } ) . map ( function ( file ) {
60
+ return path . basename ( file ) . replace ( / \. j s o n $ / , '' ) ;
61
+ } ) . sort ( ) ;
62
+ } else {
63
+ specFiles = [ ] ;
64
+ }
65
+
66
+ function getSpecs ( specArea ) {
67
+ return JSON . parse ( fs . readFileSync ( path . join ( specsDir , specArea + '.' + 'json' ) , 'utf8' ) ) ;
68
+ }
69
+
70
+ describe ( 'Mustache spec compliance' , function ( ) {
71
+ beforeEach ( function ( ) {
72
+ Mustache . clearCache ( ) ;
73
+ } ) ;
74
+
75
+ specFiles . forEach ( function ( specArea ) {
76
+ describe ( '- ' + specArea + ':' , function ( ) {
77
+ var specs = getSpecs ( specArea ) ;
78
+ specs . tests . forEach ( function ( test ) {
79
+ var it_ = ( ! noSkip && skipTests [ specArea ] && skipTests [ specArea ] . indexOf ( test . name ) >= 0 ) ? it . skip : it ;
80
+ it_ ( test . name + ' - ' + test . desc , function ( ) {
81
+ if ( test . data . lambda && test . data . lambda . __tag__ === 'code' )
82
+ test . data . lambda = eval ( '(function() { return ' + test . data . lambda . js + '; })' ) ;
83
+ var output = Mustache . render ( test . template , test . data , test . partials ) ;
84
+ assert . equal ( output , test . expected ) ;
85
+ } ) ;
86
+ } ) ;
87
+ } ) ;
88
+ } ) ;
89
+ } ) ;
0 commit comments