@@ -3,6 +3,8 @@ describe('ast', function() {
3
3
return ;
4
4
}
5
5
6
+ var AST = Handlebars . AST ;
7
+
6
8
var LOCATION_INFO = {
7
9
start : {
8
10
line : 1 ,
@@ -23,7 +25,7 @@ describe('ast', function() {
23
25
24
26
describe ( 'MustacheStatement' , function ( ) {
25
27
it ( 'should store args' , function ( ) {
26
- var mustache = new handlebarsEnv . AST . MustacheStatement ( { } , null , null , true , { } , LOCATION_INFO ) ;
28
+ var mustache = new AST . MustacheStatement ( { } , null , null , true , { } , LOCATION_INFO ) ;
27
29
equals ( mustache . type , 'MustacheStatement' ) ;
28
30
equals ( mustache . escaped , true ) ;
29
31
testLocationInfoStorage ( mustache ) ;
@@ -37,8 +39,8 @@ describe('ast', function() {
37
39
} ) ;
38
40
39
41
it ( 'stores location info' , function ( ) {
40
- var mustacheNode = new handlebarsEnv . AST . MustacheStatement ( [ { original : 'foo' } ] , null , null , false , { } ) ;
41
- var block = new handlebarsEnv . AST . BlockStatement (
42
+ var mustacheNode = new AST . MustacheStatement ( [ { original : 'foo' } ] , null , null , false , { } ) ;
43
+ var block = new AST . BlockStatement (
42
44
mustacheNode ,
43
45
null , null ,
44
46
{ body : [ ] } ,
@@ -52,78 +54,114 @@ describe('ast', function() {
52
54
} ) ;
53
55
describe ( 'PathExpression' , function ( ) {
54
56
it ( 'stores location info' , function ( ) {
55
- var idNode = new handlebarsEnv . AST . PathExpression ( false , 0 , [ ] , 'foo' , LOCATION_INFO ) ;
57
+ var idNode = new AST . PathExpression ( false , 0 , [ ] , 'foo' , LOCATION_INFO ) ;
56
58
testLocationInfoStorage ( idNode ) ;
57
59
} ) ;
58
60
} ) ;
59
61
60
62
describe ( 'Hash' , function ( ) {
61
63
it ( 'stores location info' , function ( ) {
62
- var hash = new handlebarsEnv . AST . Hash ( [ ] , LOCATION_INFO ) ;
64
+ var hash = new AST . Hash ( [ ] , LOCATION_INFO ) ;
63
65
testLocationInfoStorage ( hash ) ;
64
66
} ) ;
65
67
} ) ;
66
68
67
69
describe ( 'ContentStatement' , function ( ) {
68
70
it ( 'stores location info' , function ( ) {
69
- var content = new handlebarsEnv . AST . ContentStatement ( 'HI' , LOCATION_INFO ) ;
71
+ var content = new AST . ContentStatement ( 'HI' , LOCATION_INFO ) ;
70
72
testLocationInfoStorage ( content ) ;
71
73
} ) ;
72
74
} ) ;
73
75
74
76
describe ( 'CommentStatement' , function ( ) {
75
77
it ( 'stores location info' , function ( ) {
76
- var comment = new handlebarsEnv . AST . CommentStatement ( 'HI' , { } , LOCATION_INFO ) ;
78
+ var comment = new AST . CommentStatement ( 'HI' , { } , LOCATION_INFO ) ;
77
79
testLocationInfoStorage ( comment ) ;
78
80
} ) ;
79
81
} ) ;
80
82
81
83
describe ( 'NumberLiteral' , function ( ) {
82
84
it ( 'stores location info' , function ( ) {
83
- var integer = new handlebarsEnv . AST . NumberLiteral ( '6' , LOCATION_INFO ) ;
85
+ var integer = new AST . NumberLiteral ( '6' , LOCATION_INFO ) ;
84
86
testLocationInfoStorage ( integer ) ;
85
87
} ) ;
86
88
} ) ;
87
89
88
90
describe ( 'StringLiteral' , function ( ) {
89
91
it ( 'stores location info' , function ( ) {
90
- var string = new handlebarsEnv . AST . StringLiteral ( '6' , LOCATION_INFO ) ;
92
+ var string = new AST . StringLiteral ( '6' , LOCATION_INFO ) ;
91
93
testLocationInfoStorage ( string ) ;
92
94
} ) ;
93
95
} ) ;
94
96
95
97
describe ( 'BooleanLiteral' , function ( ) {
96
98
it ( 'stores location info' , function ( ) {
97
- var bool = new handlebarsEnv . AST . BooleanLiteral ( 'true' , LOCATION_INFO ) ;
99
+ var bool = new AST . BooleanLiteral ( 'true' , LOCATION_INFO ) ;
98
100
testLocationInfoStorage ( bool ) ;
99
101
} ) ;
100
102
} ) ;
101
103
102
104
describe ( 'PartialStatement' , function ( ) {
103
105
it ( 'provides default params' , function ( ) {
104
- var pn = new handlebarsEnv . AST . PartialStatement ( 'so_partial' , undefined , { } , { } , LOCATION_INFO ) ;
106
+ var pn = new AST . PartialStatement ( 'so_partial' , undefined , { } , { } , LOCATION_INFO ) ;
105
107
equals ( pn . params . length , 0 ) ;
106
108
} ) ;
107
109
it ( 'stores location info' , function ( ) {
108
- var pn = new handlebarsEnv . AST . PartialStatement ( 'so_partial' , [ ] , { } , { } , LOCATION_INFO ) ;
110
+ var pn = new AST . PartialStatement ( 'so_partial' , [ ] , { } , { } , LOCATION_INFO ) ;
109
111
testLocationInfoStorage ( pn ) ;
110
112
} ) ;
111
113
} ) ;
112
114
113
115
describe ( 'Program' , function ( ) {
114
116
it ( 'storing location info' , function ( ) {
115
- var pn = new handlebarsEnv . AST . Program ( [ ] , null , { } , LOCATION_INFO ) ;
117
+ var pn = new AST . Program ( [ ] , null , { } , LOCATION_INFO ) ;
116
118
testLocationInfoStorage ( pn ) ;
117
119
} ) ;
118
120
} ) ;
119
121
120
122
describe ( 'SubExpression' , function ( ) {
121
123
it ( 'provides default params' , function ( ) {
122
- var pn = new handlebarsEnv . AST . SubExpression ( 'path' , undefined , { } , LOCATION_INFO ) ;
124
+ var pn = new AST . SubExpression ( 'path' , undefined , { } , LOCATION_INFO ) ;
123
125
equals ( pn . params . length , 0 ) ;
124
126
} ) ;
125
127
} ) ;
126
128
129
+ describe ( 'helpers' , function ( ) {
130
+ describe ( '#helperExpression' , function ( ) {
131
+ it ( 'should handle mustache statements' , function ( ) {
132
+ equals ( AST . helpers . helperExpression ( new AST . MustacheStatement ( 'foo' , [ ] , undefined , false , { } , LOCATION_INFO ) ) , false ) ;
133
+ equals ( AST . helpers . helperExpression ( new AST . MustacheStatement ( 'foo' , [ 1 ] , undefined , false , { } , LOCATION_INFO ) ) , true ) ;
134
+ equals ( AST . helpers . helperExpression ( new AST . MustacheStatement ( 'foo' , [ ] , { } , false , { } , LOCATION_INFO ) ) , true ) ;
135
+ } ) ;
136
+ it ( 'should handle block statements' , function ( ) {
137
+ equals ( AST . helpers . helperExpression ( new AST . BlockStatement ( 'foo' , [ ] , undefined , false , { } , LOCATION_INFO ) ) , false ) ;
138
+ equals ( AST . helpers . helperExpression ( new AST . BlockStatement ( 'foo' , [ 1 ] , undefined , false , { } , LOCATION_INFO ) ) , true ) ;
139
+ equals ( AST . helpers . helperExpression ( new AST . BlockStatement ( 'foo' , [ ] , { } , false , { } , LOCATION_INFO ) ) , true ) ;
140
+ } ) ;
141
+ it ( 'should handle subexpressions' , function ( ) {
142
+ equals ( AST . helpers . helperExpression ( new AST . SubExpression ( ) ) , true ) ;
143
+ } ) ;
144
+ it ( 'should work with non-helper nodes' , function ( ) {
145
+ equals ( AST . helpers . helperExpression ( new AST . Program ( [ ] , [ ] , { } , LOCATION_INFO ) ) , false ) ;
146
+
147
+ equals ( AST . helpers . helperExpression ( new AST . PartialStatement ( ) ) , false ) ;
148
+ equals ( AST . helpers . helperExpression ( new AST . ContentStatement ( 'a' , LOCATION_INFO ) ) , false ) ;
149
+ equals ( AST . helpers . helperExpression ( new AST . CommentStatement ( 'a' , { } , LOCATION_INFO ) ) , false ) ;
150
+
151
+ equals ( AST . helpers . helperExpression ( new AST . PathExpression ( false , 0 , [ 'a' ] , 'a' , LOCATION_INFO ) ) , false ) ;
152
+
153
+ equals ( AST . helpers . helperExpression ( new AST . StringLiteral ( 'a' , LOCATION_INFO ) ) , false ) ;
154
+ equals ( AST . helpers . helperExpression ( new AST . NumberLiteral ( 1 , LOCATION_INFO ) ) , false ) ;
155
+ equals ( AST . helpers . helperExpression ( new AST . BooleanLiteral ( true , LOCATION_INFO ) ) , false ) ;
156
+ equals ( AST . helpers . helperExpression ( new AST . UndefinedLiteral ( LOCATION_INFO ) ) , false ) ;
157
+ equals ( AST . helpers . helperExpression ( new AST . NullLiteral ( LOCATION_INFO ) ) , false ) ;
158
+
159
+ equals ( AST . helpers . helperExpression ( new AST . Hash ( [ ] , LOCATION_INFO ) ) , false ) ;
160
+ equals ( AST . helpers . helperExpression ( new AST . HashPair ( 'foo' , 'bar' , LOCATION_INFO ) ) , false ) ;
161
+ } ) ;
162
+ } ) ;
163
+ } ) ;
164
+
127
165
describe ( 'Line Numbers' , function ( ) {
128
166
var ast , body ;
129
167
0 commit comments