refactor(common/lmlayer): generate searchTermToKey test cases

This commit is contained in:
Eddie Antonio Santos 2020-04-23 14:55:33 -06:00
parent 075848cf22
commit 0b2f4eb3b0
No known key found for this signature in database
GPG key ID: DD411EA4D9509D87

View file

@ -5,21 +5,28 @@ import { defaultSearchTermToKey } from '../dist/lexical-model-compiler/build-tri
describe('The default searchTermToKey() function', function () {
it('should lowercase and THEN normalize', function() {
const testCases: [string, string][] = [
// "İstanbul" has a U+0130 LATIN CAPITAL LETTER I WITH DOT ABOVE.
// This should be lowercased.
assert.equal(defaultSearchTermToKey('İstanbul'), 'istanbul');
['İstanbul', 'istanbul'],
// The DEFAULT function is NOT responsible for understanding the Turkish
// case regarding the lowercasing of:
// 'I' U+0048 LATIN CAPITAL LETTER I to 'ı' U+0131 LATIN SMALL LETTER DOTLESS I
// For Turkic languages, the recommendation is to make a
// custom searchTermToKey function:
assert.equal(defaultSearchTermToKey('DİYARBAKIR'), 'diyarbakir');
['DİYARBAKIR', 'diyarbakir'],
// "skýlos" is Greek for dog 🇬🇷🐶
// starts with an 's' and ends with an 's'
// which are DIFFERENT CHARACTERS in lowercased Greek!
assert.equal(defaultSearchTermToKey('σκύλος'), 'σκυλος');
assert.equal(defaultSearchTermToKey('ΣΚΥΛΟΣ'), 'σκυλος');
});
});
['σκύλος', 'σκυλος'],
['ΣΚΥΛΟΣ', 'σκυλος'],
];
for (let [input, expected] of testCases) {
it(`should normalize '${input}' to '${expected}'`, function() {
assert.equal(defaultSearchTermToKey(input), expected);
});
}
});