name-suggestion-index/tests/simplify.test.js
Bryan Housel 8c7037eede Swap jest for node-tap
node-tap is much simpler, and jest's babel transformer was messing stuff up
2021-06-22 10:27:24 -04:00

57 lines
1.5 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { test } from 'tap';
import { simplify } from '../index.mjs';
test('simplify', t => {
t.test('lowercases', t => {
t.equal(simplify('Aldo'), 'aldo');
t.end();
});
t.test('replaces diacritics', t => {
t.equal(simplify('André'), 'andre');
t.end();
});
t.test('removes spaces', t => {
t.equal(simplify('Jimmy Choo'), 'jimmychoo');
t.end();
});
t.test('removes various dashes', t => {
t.equal(simplify('PTV - Metropolitan'), 'ptvmetropolitan'); // hypen
t.equal(simplify('PTV Metropolitan'), 'ptvmetropolitan'); // en dash (U+2013)
t.equal(simplify('PTV — Metropolitan'), 'ptvmetropolitan'); // em dash (U+2014)
t.equal(simplify('PTV ― Metropolitan'), 'ptvmetropolitan'); // horizontal bar (U+2015)
t.end();
});
t.test('removes unprintable unicode (like RTL/LTR marks, zero width space, zero width nonjoiner)', t => {
t.equal(simplify('\u200FJim\u200Bmy\u200CChoo\u200E'), 'jimmychoo');
t.end();
});
t.test('removes punctuation', t => {
t.equal(simplify('K+K Schuh-Center'), 'kkschuhcenter');
t.end();
});
t.test('replaces & with and', t => {
t.equal(simplify('Johnston & Murphy'), 'johnstonandmurphy');
t.end();
});
t.test('replaces ß (eszett) with ss', t => {
t.equal(simplify('Beßon'), 'besson');
t.end();
});
t.test('returns empty string if no input', t => {
t.equal(simplify(), '');
t.equal(simplify(null), '');
t.equal(simplify({}), '');
t.end();
});
t.end();
});