romaji-fuzzy-search
Version:
Generates a regular expression for "Romaji Fuzzy Search"
44 lines (43 loc) • 1.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = require("./index");
describe('convertToRegExp', () => {
const table = [
{
name: 'it replaces one romaji',
args: ['a'],
expected: '(?:a|あ|ア)',
},
{
name: 'it replaces two romaji',
args: ['ka'],
expected: '(?:ka|か|カ)',
},
{
name: 'it replaces three romaji',
args: ['kya'],
expected: '(?:kya|きゃ|キャ)',
},
{
name: 'it does not replace a character that is not a romaji',
args: ['k'],
expected: 'k',
},
{
name: 'it escapes characters of regexp pattern',
args: ['.*+?^${}()|[]\\'],
expected: '\\.\\*\\+\\?\\^\\$\\{\\}\\(\\)\\|\\[\\]\\\\',
},
{
name: 'it gives priority to long phrases',
args: ['kyayaay'],
expected: '(?:kya|きゃ|キャ)(?:ya|や|ヤ)(?:a|あ|ア)y',
},
];
test.each(table)('$name', ({ args, expected }) => {
expect(index_1.convertToRegExp(...args)).toBe(expected);
});
test('it can change the romaji dictionary', () => {
expect(index_1.convertToRegExp('ab', { b: ['b', 'び', 'ビ'] })).toBe('a(?:b|び|ビ)');
});
});