1 | 'use strict';
|
2 |
|
3 | var grunt = require('../../lib/grunt');
|
4 |
|
5 | exports['template'] = {
|
6 | 'process': function(test) {
|
7 | test.expect(4);
|
8 | var obj = {
|
9 | foo: 'c',
|
10 | bar: 'b<%= foo %>d',
|
11 | baz: 'a<%= bar %>e'
|
12 | };
|
13 |
|
14 | test.equal(grunt.template.process('<%= foo %>', {data: obj}), 'c', 'should retrieve value.');
|
15 | test.equal(grunt.template.process('<%= bar %>', {data: obj}), 'bcd', 'should recurse.');
|
16 | test.equal(grunt.template.process('<%= baz %>', {data: obj}), 'abcde', 'should recurse.');
|
17 |
|
18 | obj.foo = '<% oops %';
|
19 | test.equal(grunt.template.process('<%= baz %>', {data: obj}), 'ab<% oops %de', 'should not explode.');
|
20 | test.done();
|
21 | },
|
22 |
|
23 | 'custom delimiters': function(test) {
|
24 | test.expect(6);
|
25 | var obj = {
|
26 | foo: 'c',
|
27 | bar: 'b{%= foo %}d',
|
28 | baz: 'a{%= bar %}e'
|
29 | };
|
30 |
|
31 | test.equal(grunt.template.process('{%= foo %}', {data: obj, delimiters: 'custom'}), '{%= foo %}', 'custom delimiters have yet to be defined.');
|
32 |
|
33 |
|
34 | grunt.template.addDelimiters('custom', '{%', '%}');
|
35 |
|
36 | test.equal(grunt.template.process('{%= foo %}', {data: obj, delimiters: 'custom'}), 'c', 'should retrieve value.');
|
37 | test.equal(grunt.template.process('{%= bar %}', {data: obj, delimiters: 'custom'}), 'bcd', 'should recurse.');
|
38 | test.equal(grunt.template.process('{%= baz %}', {data: obj, delimiters: 'custom'}), 'abcde', 'should recurse.');
|
39 |
|
40 | test.equal(grunt.template.process('{%= foo %}<%= foo %>', {data: obj, delimiters: 'custom'}), 'c<%= foo %>', 'should ignore default delimiters');
|
41 |
|
42 | obj.foo = '{% oops %';
|
43 | test.equal(grunt.template.process('{%= baz %}', {data: obj, delimiters: 'custom'}), 'ab{% oops %de', 'should not explode.');
|
44 |
|
45 | test.done();
|
46 | },
|
47 | };
|