Skip to content

Commit dd909e9

Browse files
committed
Apply formatting requested by @nknapp
1 parent 6b164bc commit dd909e9

13 files changed

+1791
-2329
lines changed

spec/basic.js

Lines changed: 71 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,19 @@ describe('basic context', function() {
1515
expectTemplate('\\{{foo}}')
1616
.withInput({ foo: 'food' })
1717
.toCompileTo('{{foo}}');
18+
1819
expectTemplate('content \\{{foo}}')
1920
.withInput({ foo: 'food' })
2021
.toCompileTo('content {{foo}}');
22+
2123
expectTemplate('\\\\{{foo}}')
2224
.withInput({ foo: 'food' })
2325
.toCompileTo('\\food');
26+
2427
expectTemplate('content \\\\{{foo}}')
2528
.withInput({ foo: 'food' })
2629
.toCompileTo('content \\food');
30+
2731
expectTemplate('\\\\ {{foo}}')
2832
.withInput({ foo: 'food' })
2933
.toCompileTo('\\\\ food');
@@ -65,14 +69,19 @@ describe('basic context', function() {
6569
.toCompileTo('Goodbye\ncruel\nworld!');
6670

6771
expectTemplate(' {{~! comment ~}} blah').toCompileTo('blah');
72+
6873
expectTemplate(' {{~!-- long-comment --~}} blah').toCompileTo(
6974
'blah'
7075
);
76+
7177
expectTemplate(' {{! comment ~}} blah').toCompileTo(' blah');
78+
7279
expectTemplate(' {{!-- long-comment --~}} blah').toCompileTo(
7380
' blah'
7481
);
82+
7583
expectTemplate(' {{~! comment}} blah').toCompileTo(' blah');
84+
7685
expectTemplate(' {{~!-- long-comment --}} blah').toCompileTo(
7786
' blah'
7887
);
@@ -104,13 +113,16 @@ describe('basic context', function() {
104113
num2: 0
105114
})
106115
.toCompileTo('num1: 42, num2: 0');
116+
107117
expectTemplate('num: {{.}}')
108118
.withInput(0)
109119
.toCompileTo('num: 0');
120+
110121
expectTemplate('num: {{num1/num2}}')
111122
.withInput({ num1: { num2: 0 } })
112123
.toCompileTo('num: 0');
113124
});
125+
114126
it('false', function() {
115127
/* eslint-disable no-new-wrappers */
116128
expectTemplate('val1: {{val1}}, val2: {{val2}}')
@@ -119,9 +131,11 @@ describe('basic context', function() {
119131
val2: new Boolean(false)
120132
})
121133
.toCompileTo('val1: false, val2: false');
134+
122135
expectTemplate('val: {{.}}')
123136
.withInput(false)
124137
.toCompileTo('val: false');
138+
125139
expectTemplate('val: {{val1/val2}}')
126140
.withInput({ val1: { val2: false } })
127141
.toCompileTo('val: false');
@@ -132,6 +146,7 @@ describe('basic context', function() {
132146
val2: new Boolean(false)
133147
})
134148
.toCompileTo('val1: false, val2: false');
149+
135150
expectTemplate('val: {{{val1/val2}}}')
136151
.withInput({ val1: { val2: false } })
137152
.toCompileTo('val: false');
@@ -152,13 +167,15 @@ describe('basic context', function() {
152167
}
153168
})
154169
.toCompileTo('true true object');
170+
155171
expectTemplate('{{undefined}}')
156172
.withInput({
157173
undefined: function() {
158174
return 'undefined!';
159175
}
160176
})
161177
.toCompileTo('undefined!');
178+
162179
expectTemplate('{{null}}')
163180
.withInput({
164181
null: function() {
@@ -170,6 +187,7 @@ describe('basic context', function() {
170187

171188
it('newlines', function() {
172189
expectTemplate("Alan's\nTest").toCompileTo("Alan's\nTest");
190+
173191
expectTemplate("Alan's\rTest").toCompileTo("Alan's\rTest");
174192
});
175193

@@ -179,16 +197,20 @@ describe('basic context', function() {
179197
"text is escaped so that it doesn't get caught on single quotes"
180198
)
181199
.toCompileTo("Awesome's");
200+
182201
expectTemplate('Awesome\\')
183202
.withMessage("text is escaped so that the closing quote can't be ignored")
184203
.toCompileTo('Awesome\\');
204+
185205
expectTemplate('Awesome\\\\ foo')
186206
.withMessage("text is escaped so that it doesn't mess up backslashes")
187207
.toCompileTo('Awesome\\\\ foo');
208+
188209
expectTemplate('Awesome {{foo}}')
189210
.withInput({ foo: '\\' })
190211
.withMessage("text is escaped so that it doesn't mess up backslashes")
191212
.toCompileTo('Awesome \\');
213+
192214
expectTemplate(" ' ' ")
193215
.withMessage('double quotes never produce invalid javascript')
194216
.toCompileTo(" ' ' ");
@@ -217,13 +239,12 @@ describe('basic context', function() {
217239
});
218240

219241
it("functions returning safestrings shouldn't be escaped", function() {
220-
var hash = {
221-
awesome: function() {
222-
return new Handlebars.SafeString("&'\\<>");
223-
}
224-
};
225242
expectTemplate('{{awesome}}')
226-
.withInput(hash)
243+
.withInput({
244+
awesome: function() {
245+
return new Handlebars.SafeString("&'\\<>");
246+
}
247+
})
227248
.withMessage("functions returning safestrings aren't escaped")
228249
.toCompileTo("&'\\<>");
229250
});
@@ -237,6 +258,7 @@ describe('basic context', function() {
237258
})
238259
.withMessage('functions are called and render their output')
239260
.toCompileTo('Awesome');
261+
240262
expectTemplate('{{awesome}}')
241263
.withInput({
242264
awesome: function() {
@@ -259,6 +281,7 @@ describe('basic context', function() {
259281
.withMessage('functions are called with context arguments')
260282
.toCompileTo('Frank');
261283
});
284+
262285
it('pathed functions with context argument', function() {
263286
expectTemplate('{{bar.awesome frank}}')
264287
.withInput({
@@ -272,6 +295,7 @@ describe('basic context', function() {
272295
.withMessage('functions are called with context arguments')
273296
.toCompileTo('Frank');
274297
});
298+
275299
it('depthed functions with context argument', function() {
276300
expectTemplate('{{#with frank}}{{../awesome .}}{{/with}}')
277301
.withInput({
@@ -319,6 +343,7 @@ describe('basic context', function() {
319343
.withMessage('block functions are called with options')
320344
.toCompileTo('inner');
321345
});
346+
322347
it('pathed block functions without context argument', function() {
323348
expectTemplate('{{#foo.awesome}}inner{{/foo.awesome}}')
324349
.withInput({
@@ -331,6 +356,7 @@ describe('basic context', function() {
331356
.withMessage('block functions are called with options')
332357
.toCompileTo('inner');
333358
});
359+
334360
it('depthed block functions without context argument', function() {
335361
expectTemplate(
336362
'{{#with value}}{{#../awesome}}inner{{/../awesome}}{{/with}}'
@@ -350,10 +376,12 @@ describe('basic context', function() {
350376
.withInput({ 'foo-bar': 'baz' })
351377
.withMessage('Paths can contain hyphens (-)')
352378
.toCompileTo('baz');
379+
353380
expectTemplate('{{foo.foo-bar}}')
354381
.withInput({ foo: { 'foo-bar': 'baz' } })
355382
.withMessage('Paths can contain hyphens (-)')
356383
.toCompileTo('baz');
384+
357385
expectTemplate('{{foo/foo-bar}}')
358386
.withInput({ foo: { 'foo-bar': 'baz' } })
359387
.withMessage('Paths can contain hyphens (-)')
@@ -379,6 +407,7 @@ describe('basic context', function() {
379407
.withInput({ '@alan': { expression: 'beautiful' } })
380408
.withMessage('Literal paths can be used')
381409
.toCompileTo('Goodbye beautiful world!');
410+
382411
expectTemplate('Goodbye {{[foo bar]/expression}} world!')
383412
.withInput({ 'foo bar': { expression: 'beautiful' } })
384413
.withMessage('Literal paths can be used')
@@ -389,18 +418,23 @@ describe('basic context', function() {
389418
expectTemplate('Goodbye {{[foo bar]}} world!')
390419
.withInput({ 'foo bar': 'beautiful' })
391420
.toCompileTo('Goodbye beautiful world!');
421+
392422
expectTemplate('Goodbye {{"foo bar"}} world!')
393423
.withInput({ 'foo bar': 'beautiful' })
394424
.toCompileTo('Goodbye beautiful world!');
425+
395426
expectTemplate("Goodbye {{'foo bar'}} world!")
396427
.withInput({ 'foo bar': 'beautiful' })
397428
.toCompileTo('Goodbye beautiful world!');
429+
398430
expectTemplate('Goodbye {{"foo[bar"}} world!')
399431
.withInput({ 'foo[bar': 'beautiful' })
400432
.toCompileTo('Goodbye beautiful world!');
433+
401434
expectTemplate('Goodbye {{"foo\'bar"}} world!')
402435
.withInput({ "foo'bar": 'beautiful' })
403436
.toCompileTo('Goodbye beautiful world!');
437+
404438
expectTemplate("Goodbye {{'foo\"bar'}} world!")
405439
.withInput({ 'foo"bar': 'beautiful' })
406440
.toCompileTo('Goodbye beautiful world!');
@@ -417,25 +451,22 @@ describe('basic context', function() {
417451
expectTemplate('{{person/name}}')
418452
.withInput({ person: { name: null } })
419453
.toCompileTo('');
454+
420455
expectTemplate('{{person/name}}')
421456
.withInput({ person: {} })
422457
.toCompileTo('');
423458
});
424459

425460
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'] })
430463
.withMessage('This keyword in paths evaluates to current context')
431464
.toCompileTo('goodbyeGoodbyeGOODBYE');
432465

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+
})
439470
.withMessage('This keyword evaluates in more complex paths')
440471
.toCompileTo('helloHelloHELLO');
441472
});
@@ -449,6 +480,7 @@ describe('basic context', function() {
449480
expectTemplate('{{[this]}}')
450481
.withInput({ this: 'bar' })
451482
.toCompileTo('bar');
483+
452484
expectTemplate('{{text/[this]}}')
453485
.withInput({ text: { this: 'bar' } })
454486
.toCompileTo('bar');
@@ -460,28 +492,27 @@ describe('basic context', function() {
460492
return 'bar ' + value;
461493
}
462494
};
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'] })
467498
.withHelpers(helpers)
468499
.withMessage('This keyword in paths evaluates to current context')
469500
.toCompileTo('bar goodbyebar Goodbyebar GOODBYE');
470501

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+
})
477506
.withHelpers(helpers)
478507
.withMessage('This keyword evaluates in more complex paths')
479508
.toCompileTo('bar hellobar Hellobar HELLO');
480509
});
481510

482511
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+
);
485516

486517
expectTemplate('{{foo [this]}}')
487518
.withInput({
@@ -491,6 +522,7 @@ describe('basic context', function() {
491522
this: 'bar'
492523
})
493524
.toCompileTo('bar');
525+
494526
expectTemplate('{{foo text/[this]}}')
495527
.withInput({
496528
foo: function(value) {
@@ -503,9 +535,11 @@ describe('basic context', function() {
503535

504536
it('pass string literals', function() {
505537
expectTemplate('{{"foo"}}').toCompileTo('');
538+
506539
expectTemplate('{{"foo"}}')
507540
.withInput({ foo: 'bar' })
508541
.toCompileTo('bar');
542+
509543
expectTemplate('{{#"foo"}}{{.}}{{/"foo"}}')
510544
.withInput({
511545
foo: ['bar', 'baz']
@@ -515,13 +549,17 @@ describe('basic context', function() {
515549

516550
it('pass number literals', function() {
517551
expectTemplate('{{12}}').toCompileTo('');
552+
518553
expectTemplate('{{12}}')
519554
.withInput({ '12': 'bar' })
520555
.toCompileTo('bar');
556+
521557
expectTemplate('{{12.34}}').toCompileTo('');
558+
522559
expectTemplate('{{12.34}}')
523560
.withInput({ '12.34': 'bar' })
524561
.toCompileTo('bar');
562+
525563
expectTemplate('{{12.34 1}}')
526564
.withInput({
527565
'12.34': function(arg) {
@@ -533,27 +571,26 @@ describe('basic context', function() {
533571

534572
it('pass boolean literals', function() {
535573
expectTemplate('{{true}}').toCompileTo('');
574+
536575
expectTemplate('{{true}}')
537576
.withInput({ '': 'foo' })
538577
.toCompileTo('');
578+
539579
expectTemplate('{{false}}')
540580
.withInput({ false: 'foo' })
541581
.toCompileTo('foo');
542582
});
543583

544584
it('should handle literals in subexpression', function() {
545-
var helpers = {
546-
foo: function(arg) {
547-
return arg;
548-
}
549-
};
550585
expectTemplate('{{foo (false)}}')
551586
.withInput({
552587
false: function() {
553588
return 'bar';
554589
}
555590
})
556-
.withHelpers(helpers)
591+
.withHelper('foo', function(arg) {
592+
return arg;
593+
})
557594
.toCompileTo('bar');
558595
});
559596
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy