Skip to content

Commit

Permalink
feat: All flagWords and suggestWords suggestions are preferred. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S authored Feb 15, 2023
1 parent 7f17e32 commit abfb09c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createSuggestDictionary } from './SuggestDictionary';

// const oc = expect.objectContaining;
const isPreferred = true;

describe('SuggestDictionary 1', () => {
const dictWords = [' english:English', 'red->green', 'blue:purple', 'yellow->white'];
Expand Down Expand Up @@ -86,18 +87,18 @@ describe('SuggestDictionary 2', () => {
test.each`
word | expected
${''} | ${[]}
${'Avocado'} | ${[{ cost: 1, isPreferred: true, word: 'Avocado' }]}
${'avocado'} | ${[{ cost: 1, isPreferred: true, word: 'Avocado' }]}
${'cafe'} | ${[{ cost: 1, isPreferred: true, word: 'café' }]}
${'English'} | ${[{ word: 'English', isPreferred: true, cost: 1 }]}
${'english'} | ${[{ word: 'English', isPreferred: true, cost: 1 }]}
${'Avocado'} | ${[{ cost: 1, isPreferred, word: 'Avocado' }]}
${'avocado'} | ${[{ cost: 1, isPreferred, word: 'Avocado' }]}
${'cafe'} | ${[{ cost: 1, isPreferred, word: 'café' }]}
${'English'} | ${[{ word: 'English', isPreferred, cost: 1 }]}
${'english'} | ${[{ word: 'English', isPreferred, cost: 1 }]}
${'grumpy'} | ${[]}
${'red'} | ${[{ cost: 1, isPreferred: true, word: 'green' }]}
${'red'} | ${[{ cost: 1, isPreferred, word: 'green' }]}
${'green'} | ${[]}
${'blue'} | ${[{ cost: 1, word: 'purple' }, { cost: 2, word: 'cyan' }]}
${'yellow'} | ${[{ cost: 1, word: 'white' }, { cost: 2, word: 'black' }]}
${'blue'} | ${[{ cost: 1, isPreferred, word: 'purple' }, { cost: 2, isPreferred, word: 'cyan' }]}
${'yellow'} | ${[{ cost: 1, isPreferred, word: 'white' }, { cost: 2, isPreferred, word: 'black' }]}
${'Grumpy'} | ${[]}
${'wont'} | ${[{ word: "won't", cost: 1 }, { word: 'will not', cost: 2 }]}
${'wont'} | ${[{ word: "won't", isPreferred, cost: 1 }, { word: 'will not', isPreferred, cost: 2 }]}
`('suggest of "$word"', async ({ word, expected }) => {
expect(dict.suggest(word)).toEqual(expected);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,18 @@ class SuggestDictionaryImpl implements SuggestDictionary {
private _suggest(word: string): SuggestionResult[] | undefined {
if (!(word in this.typosDef)) return undefined;
const sug = this.typosDef[word];
const isPreferred = true;
if (!sug) return [];
if (typeof sug === 'string') {
return [
{
word: sug,
cost: 1,
isPreferred: true,
isPreferred,
},
];
}
return sug.map((word, index) => ({ word, cost: index + 1 }));
return sug.map((word, index) => ({ word, cost: index + 1, isPreferred }));
}

genSuggestions(collector: SuggestionCollector): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createTyposDictionary } from './TyposDictionary';

// const oc = expect.objectContaining;
const isPreferred = true;

describe('TyposDictionary 1', () => {
const dictWords = [' english:English', 'grumpy', 'Avocado', 'avocadoS', '!avocado', 'crud'];
Expand Down Expand Up @@ -202,14 +203,14 @@ describe('TyposDictionary 2', () => {
test.each`
word | expected
${''} | ${[]}
${'Avocado'} | ${[{ cost: 1, isPreferred: true, word: 'Avocado' }]}
${'avocado'} | ${[{ cost: 1, isPreferred: true, word: 'Avocado' }]}
${'cafe'} | ${[{ cost: 1, isPreferred: true, word: 'café' }]}
${'English'} | ${[{ word: 'English', isPreferred: true, cost: 1 }]}
${'english'} | ${[{ word: 'English', isPreferred: true, cost: 1 }]}
${'Avocado'} | ${[{ cost: 1, isPreferred, word: 'Avocado' }]}
${'avocado'} | ${[{ cost: 1, isPreferred, word: 'Avocado' }]}
${'cafe'} | ${[{ cost: 1, isPreferred, word: 'café' }]}
${'English'} | ${[{ word: 'English', isPreferred, cost: 1 }]}
${'english'} | ${[{ word: 'English', isPreferred, cost: 1 }]}
${'grumpy'} | ${[]}
${'Grumpy'} | ${[]}
${'wont'} | ${[{ word: "won't", cost: 1 }, { word: 'will not', cost: 2 }]}
${'wont'} | ${[{ word: "won't", isPreferred, cost: 1 }, { word: 'will not', isPreferred, cost: 2 }]}
`('suggest of "$word"', async ({ word, expected }) => {
expect(dict.suggest(word)).toEqual(expected);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,18 @@ class TyposDictionaryImpl implements TyposDictionary {
if (this.ignoreWords.has(word)) return [];
if (!(word in this.typosDef)) return undefined;
const sug = this.typosDef[word];
const isPreferred = true;
if (!sug) return [];
if (typeof sug === 'string') {
return [
{
word: sug,
cost: 1,
isPreferred: true,
isPreferred,
},
];
}
return sug.map((word, index) => ({ word, cost: index + 1 }));
return sug.map((word, index) => ({ word, cost: index + 1, isPreferred }));
}

genSuggestions(collector: SuggestionCollector): void {
Expand Down

0 comments on commit abfb09c

Please sign in to comment.