-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
scanner-test.js
78 lines (69 loc) · 2.41 KB
/
scanner-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
require('./helper');
var Scanner = Mustache.Scanner;
describe('A new Mustache.Scanner', function () {
describe('for an empty string', function () {
it('is at the end', function () {
var scanner = new Scanner('');
assert(scanner.eos());
});
});
describe('for a non-empty string', function () {
var scanner;
beforeEach(function () {
scanner = new Scanner('a b c');
});
describe('scan', function () {
describe('when the RegExp matches the entire string', function () {
it('returns the entire string', function () {
var match = scanner.scan(/a b c/);
assert.equal(match, scanner.string);
assert(scanner.eos());
});
});
describe('when the RegExp matches at index 0', function () {
it('returns the portion of the string that matched', function () {
var match = scanner.scan(/a/);
assert.equal(match, 'a');
assert.equal(scanner.pos, 1);
});
});
describe('when the RegExp matches at some index other than 0', function () {
it('returns the empty string', function () {
var match = scanner.scan(/b/);
assert.equal(match, '');
assert.equal(scanner.pos, 0);
});
});
describe('when the RegExp does not match', function () {
it('returns the empty string', function () {
var match = scanner.scan(/z/);
assert.equal(match, '');
assert.equal(scanner.pos, 0);
});
});
}); // scan
describe('scanUntil', function () {
describe('when the RegExp matches at index 0', function () {
it('returns the empty string', function () {
var match = scanner.scanUntil(/a/);
assert.equal(match, '');
assert.equal(scanner.pos, 0);
});
});
describe('when the RegExp matches at some index other than 0', function () {
it('returns the string up to that index', function () {
var match = scanner.scanUntil(/b/);
assert.equal(match, 'a ');
assert.equal(scanner.pos, 2);
});
});
describe('when the RegExp does not match', function () {
it('returns the entire string', function () {
var match = scanner.scanUntil(/z/);
assert.equal(match, scanner.string);
assert(scanner.eos());
});
});
}); // scanUntil
}); // for a non-empty string
});