Add a test for the default wordform to key function.

This commit is contained in:
Eddie Antonio Santos 2019-06-04 11:08:41 -06:00
parent 3f4aa0e9d9
commit 784555b7db
No known key found for this signature in database
GPG key ID: DD411EA4D9509D87
3 changed files with 32 additions and 2 deletions

View file

@ -154,7 +154,36 @@ describe('LMLayerWorker trie model for word lists', function() {
firstResults.map(s => s.displayAs)
);
});
})
});
describe('The default key function', function () {
it('uses the default key function', function () {
var model = new TrieModel(jsonFixture('tries/accented'));
// «nai| » [Send]
// [ ??? ] [ naïve ] [ ??? ]
var [suggestion] = model.predict({
insert: 'i', deleteLeft: 0
}, {
left: 'na',
startOfBuffer: false,
endOfBuffer: true
}).map(getSample);
assert.strictEqual(suggestion.displayAs, 'naïve');
// «Lets get some pho| » [Send]
// [ ??? ] [ phở ] [ ??? ]
var [suggestion] = model.predict({
insert: 'o', deleteLeft: 0
}, {
left: 'Lets get some ph',
startOfBuffer: false,
endOfBuffer: true
}).map(getSample);
assert.strictEqual(suggestion.displayAs, 'phở');
});
});
it('replaces the entire typed word when a suggestion is accepted', function () {
// Ensure that all input is lower-cased when we try to look it up.

View file

@ -0,0 +1 @@
{"type":"internal","weight":1,"values":["p","n"],"children":{"p":{"type":"leaf","weight":1,"entries":[{"key":"pho","weight":1,"content":"phở"}]},"n":{"type":"leaf","weight":1,"entries":[{"key":"naive","weight":1,"content":"naïve"}]}}}

View file

@ -429,7 +429,7 @@
*/
function defaultWordform2Key(wordform: string): SearchKey {
return wordform
.replace(/[\u0100-\u2200]/, function (c) {
.replace(/[\u0100-\u2200]/g, function (c) {
if (c in PARTIAL_NFD_LOOKUP) {
return PARTIAL_NFD_LOOKUP[c];
}