-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
test.js
71 lines (57 loc) · 2.43 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*!
* handlebars-delimiters <https://github.com/jonschlinkert/handlebars-delimiters>
*
* Copyright (c) 2014-2017, Jon Schlinkert.
* Released under the MIT License.
*/
'use strict';
var assert = require('assert');
var handlebars = require('handlebars');
var delimiters = require('./');
var hbs;
var fixture = '{%= name %}{{ name }}{{{ name }}}<%= name %><% name %><<= name >><< name >>%{name}%{ name }';
describe('custom handlebars delimiters', function() {
beforeEach(function() {
hbs = handlebars.create();
});
function testWith(fixture, expectation) {
var actual = hbs.compile(fixture)({name: 'Jon Schlinkert'});
assert.equal(actual, expectation);
}
it('should use default delimiters', function() {
var actual = hbs.compile(fixture)({name: 'Jon Schlinkert'});
testWith(fixture, '{%= name %}Jon SchlinkertJon Schlinkert<%= name %><% name %><<= name >><< name >>%{name}%{ name }');
});
it('should use <%=...%>', function() {
delimiters(hbs, ['<%=', '%>']);
testWith(fixture, '{%= name %}{{ name }}{{{ name }}}Jon Schlinkert<% name %><<= name >><< name >>%{name}%{ name }');
});
it('should use {%=...%}', function() {
delimiters(hbs, ['{%=', '%}']);
testWith(fixture, 'Jon Schlinkert{{ name }}{{{ name }}}<%= name %><% name %><<= name >><< name >>%{name}%{ name }');
});
it('should use <%...%>', function() {
delimiters(hbs, ['<%', '%>']);
testWith(fixture, '{%= name %}{{ name }}{{{ name }}}<%= name %>Jon Schlinkert<<= name >><< name >>%{name}%{ name }');
});
it('should use <<...>>', function() {
delimiters(hbs, ['<<', '>>']);
testWith(fixture, '{%= name %}{{ name }}{{{ name }}}<%= name %><% name %><<= name >>Jon Schlinkert%{name}%{ name }');
});
it('should use <<=...>>', function() {
delimiters(hbs, ['<<=', '>>']);
testWith(fixture, '{%= name %}{{ name }}{{{ name }}}<%= name %><% name %>Jon Schlinkert<< name >>%{name}%{ name }');
});
it('should use %{...} with or without spaces', function() {
delimiters(hbs, ['%{', '}']);
testWith(fixture, '{%= name %}{{ name }}{{{ name }}}<%= name %><% name %><<= name >><< name >>Jon SchlinkertJon Schlinkert');
});
it('should handle no spaces in first occurence', function() {
delimiters(hbs, ['%{', '}']);
testWith("%{name}", 'Jon Schlinkert');
});
it('should handle spaces in first occurence', function() {
delimiters(hbs, ['%{', '}']);
testWith("%{ name }", 'Jon Schlinkert');
});
});