Skip to content

Commit 4e96c31

Browse files
committed
add some tests for index.tokenize
1 parent cfb2890 commit 4e96c31

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

test/index_test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,38 @@ var tape = require('tape');
44

55
var instructions = require('../index');
66

7+
tape.test('v5 tokenize', function(assert) {
8+
var v5Instructions = instructions('v5');
9+
10+
var tokenString = 'Can {first} {second}';
11+
12+
var hasBoth = v5Instructions.tokenize(tokenString, {
13+
first: 'osrm',
14+
second: 'do routing'
15+
}, 'en');
16+
assert.equal(hasBoth, 'Can osrm do routing', 'does find and replace');
17+
18+
var hasFirst = v5Instructions.tokenize(tokenString, {
19+
first: 'osrm',
20+
second: ''
21+
}, 'en');
22+
assert.equal(hasFirst, 'Can osrm ', 'does find and replace and does not drop trailing spaces');
23+
24+
var hasSecond = v5Instructions.tokenize(tokenString, {
25+
second: 'swim',
26+
first: ''
27+
}, 'en');
28+
assert.equal(hasSecond, 'Can swim', 'does find and replace and drops internal extra spaces');
29+
30+
var missingSecond = v5Instructions.tokenize(tokenString, {
31+
first: 'osrm'
32+
}, 'en');
33+
assert.equal(missingSecond, 'Can osrm {second}', 'does not replace tokens which are not provided');
34+
35+
36+
assert.end();
37+
});
38+
739
tape.test('v5 directionFromDegree', function(assert) {
840
var v5Instructions = instructions('v5');
941

0 commit comments

Comments
 (0)