-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtabstop-resolution.js
86 lines (67 loc) · 2.54 KB
/
tabstop-resolution.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
'use strict';
require('mocha');
const assert = require('assert').strict;
const Session = require('..');
const render = (input, data, stop) => {
let session = new Session(input);
let ast = session.parse();
let fn = ast.compile();
if (Array.isArray(stop)) {
session.snippet.values.tabstop.set(...stop);
}
return fn(data);
};
const create = (input, options) => {
let session = new Session(input, options);
let ast = session.parse();
let fn = ast.compile();
return {
set(...args) {
session.snippet.values.tabstop.set(...args);
},
render(data) {
return fn(data);
}
};
};
describe('tabstop resolution', () => {
it('should return an empty string for undefined stops', () => {
assert.equal(render('foo $1 bar'), 'foo bar');
assert.equal(render('foo $1 $1 $1 bar'), 'foo bar');
assert.equal(render('foo $1 $2 $3 bar'), 'foo bar');
assert.equal(render('foo ${1} bar'), 'foo bar');
assert.equal(render('foo ${1} ${1} ${1} bar'), 'foo bar');
assert.equal(render('foo ${1} ${2} ${3} bar'), 'foo bar');
assert.equal(render('foo ${1} $1 bar'), 'foo bar');
assert.equal(render('foo ${1} $1 ${1} bar'), 'foo bar');
assert.equal(render('foo ${1} $2 ${3} $4 bar'), 'foo bar');
});
it('should use placeholders in subsequent tabstops', () => {
assert.equal(render('foo ${1:A} $1 bar'), 'foo A A bar');
assert.equal(render('foo ${1:A} $1 ${1} bar'), 'foo A A A bar');
});
it('should use the first placeholder in subsequent tabstops', () => {
assert.equal(render('foo ${1:A} $1 bar'), 'foo A A bar');
assert.equal(render('foo ${1:A} ${1:B} ${1:C} bar'), 'foo A A A bar');
});
it('should use the first placeholder from any tabstop', () => {
assert.equal(render('foo $1 ${1:A} bar'), 'foo A A bar');
assert.equal(render('foo ${1} ${1:B} $1 bar'), 'foo B B B bar');
});
it('should return an empty string for undefined tabstops', () => {
const session = create('foo $1 $1 $1 bar');
assert.equal(session.render(), 'foo bar');
session.set(1, 'V');
assert.equal(session.render(), 'foo V V V bar');
session.set(1, 'VA');
assert.equal(session.render(), 'foo VA VA VA bar');
session.set(1, 'VAL');
assert.equal(session.render(), 'foo VAL VAL VAL bar');
session.set(1, 'VALU');
assert.equal(session.render(), 'foo VALU VALU VALU bar');
session.set(1, 'VALUE');
assert.equal(session.render(), 'foo VALUE VALUE VALUE bar');
session.set(1, void 0);
assert.equal(session.render(), 'foo bar');
});
});