|
|
|
@ -1,4 +1,4 @@ |
|
|
|
import { createTokenParser } from '../utils/string-utils'; |
|
|
|
import { createTokenParser, interpolate } from '../utils/string-utils'; |
|
|
|
|
|
|
|
describe('String Utils', () => { |
|
|
|
describe('#createTokenParser', () => { |
|
|
|
@ -19,4 +19,28 @@ describe('String Utils', () => { |
|
|
|
}, |
|
|
|
); |
|
|
|
}); |
|
|
|
|
|
|
|
describe('#interpolate', () => { |
|
|
|
test.each` |
|
|
|
text | params | expected |
|
|
|
${'This is {0} and {1} example.'} | ${['foo', 'bar']} | ${'This is foo and bar example.'} |
|
|
|
${'This is {1} and {0} example.'} | ${['foo', 'bar']} | ${'This is bar and foo example.'} |
|
|
|
${'This is {0} and {0} example.'} | ${['foo', 'bar']} | ${'This is foo and foo example.'} |
|
|
|
${'This is {1} and {1} example.'} | ${['foo', 'bar']} | ${'This is bar and bar example.'} |
|
|
|
${'This is "{0}" and "{1}" example.'} | ${['foo', 'bar']} | ${'This is foo and bar example.'} |
|
|
|
${"This is '{1}' and '{0}' example."} | ${['foo', 'bar']} | ${'This is bar and foo example.'} |
|
|
|
${'This is { 0 } and {0} example.'} | ${['foo', 'bar']} | ${'This is foo and foo example.'} |
|
|
|
${'This is {1} and { 1 } example.'} | ${['foo', 'bar']} | ${'This is bar and bar example.'} |
|
|
|
${'This is {0}, {3}, {1}, and {2} example.'} | ${['foo', 'bar', 'baz', 'qux']} | ${'This is foo, qux, bar, and baz example.'} |
|
|
|
${'This is {0} with 0 example.'} | ${['foo']} | ${'This is foo with 0 example.'} |
|
|
|
${'This is {0} and {1} example.'} | ${['foo']} | ${'This is foo and {1} example.'} |
|
|
|
${'This is {0} and {1} example.'} | ${[]} | ${'This is {0} and {1} example.'} |
|
|
|
${'This is {0} example.'} | ${[null]} | ${'This is {0} example.'} |
|
|
|
`(
|
|
|
|
'should return $expected when text is $text and params are $params', |
|
|
|
({ text, params, expected }) => { |
|
|
|
expect(interpolate(text, params)).toBe(expected); |
|
|
|
}, |
|
|
|
); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|