-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
100 lines (84 loc) · 2.94 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
'use strict';
const expect = require('chai').expect;
const Plugin = require('.');
describe('pegjs-brunch', function () {
it('should initialize with no arguments', function () {
const plugin = new Plugin();
expect(plugin).to.be.ok;
});
it('should initialize with empty brunch config', function () {
const plugin = new Plugin({});
expect(plugin).to.be.ok;
});
it('should initialize with empty plugins config', function () {
const plugin = new Plugin({plugins: {}});
expect(plugin).to.be.ok;
});
it('should initialize with empty plugin config', function () {
const plugin = new Plugin({plugins: {pegjs: {}}});
expect(plugin).to.be.ok;
});
it('should generate parser from valid grammar', function (done) {
const data = 'Integer\n\t= \'-\'\n\t[1-9][0-9]*';
const plugin = new Plugin({
plugins: {pegjs: {output: 'source'}}
});
plugin.compile({data: data, path: 'file.pegjs'}).then((file) => {
expect(file.data).to.be.a('string');
done();
}).catch(done);
});
it('should throw error for invalid grammar', function (done) {
const data = 'blahblah';
const plugin = new Plugin();
plugin.compile({data: data, path: 'file.pegjs'}).then((file) => {
expect(file).not.to.be.ok;
}, (error) => {
expect(error).to.be.ok;
done();
}).catch(done);
});
it('should provide line no./column for invalid grammar', function (done) {
const data = 'blahblah';
const plugin = new Plugin();
plugin.compile({data: data, path: 'file.pegjs'}).then((file) => {
expect(file).not.to.be.ok;
}, (error) => {
expect(error.message).to.match(/1:9/);
done();
}).catch(done);
});
it('should generate parser as string regardless of config', function (done) {
const data = 'Integer\n\t= \'-\'?[1-9][0-9]*';
const plugin = new Plugin({
plugins: {pegjs: {output: 'parser'}}
});
plugin.compile({data: data, path: 'file.pegjs'}).then((file) => {
expect(file.data).to.be.a('string');
done();
}).catch(done);
});
it('should pass other options to parser', function (done) {
const data = 'Integer\n\t= \'-\'?[1-9][0-9]*';
const plugin = new Plugin({
plugins: {pegjs: {format: 'globals', exportVar: 'foo', output: 'source'}}
});
plugin.compile({data: data, path: 'file.pegjs'}).then((file) => {
expect(file.data).to.be.a('string');
expect(file.data).to.match(/\bfoo\s*=\s*/);
done();
}).catch(done);
});
it('should be registered as Brunch plugin', function () {
expect(Plugin.prototype.brunchPlugin).to.be.true;
});
it('should generate JavaScript files', function () {
expect(Plugin.prototype.type).to.equal('javascript');
});
it('should process PEG.js grammar files', function () {
expect(Plugin.prototype.extension).to.equal('pegjs');
});
it('should enable processor chaining', function () {
expect(Plugin.prototype.targetExtension).to.equal('js');
});
});