Skip to content
Permalink
Browse files

Fix bug where 了 didn't return all the dictionary entries, only the fu…

…rthest one
  • Loading branch information...
nieldlr committed Jan 26, 2019
1 parent bf47430 commit d7f48df95c38bf3b9cad300e4516b85293eb9d8a
Showing with 54 additions and 2 deletions.
  1. +29 −2 lib/dictionary.js
  2. +25 −0 test/dictionary.js
@@ -33,8 +33,35 @@ function start() {
i++;
}

dictionarysimplified[multiplearray[0].simplified] = multiplearray;
dictionarytraditional[multiplearray[0].traditional] = multiplearray;
if (
typeof dictionarysimplified[multiplearray[0].simplified] != 'undefined'
) {
let newMultipleArray = dictionarysimplified[multiplearray[0].simplified];
for (var j = 0; j < multiplearray.length; j++) {
newMultipleArray.push(multiplearray[j]);
}

dictionarysimplified[multiplearray[0].simplified] = newMultipleArray;
} else {
dictionarysimplified[multiplearray[0].simplified] = multiplearray;
}

if (
typeof dictionarytraditional[multiplearray[0].traditional] != 'undefined'
) {
let newMultipleArray =
dictionarytraditional[multiplearray[0].traditional];
for (var j = 0; j < multiplearray.length; j++) {
newMultipleArray.push(multiplearray[j]);
}

dictionarytraditional[multiplearray[0].traditional] = newMultipleArray;
} else {
dictionarytraditional[multiplearray[0].traditional] = multiplearray;
}

// dictionarysimplified[multiplearray[0].simplified] = multiplearray;
// dictionarytraditional[multiplearray[0].traditional] = multiplearray;
}

function nextCharTraditional(j) {
@@ -136,6 +136,31 @@ describe('hanzidictionary', function() {
assert.deepEqual(hanzi.definitionLookup(''), expected);
});

it('should look up a definition of 了 correctly which multiple entries across the whole dictionary', function() {
var expected = [
{
traditional: '',
simplified: '',
pinyin: 'le5',
definition:
'(modal particle intensifying preceding clause)/(completed action marker)'
},
{
traditional: '',
simplified: '',
pinyin: 'liao3',
definition: 'to finish/to achieve/to understand'
},
{
traditional: '',
simplified: '',
pinyin: 'liao3',
definition: '(of eyes) bright/clear-sighted/to understand clearly'
}
];
assert.deepEqual(hanzi.definitionLookup(''), expected);
});

it('should fail looking up a definition with dirty input', function() {
assert.deepEqual(hanzi.definitionLookup('%'), undefined);
});

0 comments on commit d7f48df

Please sign in to comment.
You can’t perform that action at this time.