-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
46 lines (39 loc) · 1.15 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
'use strict';
require('mocha');
const assert = require('assert');
const Scanner = require('./');
let scanner;
describe('scanner', () => {
beforeEach(() => {
scanner = new Scanner('//foo/bar.com');
});
it('should throw when regex matches an empty string', () => {
scanner.addRule('foo', /^(?=.)/);
assert.throws(() => scanner.scan(), /regex should not match an empty string/);
});
it('should add rule to error object', cb => {
scanner.addRule('foo', /^(?=.)/);
try {
scanner.scan();
} catch (err) {
assert.equal(err.rule, 'foo');
cb();
}
});
it('should get the next token from the given regex', () => {
scanner = new Scanner('//foo/bar.com', {
rules: {
dot: /^\./,
slash: /^\//,
text: /^\w+/
}
});
assert.deepEqual(scanner.scan().value, '/' );
assert.deepEqual(scanner.scan().value, '/' );
assert.deepEqual(scanner.scan().value, 'foo' );
assert.deepEqual(scanner.scan().value, '/' );
assert.deepEqual(scanner.scan().value, 'bar' );
assert.deepEqual(scanner.scan().value, '.' );
assert.deepEqual(scanner.scan().value, 'com' );
});
});