-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
96 lines (84 loc) · 2.34 KB
/
Copy pathtest.js
File metadata and controls
96 lines (84 loc) · 2.34 KB
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
var assert = require('assert');
var grammar = require('./');
var Parser = require('grammarjs-recursive-parser');
var parser = new Parser(grammar);
var fs = require('fs');
describe('makefile', function(){
describe('comment', function(){
test('# comment');
});
describe('assignment', function(){
test('BINS= node_modules/.bin');
test('BINS = node_modules/.bin');
test('BINS = ./bin node_modules/.bin');
test('BINS = $(NODE_MODULES)');
test('BINS = $(NODE_MODULES)/.bin');
test('BINS = $(NODE_MODULES) $(COMPONENTS)');
test('SRC= $(wildcard index.js lib/*.js)');
test('tests ?= *');
test('TEST= http://localhost:4202');
// TODO: handle quotes
test('BROWSERS ?= \'chrome, safari, firefox\'');
test('PHANTOM= $(BINS)/mocha-phantomjs \\'
+ ' --setting local-to-remote-url-access=true \\'
+ ' --setting web-security=false');
});
describe('rule', function(){
test('clean:\n rm -rf tmp');
test('clean:\n @rm -rf tmp');
test('clean:\n -rm -rf tmp');
test('build: clean\n -rm -rf tmp');
test('build: clean install\n -rm -rf tmp');
test('build: clean install $(SRC)\n @rm -rf tmp');
test('build:\n @rm -rf tmp\n @component install');
test('test: build server test-node\n @$(PHANTOM) $(TEST)');
test('test-browser: test');
test('.PHONY: clean build test');
test('$(TEST): build\n cd test && make $@');
test('%:\n @component install $@');
});
describe('real world', function(){
test(fs.readFileSync('Makefile', 'utf-8'));
});
});
/**
* Test helper.
*
* @api private
*/
function test(str, log) {
return it(str, function(){
assert.equal(str, compile(str, log));
});
}
/**
* Parse `str` to ast, then stringify back.
*
* @param {String} str
* @return {String}
*/
function compile(str, log) {
var ast = parser.parse(str);
if (log) console.log(JSON.stringify(ast, null, 2));
return stringify(ast);
}
/**
* For testing, it should generate the original string.
*
* @param {Token} token
* @api public
*/
function stringify(token) {
if (!token) return '';
var html = [];
if (Array.isArray(token.content)) {
token.content.forEach(function(child){
html.push(stringify(child));
});
} else if (null != token.content) {
html.push(stringify(token.content));
} else {
html.push(token);
}
return html.join('');
}