From 4e96c319d00975fb3ec86b3f6c59c98190650d06 Mon Sep 17 00:00:00 2001 From: Matthew Chase Whittemore Date: Tue, 5 Sep 2017 18:17:49 -0400 Subject: [PATCH] add some tests for index.tokenize --- test/index_test.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/index_test.js b/test/index_test.js index 48540cbe2..a027c1cb6 100644 --- a/test/index_test.js +++ b/test/index_test.js @@ -4,6 +4,38 @@ var tape = require('tape'); var instructions = require('../index'); +tape.test('v5 tokenize', function(assert) { + var v5Instructions = instructions('v5'); + + var tokenString = 'Can {first} {second}'; + + var hasBoth = v5Instructions.tokenize(tokenString, { + first: 'osrm', + second: 'do routing' + }, 'en'); + assert.equal(hasBoth, 'Can osrm do routing', 'does find and replace'); + + var hasFirst = v5Instructions.tokenize(tokenString, { + first: 'osrm', + second: '' + }, 'en'); + assert.equal(hasFirst, 'Can osrm ', 'does find and replace and does not drop trailing spaces'); + + var hasSecond = v5Instructions.tokenize(tokenString, { + second: 'swim', + first: '' + }, 'en'); + assert.equal(hasSecond, 'Can swim', 'does find and replace and drops internal extra spaces'); + + var missingSecond = v5Instructions.tokenize(tokenString, { + first: 'osrm' + }, 'en'); + assert.equal(missingSecond, 'Can osrm {second}', 'does not replace tokens which are not provided'); + + + assert.end(); +}); + tape.test('v5 directionFromDegree', function(assert) { var v5Instructions = instructions('v5');