-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest-context-with-holes.js
55 lines (44 loc) · 1.56 KB
/
test-context-with-holes.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
import test from 'ava';
import ContextWithHoles from '../src/context-with-holes.mjs';
import Context from '../src/context.mjs';
test('no holes', t => {
let c = new ContextWithHoles(['abc'], []);
t.is(c.next().value, 'a');
t.is(c.next().value, 'b');
t.is(c.next().value, 'c');
t.true(c.next().done);
});
test('unmatched number of parts and holes', t => {
t.throws(() => new ContextWithHoles([], []));
t.throws(() => new ContextWithHoles(['abc'], [() => null]));
t.throws(() => new ContextWithHoles([], [() => null]));
});
test('empty strings with a single hole', t => {
let c = new ContextWithHoles(['', ''], [() => 'b']);
t.is(c.next().value[ContextWithHoles.hole](), 'b');
t.true(c.next().done);
});
test('single strings with a single hole', t => {
let c = new ContextWithHoles(['a', 'c'], [() => 'b']);
t.is(c.next().value, 'a');
t.is(c.next().value[ContextWithHoles.hole](), 'b');
t.is(c.next().value, 'c');
t.true(c.next().done);
});
test('regex matching in the middle of a part', t => {
let c = new ContextWithHoles(['abc', 'c'], [() => 'b']);
t.is(c.next().value, 'a');
t.is(c[Context.regex](/b/).value, 'b');
t.is(c.next().value, 'c');
t.is(c.next().value[ContextWithHoles.hole](), 'b');
t.is(c.next().value, 'c');
t.true(c.next().done);
});
test('regex matching to the end of a part', t => {
let c = new ContextWithHoles(['abc', 'c'], [() => 'b']);
t.is(c.next().value, 'a');
t.is(c[Context.regex](/bc/).value, 'bc');
t.is(c.next().value[ContextWithHoles.hole](), 'b');
t.is(c.next().value, 'c');
t.true(c.next().done);
});