1 | var path = require ('path');
|
2 | var assert = require ('assert');
|
3 |
|
4 | var common = require ('../common');
|
5 |
|
6 | var baseName = path.basename (__filename, path.extname (__filename));
|
7 |
|
8 | var data = {
|
9 | boolExp: "{$data.bool}",
|
10 | stringExp: "{$data.string}",
|
11 | stringExp3: "{$okString}",
|
12 | numberExp: "{$data.number}",
|
13 | inlineExp: "{$data.string}-{$data.number}",
|
14 | arrayExp: "{$arr}",
|
15 | objectExp: "{$data}",
|
16 | indexedExp: "{$nestedData.arr.0}",
|
17 | indexedZeroPropExp: "{$nestedData.arr.0.record}",
|
18 | indexedNonZeroPropExp: "{$nestedData.arr.1.record}",
|
19 |
|
20 | };
|
21 |
|
22 | var dict = {
|
23 | data: {
|
24 | bool: true,
|
25 | string: "string",
|
26 | number: 123
|
27 | },
|
28 | nestedData: {
|
29 | arr: [
|
30 | { record: 'a' },
|
31 | { record: 'b' }
|
32 | ]
|
33 | },
|
34 | badString: "{$",
|
35 | okString: "}",
|
36 | arr: ['a', 'b'],
|
37 | };
|
38 |
|
39 | describe (baseName + ' interpolate', function () {
|
40 |
|
41 | it ('expandBoolean', function() {
|
42 | var result = data.boolExp.interpolate (dict);
|
43 | assert.strictEqual (result, true);
|
44 | })
|
45 |
|
46 | it ('expandString', function() {
|
47 | var result = data.stringExp.interpolate (dict);
|
48 | assert.strictEqual (result, "string");
|
49 | })
|
50 |
|
51 | it ('expandString2', function() {
|
52 | assert.throws (function () {
|
53 | var result = data.stringExp2.interpolate (dict);
|
54 | });
|
55 | })
|
56 |
|
57 | it ('expandString3', function() {
|
58 | var result = data.stringExp3.interpolate (dict);
|
59 | assert.strictEqual (result, "}");
|
60 | })
|
61 |
|
62 | it ('expandNumber', function() {
|
63 | var result = data.numberExp.interpolate (dict);
|
64 | assert.strictEqual (result, 123);
|
65 | })
|
66 |
|
67 | it ('expandInline', function() {
|
68 | var result = data.inlineExp.interpolate (dict);
|
69 | assert.strictEqual (result, "string-123");
|
70 | })
|
71 |
|
72 | it ('expandArray', function() {
|
73 | var result = data.arrayExp.interpolate (dict);
|
74 | assert.deepEqual (result, ['a', 'b']);
|
75 | })
|
76 |
|
77 | it ('expandObject', function() {
|
78 | var result = data.objectExp.interpolate (dict);
|
79 | assert.deepEqual (result, {
|
80 | bool: true,
|
81 | string: "string",
|
82 | number: 123
|
83 | });
|
84 | })
|
85 |
|
86 | it ('expandIndexed', function() {
|
87 | var result = data.indexedExp.interpolate (dict);
|
88 |
|
89 | assert.deepEqual (result, { record: 'a' });
|
90 | })
|
91 |
|
92 | it ('expandIndexedZeroProp', function() {
|
93 | var result = data.indexedZeroPropExp.interpolate (dict);
|
94 |
|
95 | assert.equal (result, 'a');
|
96 | })
|
97 |
|
98 | it ('expandIndexedNonZeroProp', function() {
|
99 | var result = data.indexedNonZeroPropExp.interpolate (dict);
|
100 |
|
101 | assert.equal (result, 'b');
|
102 | })
|
103 | });
|