-
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support multiple
repMap
combinations (#4270)
- Loading branch information
Showing
9 changed files
with
208 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 18 additions & 9 deletions
27
packages/cspell-dictionary/src/SpellingDictionary/SpellingDictionaryFromTrie.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,28 @@ | ||
import { createMapper } from '../util/repMap'; | ||
import { __testing__ } from './SpellingDictionaryFromTrie'; | ||
import { buildTrieFast } from 'cspell-trie-lib'; | ||
|
||
import { __testing__, SpellingDictionaryFromTrie } from './SpellingDictionaryFromTrie'; | ||
|
||
const { outerWordForms } = __testing__; | ||
|
||
// cspell:ignore guenstig günstig Bundesstaat Bundeßtaat | ||
// cspell:ignore Goerresstraße, Goerreßtraße, Görresstraße, Görreßtraße | ||
|
||
describe('SpellingDictionaryFromTrie', () => { | ||
test.each` | ||
word | repMap | expected | ||
${'hello'} | ${undefined} | ${['hello']} | ||
${'guenstig'} | ${[['ae', 'ä'], ['oe', 'ö'], ['ue', 'ü'], ['ss', 'ß']]} | ${['guenstig', 'günstig']} | ||
${'günstig'} | ${[['ae', 'ä'], ['oe', 'ö'], ['ue', 'ü'], ['ss', 'ß']]} | ${['günstig', 'günstig'.normalize('NFD')]} | ||
${'Bundesstaat'} | ${[['ae', 'ä'], ['oe', 'ö'], ['ue', 'ü'], ['ss', 'ß']]} | ${['Bundesstaat', 'Bundeßtaat']} | ||
word | repMap | expected | ||
${'hello'} | ${undefined} | ${['hello']} | ||
${'guenstig'} | ${[['ae', 'ä'], ['oe', 'ö'], ['ue', 'ü'], ['ss', 'ß']]} | ${['guenstig', 'günstig']} | ||
${'günstig'} | ${[['ae', 'ä'], ['oe', 'ö'], ['ue', 'ü'], ['ss', 'ß']]} | ${['günstig', N('günstig')]} | ||
${'Bundesstaat'} | ${[['ae', 'ä'], ['oe', 'ö'], ['ue', 'ü'], ['ss', 'ß']]} | ${['Bundesstaat', 'Bundeßtaat']} | ||
${'Goerresstraße'} | ${[['ae', 'ä'], ['oe', 'ö'], ['ue', 'ü'], ['ss', 'ß']]} | ${['Goerresstraße', 'Goerreßtraße', 'Görresstraße', 'Görreßtraße']} | ||
`('outerWordForms $word', ({ word, repMap, expected }) => { | ||
const mapWord = createMapper(repMap); | ||
expect(outerWordForms(word, mapWord ?? ((a) => a))).toEqual(new Set(expected)); | ||
const trie = buildTrieFast([]); | ||
const dict = new SpellingDictionaryFromTrie(trie, 'test', { repMap }); | ||
const mapWord = dict.remapWord || ((a) => [dict.mapWord(a)]); | ||
expect(outerWordForms(word, mapWord)).toEqual(new Set(expected)); | ||
}); | ||
}); | ||
|
||
function N(s: string, mode: 'NFD' | 'NFC' = 'NFD') { | ||
return s.normalize(mode); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters