forked from jonschlinkert/handlebars-delimiters
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
69 lines (55 loc) · 2.42 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
/*!
* handlebars-delimiters <https://github.com/jonschlinkert/handlebars-delimiters>
*
* Copyright (c) 2014 Jon Schlinkert, contributors.
* Licensed under the MIT License
*/
'use strict';
var assert = require('assert');
var useDelims = require('./');
describe('custom handlebars delimiters', function() {
var Handlebars, str = '{%= name %}{{ name }}{{{ name }}}<%= name %><% name %><<= name >><< name >>%{name}%{ name }';
beforeEach(function() {
Handlebars = require('handlebars');
});
function testWith(str, expectation) {
var actual = Handlebars.compile(str)({name: 'Jon Schlinkert'});
assert.equal(actual, expectation);
}
it('should use default delimiters', function() {
var actual = Handlebars.compile(str)({name: 'Jon Schlinkert'});
testWith(str, '{%= name %}Jon SchlinkertJon Schlinkert<%= name %><% name %><<= name >><< name >>%{name}%{ name }');
});
it('should use <%=...%>', function() {
useDelims(Handlebars, ['<%=', '%>']);
testWith(str, '{%= name %}{{ name }}{{{ name }}}Jon Schlinkert<% name %><<= name >><< name >>%{name}%{ name }');
});
it('should use {%=...%}', function() {
useDelims(Handlebars, ['{%=', '%}']);
testWith(str, 'Jon Schlinkert{{ name }}{{{ name }}}<%= name %><% name %><<= name >><< name >>%{name}%{ name }');
});
it('should use <%...%>', function() {
useDelims(Handlebars, ['<%', '%>']);
testWith(str, '{%= name %}{{ name }}{{{ name }}}<%= name %>Jon Schlinkert<<= name >><< name >>%{name}%{ name }');
});
it('should use <<...>>', function() {
useDelims(Handlebars, ['<<', '>>']);
testWith(str, '{%= name %}{{ name }}{{{ name }}}<%= name %><% name %><<= name >>Jon Schlinkert%{name}%{ name }');
});
it('should use <<=...>>', function() {
useDelims(Handlebars, ['<<=', '>>']);
testWith(str, '{%= name %}{{ name }}{{{ name }}}<%= name %><% name %>Jon Schlinkert<< name >>%{name}%{ name }');
});
it('should use %{...} with or without spaces', function() {
useDelims(Handlebars, ['%{', '}']);
testWith(str, '{%= name %}{{ name }}{{{ name }}}<%= name %><% name %><<= name >><< name >>Jon SchlinkertJon Schlinkert');
});
it('should handle no spaces in first occurence', function() {
useDelims(Handlebars, ['%{', '}']);
testWith("%{name}", 'Jon Schlinkert');
});
it('should handle spaces in first occurence', function() {
useDelims(Handlebars, ['%{', '}']);
testWith("%{ name }", 'Jon Schlinkert');
});
});