-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
120 lines (107 loc) · 3.54 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
'use strict';
require('mocha');
const assert = require('assert');
const lint = require('./');
let options;
describe('handlebars-variables', function() {
describe('partials', function() {
it('should return a list of missing partials', function() {
const fixture = '{{> foo }}{{> bar }}';
const options = {
context: {
partials: ['foo', 'qux']
}
};
assert.deepEqual(lint(fixture, options), { partials: ['bar'] });
});
});
describe('variables', function() {
it('should return a list of missing variables', function() {
const fixture = '{{foo one}}{{bar two}}';
const options = {
context: {
helpers: ['foo', 'bar'],
variables: ['xxx', 'yyy']
}
};
assert.deepEqual(lint(fixture, options), { variables: ['one', 'two'] });
});
it('should get hash variables', function() {
const fixture = '{{foo abc=bar}}';
assert.deepEqual(lint(fixture), { helpers: ['foo'], variables: ['bar'] });
});
it('should get subexpressions', function() {
const fixture = '{{foo (bar baz)}}';
assert.deepEqual(lint(fixture), { helpers: ['bar', 'foo'], variables: ['baz'] });
});
it('should get', function() {
const fixture = `{
"name": "{{name}}",
"description": "{{description}}",
"version": "{{version}}",
"homepage": "{{homepage}}",
"author": "{{author.name}} ({{author_url}})",
"repository": "{{owner}}/{{name}}",
"bugs": {
"url": "https://github.com/{{owner}}/{{name}}/issues"
},
"engines": {
"node": ">=4"
},
"license": "{{license}}",
"scripts": {
"test": "mocha"
},
"keywords": []
}
`;
assert.deepEqual(lint(fixture), {
variables: ['author', 'author_url', 'description', 'homepage', 'license', 'name', 'owner', 'version']
});
});
});
describe('partials', function() {
it('should return a list of missing block helpers', function() {
assert.deepEqual(lint('{{#foo}}...{{/foo}}', { context: { helpers: ['foo', 'qux'] } }), {});
assert.deepEqual(lint('{{#bar}}...{{/bar}}', { context: { helpers: ['foo', 'qux'] } }), {
blockHelpers: ['bar']
});
assert.deepEqual(lint('{{#bar}}{{#baz}}...{{/baz}}{{/bar}}', { context: { helpers: ['foo', 'qux'] } }), {
blockHelpers: ['bar', 'baz']
});
});
});
describe('helpers', function() {
it('should return a list of missing helpers', function() {
const fixture = '{{foo}}{{bar}}';
options = {
context: {
helpers: ['foo']
}
};
assert.deepEqual(lint(fixture, options), { variables: ['bar'] });
});
it('should return a list of missing variables', function() {
options = { context: { helpers: ['foo'] } };
assert.deepEqual(lint('{{foo one}}{{bar two}}', options), {
helpers: ['bar'],
variables: ['one', 'two']
});
options = { context: { helpers: ['foo'], variables: ['two'] } };
assert.deepEqual(lint('{{foo one}}{{bar two}}', options), {
helpers: ['bar'],
variables: ['one']
});
options = { context: { variables: ['foo'] } };
assert.deepEqual(lint('{{foo}}{{bar two}}', options), {
helpers: ['bar'],
variables: ['two']
});
options = { context: { helpers: ['foo'] } };
assert.deepEqual(lint('{{foo}}{{bar two}}', options), {
helpers: ['bar'],
variables: ['two']
});
});
});
});