2016-08-26 14:57:27 +08:00
|
|
|
import test from 'ava';
|
2017-09-19 03:05:26 +08:00
|
|
|
import { escapeHTML, unescapeHTML, findUniqueName } from '../src/utils/stringUtils'
|
2016-08-26 14:57:27 +08:00
|
|
|
|
2017-09-19 03:05:26 +08:00
|
|
|
test('escapeHTML', t => {
|
|
|
|
t.is(escapeHTML(' hello '), '\u00A0\u00A0 hello \u00A0')
|
|
|
|
t.is(escapeHTML('\u00A0 hello'), '\u00A0 hello')
|
|
|
|
t.is(escapeHTML('hello\nworld'), 'hello\\nworld')
|
|
|
|
|
|
|
|
// TODO: test escapeHTML more thorougly
|
|
|
|
})
|
|
|
|
|
|
|
|
test('unescapeHTML', t => {
|
|
|
|
t.is(unescapeHTML(' \u00A0 hello \u00A0'), ' hello ')
|
|
|
|
t.is(unescapeHTML('\u00A0 hello'), ' hello')
|
2016-08-26 14:57:27 +08:00
|
|
|
|
2017-09-19 03:05:26 +08:00
|
|
|
t.is(unescapeHTML('hello\\nworld'), 'hello\nworld')
|
|
|
|
|
|
|
|
// TODO: test unescapeHTML more thorougly
|
|
|
|
})
|
|
|
|
|
|
|
|
test('findUniqueName', t => {
|
2016-08-26 14:57:27 +08:00
|
|
|
t.is(findUniqueName('other', ['a', 'b', 'c']), 'other')
|
|
|
|
t.is(findUniqueName('b', ['a', 'b', 'c']), 'b (copy)')
|
|
|
|
t.is(findUniqueName('b', ['a', 'b', 'c', 'b (copy)']), 'b (copy 2)')
|
|
|
|
t.is(findUniqueName('b', ['a', 'b', 'c', 'b (copy)', 'b (copy 2)']), 'b (copy 3)')
|
2017-09-19 03:05:26 +08:00
|
|
|
})
|