@@ -15,15 +15,19 @@ describe('basic context', function() {
15
15
expectTemplate ( '\\{{foo}}' )
16
16
. withInput ( { foo : 'food' } )
17
17
. toCompileTo ( '{{foo}}' ) ;
18
+
18
19
expectTemplate ( 'content \\{{foo}}' )
19
20
. withInput ( { foo : 'food' } )
20
21
. toCompileTo ( 'content {{foo}}' ) ;
22
+
21
23
expectTemplate ( '\\\\{{foo}}' )
22
24
. withInput ( { foo : 'food' } )
23
25
. toCompileTo ( '\\food' ) ;
26
+
24
27
expectTemplate ( 'content \\\\{{foo}}' )
25
28
. withInput ( { foo : 'food' } )
26
29
. toCompileTo ( 'content \\food' ) ;
30
+
27
31
expectTemplate ( '\\\\ {{foo}}' )
28
32
. withInput ( { foo : 'food' } )
29
33
. toCompileTo ( '\\\\ food' ) ;
@@ -65,14 +69,19 @@ describe('basic context', function() {
65
69
. toCompileTo ( 'Goodbye\ncruel\nworld!' ) ;
66
70
67
71
expectTemplate ( ' {{~! comment ~}} blah' ) . toCompileTo ( 'blah' ) ;
72
+
68
73
expectTemplate ( ' {{~!-- long-comment --~}} blah' ) . toCompileTo (
69
74
'blah'
70
75
) ;
76
+
71
77
expectTemplate ( ' {{! comment ~}} blah' ) . toCompileTo ( ' blah' ) ;
78
+
72
79
expectTemplate ( ' {{!-- long-comment --~}} blah' ) . toCompileTo (
73
80
' blah'
74
81
) ;
82
+
75
83
expectTemplate ( ' {{~! comment}} blah' ) . toCompileTo ( ' blah' ) ;
84
+
76
85
expectTemplate ( ' {{~!-- long-comment --}} blah' ) . toCompileTo (
77
86
' blah'
78
87
) ;
@@ -104,13 +113,16 @@ describe('basic context', function() {
104
113
num2 : 0
105
114
} )
106
115
. toCompileTo ( 'num1: 42, num2: 0' ) ;
116
+
107
117
expectTemplate ( 'num: {{.}}' )
108
118
. withInput ( 0 )
109
119
. toCompileTo ( 'num: 0' ) ;
120
+
110
121
expectTemplate ( 'num: {{num1/num2}}' )
111
122
. withInput ( { num1 : { num2 : 0 } } )
112
123
. toCompileTo ( 'num: 0' ) ;
113
124
} ) ;
125
+
114
126
it ( 'false' , function ( ) {
115
127
/* eslint-disable no-new-wrappers */
116
128
expectTemplate ( 'val1: {{val1}}, val2: {{val2}}' )
@@ -119,9 +131,11 @@ describe('basic context', function() {
119
131
val2 : new Boolean ( false )
120
132
} )
121
133
. toCompileTo ( 'val1: false, val2: false' ) ;
134
+
122
135
expectTemplate ( 'val: {{.}}' )
123
136
. withInput ( false )
124
137
. toCompileTo ( 'val: false' ) ;
138
+
125
139
expectTemplate ( 'val: {{val1/val2}}' )
126
140
. withInput ( { val1 : { val2 : false } } )
127
141
. toCompileTo ( 'val: false' ) ;
@@ -132,6 +146,7 @@ describe('basic context', function() {
132
146
val2 : new Boolean ( false )
133
147
} )
134
148
. toCompileTo ( 'val1: false, val2: false' ) ;
149
+
135
150
expectTemplate ( 'val: {{{val1/val2}}}' )
136
151
. withInput ( { val1 : { val2 : false } } )
137
152
. toCompileTo ( 'val: false' ) ;
@@ -152,13 +167,15 @@ describe('basic context', function() {
152
167
}
153
168
} )
154
169
. toCompileTo ( 'true true object' ) ;
170
+
155
171
expectTemplate ( '{{undefined}}' )
156
172
. withInput ( {
157
173
undefined : function ( ) {
158
174
return 'undefined!' ;
159
175
}
160
176
} )
161
177
. toCompileTo ( 'undefined!' ) ;
178
+
162
179
expectTemplate ( '{{null}}' )
163
180
. withInput ( {
164
181
null : function ( ) {
@@ -170,6 +187,7 @@ describe('basic context', function() {
170
187
171
188
it ( 'newlines' , function ( ) {
172
189
expectTemplate ( "Alan's\nTest" ) . toCompileTo ( "Alan's\nTest" ) ;
190
+
173
191
expectTemplate ( "Alan's\rTest" ) . toCompileTo ( "Alan's\rTest" ) ;
174
192
} ) ;
175
193
@@ -179,16 +197,20 @@ describe('basic context', function() {
179
197
"text is escaped so that it doesn't get caught on single quotes"
180
198
)
181
199
. toCompileTo ( "Awesome's" ) ;
200
+
182
201
expectTemplate ( 'Awesome\\' )
183
202
. withMessage ( "text is escaped so that the closing quote can't be ignored" )
184
203
. toCompileTo ( 'Awesome\\' ) ;
204
+
185
205
expectTemplate ( 'Awesome\\\\ foo' )
186
206
. withMessage ( "text is escaped so that it doesn't mess up backslashes" )
187
207
. toCompileTo ( 'Awesome\\\\ foo' ) ;
208
+
188
209
expectTemplate ( 'Awesome {{foo}}' )
189
210
. withInput ( { foo : '\\' } )
190
211
. withMessage ( "text is escaped so that it doesn't mess up backslashes" )
191
212
. toCompileTo ( 'Awesome \\' ) ;
213
+
192
214
expectTemplate ( " ' ' " )
193
215
. withMessage ( 'double quotes never produce invalid javascript' )
194
216
. toCompileTo ( " ' ' " ) ;
@@ -217,13 +239,12 @@ describe('basic context', function() {
217
239
} ) ;
218
240
219
241
it ( "functions returning safestrings shouldn't be escaped" , function ( ) {
220
- var hash = {
221
- awesome : function ( ) {
222
- return new Handlebars . SafeString ( "&'\\<>" ) ;
223
- }
224
- } ;
225
242
expectTemplate ( '{{awesome}}' )
226
- . withInput ( hash )
243
+ . withInput ( {
244
+ awesome : function ( ) {
245
+ return new Handlebars . SafeString ( "&'\\<>" ) ;
246
+ }
247
+ } )
227
248
. withMessage ( "functions returning safestrings aren't escaped" )
228
249
. toCompileTo ( "&'\\<>" ) ;
229
250
} ) ;
@@ -237,6 +258,7 @@ describe('basic context', function() {
237
258
} )
238
259
. withMessage ( 'functions are called and render their output' )
239
260
. toCompileTo ( 'Awesome' ) ;
261
+
240
262
expectTemplate ( '{{awesome}}' )
241
263
. withInput ( {
242
264
awesome : function ( ) {
@@ -259,6 +281,7 @@ describe('basic context', function() {
259
281
. withMessage ( 'functions are called with context arguments' )
260
282
. toCompileTo ( 'Frank' ) ;
261
283
} ) ;
284
+
262
285
it ( 'pathed functions with context argument' , function ( ) {
263
286
expectTemplate ( '{{bar.awesome frank}}' )
264
287
. withInput ( {
@@ -272,6 +295,7 @@ describe('basic context', function() {
272
295
. withMessage ( 'functions are called with context arguments' )
273
296
. toCompileTo ( 'Frank' ) ;
274
297
} ) ;
298
+
275
299
it ( 'depthed functions with context argument' , function ( ) {
276
300
expectTemplate ( '{{#with frank}}{{../awesome .}}{{/with}}' )
277
301
. withInput ( {
@@ -319,6 +343,7 @@ describe('basic context', function() {
319
343
. withMessage ( 'block functions are called with options' )
320
344
. toCompileTo ( 'inner' ) ;
321
345
} ) ;
346
+
322
347
it ( 'pathed block functions without context argument' , function ( ) {
323
348
expectTemplate ( '{{#foo.awesome}}inner{{/foo.awesome}}' )
324
349
. withInput ( {
@@ -331,6 +356,7 @@ describe('basic context', function() {
331
356
. withMessage ( 'block functions are called with options' )
332
357
. toCompileTo ( 'inner' ) ;
333
358
} ) ;
359
+
334
360
it ( 'depthed block functions without context argument' , function ( ) {
335
361
expectTemplate (
336
362
'{{#with value}}{{#../awesome}}inner{{/../awesome}}{{/with}}'
@@ -350,10 +376,12 @@ describe('basic context', function() {
350
376
. withInput ( { 'foo-bar' : 'baz' } )
351
377
. withMessage ( 'Paths can contain hyphens (-)' )
352
378
. toCompileTo ( 'baz' ) ;
379
+
353
380
expectTemplate ( '{{foo.foo-bar}}' )
354
381
. withInput ( { foo : { 'foo-bar' : 'baz' } } )
355
382
. withMessage ( 'Paths can contain hyphens (-)' )
356
383
. toCompileTo ( 'baz' ) ;
384
+
357
385
expectTemplate ( '{{foo/foo-bar}}' )
358
386
. withInput ( { foo : { 'foo-bar' : 'baz' } } )
359
387
. withMessage ( 'Paths can contain hyphens (-)' )
@@ -379,6 +407,7 @@ describe('basic context', function() {
379
407
. withInput ( { '@alan' : { expression : 'beautiful' } } )
380
408
. withMessage ( 'Literal paths can be used' )
381
409
. toCompileTo ( 'Goodbye beautiful world!' ) ;
410
+
382
411
expectTemplate ( 'Goodbye {{[foo bar]/expression}} world!' )
383
412
. withInput ( { 'foo bar' : { expression : 'beautiful' } } )
384
413
. withMessage ( 'Literal paths can be used' )
@@ -389,18 +418,23 @@ describe('basic context', function() {
389
418
expectTemplate ( 'Goodbye {{[foo bar]}} world!' )
390
419
. withInput ( { 'foo bar' : 'beautiful' } )
391
420
. toCompileTo ( 'Goodbye beautiful world!' ) ;
421
+
392
422
expectTemplate ( 'Goodbye {{"foo bar"}} world!' )
393
423
. withInput ( { 'foo bar' : 'beautiful' } )
394
424
. toCompileTo ( 'Goodbye beautiful world!' ) ;
425
+
395
426
expectTemplate ( "Goodbye {{'foo bar'}} world!" )
396
427
. withInput ( { 'foo bar' : 'beautiful' } )
397
428
. toCompileTo ( 'Goodbye beautiful world!' ) ;
429
+
398
430
expectTemplate ( 'Goodbye {{"foo[bar"}} world!' )
399
431
. withInput ( { 'foo[bar' : 'beautiful' } )
400
432
. toCompileTo ( 'Goodbye beautiful world!' ) ;
433
+
401
434
expectTemplate ( 'Goodbye {{"foo\'bar"}} world!' )
402
435
. withInput ( { "foo'bar" : 'beautiful' } )
403
436
. toCompileTo ( 'Goodbye beautiful world!' ) ;
437
+
404
438
expectTemplate ( "Goodbye {{'foo\"bar'}} world!" )
405
439
. withInput ( { 'foo"bar' : 'beautiful' } )
406
440
. toCompileTo ( 'Goodbye beautiful world!' ) ;
@@ -417,25 +451,22 @@ describe('basic context', function() {
417
451
expectTemplate ( '{{person/name}}' )
418
452
. withInput ( { person : { name : null } } )
419
453
. toCompileTo ( '' ) ;
454
+
420
455
expectTemplate ( '{{person/name}}' )
421
456
. withInput ( { person : { } } )
422
457
. toCompileTo ( '' ) ;
423
458
} ) ;
424
459
425
460
it ( 'this keyword in paths' , function ( ) {
426
- var string = '{{#goodbyes}}{{this}}{{/goodbyes}}' ;
427
- var hash = { goodbyes : [ 'goodbye' , 'Goodbye' , 'GOODBYE' ] } ;
428
- expectTemplate ( string )
429
- . withInput ( hash )
461
+ expectTemplate ( '{{#goodbyes}}{{this}}{{/goodbyes}}' )
462
+ . withInput ( { goodbyes : [ 'goodbye' , 'Goodbye' , 'GOODBYE' ] } )
430
463
. withMessage ( 'This keyword in paths evaluates to current context' )
431
464
. toCompileTo ( 'goodbyeGoodbyeGOODBYE' ) ;
432
465
433
- string = '{{#hellos}}{{this/text}}{{/hellos}}' ;
434
- hash = {
435
- hellos : [ { text : 'hello' } , { text : 'Hello' } , { text : 'HELLO' } ]
436
- } ;
437
- expectTemplate ( string )
438
- . withInput ( hash )
466
+ expectTemplate ( '{{#hellos}}{{this/text}}{{/hellos}}' )
467
+ . withInput ( {
468
+ hellos : [ { text : 'hello' } , { text : 'Hello' } , { text : 'HELLO' } ]
469
+ } )
439
470
. withMessage ( 'This keyword evaluates in more complex paths' )
440
471
. toCompileTo ( 'helloHelloHELLO' ) ;
441
472
} ) ;
@@ -449,6 +480,7 @@ describe('basic context', function() {
449
480
expectTemplate ( '{{[this]}}' )
450
481
. withInput ( { this : 'bar' } )
451
482
. toCompileTo ( 'bar' ) ;
483
+
452
484
expectTemplate ( '{{text/[this]}}' )
453
485
. withInput ( { text : { this : 'bar' } } )
454
486
. toCompileTo ( 'bar' ) ;
@@ -460,28 +492,27 @@ describe('basic context', function() {
460
492
return 'bar ' + value ;
461
493
}
462
494
} ;
463
- var string = '{{#goodbyes}}{{foo this}}{{/goodbyes}}' ;
464
- var hash = { goodbyes : [ 'goodbye' , 'Goodbye' , 'GOODBYE' ] } ;
465
- expectTemplate ( string )
466
- . withInput ( hash )
495
+
496
+ expectTemplate ( '{{#goodbyes}}{{foo this}}{{/goodbyes}}' )
497
+ . withInput ( { goodbyes : [ 'goodbye' , 'Goodbye' , 'GOODBYE' ] } )
467
498
. withHelpers ( helpers )
468
499
. withMessage ( 'This keyword in paths evaluates to current context' )
469
500
. toCompileTo ( 'bar goodbyebar Goodbyebar GOODBYE' ) ;
470
501
471
- string = '{{#hellos}}{{foo this/text}}{{/hellos}}' ;
472
- hash = {
473
- hellos : [ { text : 'hello' } , { text : 'Hello' } , { text : 'HELLO' } ]
474
- } ;
475
- expectTemplate ( string )
476
- . withInput ( hash )
502
+ expectTemplate ( '{{#hellos}}{{foo this/text}}{{/hellos}}' )
503
+ . withInput ( {
504
+ hellos : [ { text : 'hello' } , { text : 'Hello' } , { text : 'HELLO' } ]
505
+ } )
477
506
. withHelpers ( helpers )
478
507
. withMessage ( 'This keyword evaluates in more complex paths' )
479
508
. toCompileTo ( 'bar hellobar Hellobar HELLO' ) ;
480
509
} ) ;
481
510
482
511
it ( 'this keyword nested inside helpers param' , function ( ) {
483
- var string = '{{#hellos}}{{foo text/this/foo}}{{/hellos}}' ;
484
- expectTemplate ( string ) . toThrow ( Error , 'Invalid path: text/this - 1:17' ) ;
512
+ expectTemplate ( '{{#hellos}}{{foo text/this/foo}}{{/hellos}}' ) . toThrow (
513
+ Error ,
514
+ 'Invalid path: text/this - 1:17'
515
+ ) ;
485
516
486
517
expectTemplate ( '{{foo [this]}}' )
487
518
. withInput ( {
@@ -491,6 +522,7 @@ describe('basic context', function() {
491
522
this : 'bar'
492
523
} )
493
524
. toCompileTo ( 'bar' ) ;
525
+
494
526
expectTemplate ( '{{foo text/[this]}}' )
495
527
. withInput ( {
496
528
foo : function ( value ) {
@@ -503,9 +535,11 @@ describe('basic context', function() {
503
535
504
536
it ( 'pass string literals' , function ( ) {
505
537
expectTemplate ( '{{"foo"}}' ) . toCompileTo ( '' ) ;
538
+
506
539
expectTemplate ( '{{"foo"}}' )
507
540
. withInput ( { foo : 'bar' } )
508
541
. toCompileTo ( 'bar' ) ;
542
+
509
543
expectTemplate ( '{{#"foo"}}{{.}}{{/"foo"}}' )
510
544
. withInput ( {
511
545
foo : [ 'bar' , 'baz' ]
@@ -515,13 +549,17 @@ describe('basic context', function() {
515
549
516
550
it ( 'pass number literals' , function ( ) {
517
551
expectTemplate ( '{{12}}' ) . toCompileTo ( '' ) ;
552
+
518
553
expectTemplate ( '{{12}}' )
519
554
. withInput ( { '12' : 'bar' } )
520
555
. toCompileTo ( 'bar' ) ;
556
+
521
557
expectTemplate ( '{{12.34}}' ) . toCompileTo ( '' ) ;
558
+
522
559
expectTemplate ( '{{12.34}}' )
523
560
. withInput ( { '12.34' : 'bar' } )
524
561
. toCompileTo ( 'bar' ) ;
562
+
525
563
expectTemplate ( '{{12.34 1}}' )
526
564
. withInput ( {
527
565
'12.34' : function ( arg ) {
@@ -533,27 +571,26 @@ describe('basic context', function() {
533
571
534
572
it ( 'pass boolean literals' , function ( ) {
535
573
expectTemplate ( '{{true}}' ) . toCompileTo ( '' ) ;
574
+
536
575
expectTemplate ( '{{true}}' )
537
576
. withInput ( { '' : 'foo' } )
538
577
. toCompileTo ( '' ) ;
578
+
539
579
expectTemplate ( '{{false}}' )
540
580
. withInput ( { false : 'foo' } )
541
581
. toCompileTo ( 'foo' ) ;
542
582
} ) ;
543
583
544
584
it ( 'should handle literals in subexpression' , function ( ) {
545
- var helpers = {
546
- foo : function ( arg ) {
547
- return arg ;
548
- }
549
- } ;
550
585
expectTemplate ( '{{foo (false)}}' )
551
586
. withInput ( {
552
587
false : function ( ) {
553
588
return 'bar' ;
554
589
}
555
590
} )
556
- . withHelpers ( helpers )
591
+ . withHelper ( 'foo' , function ( arg ) {
592
+ return arg ;
593
+ } )
557
594
. toCompileTo ( 'bar' ) ;
558
595
} ) ;
559
596
} ) ;
0 commit comments