Skip to content

Commit

Permalink
Merge 8233c3e into dec4cdf
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S committed Jan 11, 2020
2 parents dec4cdf + 8233c3e commit 0c19dc7
Show file tree
Hide file tree
Showing 18 changed files with 382 additions and 383 deletions.
51 changes: 32 additions & 19 deletions packages/cspell-lib/src/SpellingDictionary/Dictionaries.test.ts
Expand Up @@ -4,28 +4,39 @@ import { getDefaultSettings } from '../Settings';
// cspell:ignore café rhône

describe('Validate getDictionary', () => {
test('tests that userWords are included in the dictionary', () => {
test('tests that userWords are included in the dictionary', async () => {
const settings = {
...getDefaultSettings(),
words: ['one', 'two', 'three', 'café'],
words: ['one', 'two', 'three', 'café', '!snarf'],
userWords: ['four', 'five', 'six', 'Rhône'],
};

return Dictionaries.getDictionary(settings).then(dict => {
settings.words.forEach(word => {
expect(dict.has(word)).toBe(true);
});
settings.userWords.forEach(word => {
expect(dict.has(word)).toBe(true);
});
expect(dict.has('zero', { ignoreCase: false })).toBe(false);
expect(dict.has('Rhône', { ignoreCase: false })).toBe(true);
expect(dict.has('RHÔNE', { ignoreCase: false })).toBe(true);
expect(dict.has('Café', { ignoreCase: false })).toBe(true);
expect(dict.has('rhône', { ignoreCase: false })).toBe(true);
expect(dict.has('rhone', { ignoreCase: false })).toBe(true);
expect(dict.has('cafe', { ignoreCase: false })).toBe(true);
});
const dict = await Dictionaries.getDictionary(settings);
settings.words.forEach(w => {
const word = w.replace(/^[!+*]+(.*)[*+]+/, '$1');
const found = w[0] !== '!';
const result = {word, found: dict.has(word)};
expect(result).toEqual({ word, found });
});
settings.userWords.forEach(w => {
const word = w.replace(/^[!+*]+(.*)[*+]+/, '$1');
const found = w[0] !== '!';
const result = {word, found: dict.has(word)};
expect(result).toEqual({ word, found });
});
expect(dict.has('zero', { ignoreCase: false })).toBe(false);
expect(dict.has('Café', { ignoreCase: false })).toBe(true);
expect(dict.has('CAFÉ', { ignoreCase: false })).toBe(true);
expect(dict.has('café', { ignoreCase: false })).toBe(true);
expect(dict.has('cafe', { ignoreCase: true })).toBe(true);
expect(dict.has('CAFE', { ignoreCase: true })).toBe(true);
expect(dict.has('Rhône', { ignoreCase: false })).toBe(true);
expect(dict.has('RHÔNE', { ignoreCase: false })).toBe(true);
expect(dict.has('rhône', { ignoreCase: false })).toBe(false);
expect(dict.has('rhône', { ignoreCase: true })).toBe(true);
expect(dict.has('rhone', { ignoreCase: false })).toBe(false);
expect(dict.has('rhone', { ignoreCase: true })).toBe(true);
expect(dict.has('snarf', { ignoreCase: true })).toBe(false);
});

test('Case sensitive', async () => {
Expand All @@ -38,10 +49,12 @@ describe('Validate getDictionary', () => {

const dict = await Dictionaries.getDictionary(settings);
settings.words.forEach(word => {
expect(dict.has(word)).toBe(true);
const result = {word, found: dict.has(word)};
expect(result).toEqual({ word, found: true });
});
settings.userWords.forEach(word => {
expect(dict.has(word)).toBe(true);
const result = {word, found: dict.has(word)};
expect(result).toEqual({ word, found: true });
});
const opts = { ignoreCase: false };
expect(dict.has('zero')).toBe(false);
Expand Down
3 changes: 2 additions & 1 deletion packages/cspell-lib/src/SpellingDictionary/Dictionaries.ts
@@ -1,7 +1,8 @@
import { DictionaryDefinition, DictionaryId, CSpellUserSettings } from '../Settings';
import { filterDictDefsToLoad } from '../Settings/DictionarySettings';
import { loadDictionary } from './DictionaryLoader';
import { SpellingDictionary, createSpellingDictionary } from './SpellingDictionary';
import { createSpellingDictionary } from "./createSpellingDictionary";
import { SpellingDictionary } from "./SpellingDictionary";
import { createCollectionP } from './SpellingDictionaryCollection';
import { SpellingDictionaryCollection } from './index';

Expand Down
@@ -1,5 +1,7 @@
import { splitLineIntoWords, splitLineIntoCodeWords, loadWordsNoError } from '../wordListHelper';
import { SpellingDictionary, createSpellingDictionaryTrie, createSpellingDictionary } from './SpellingDictionary';
import { createSpellingDictionaryTrie } from './SpellingDictionaryFromTrie';
import { createSpellingDictionary } from './createSpellingDictionary';
import { SpellingDictionary } from './SpellingDictionary';
import * as path from 'path';
import { ReplaceMap } from '../Settings';
import { genSequence } from 'gensequence';
Expand Down
@@ -1,4 +1,6 @@
import { createSpellingDictionary, SpellingDictionaryFromTrie, __testMethods } from './SpellingDictionary';
import { __testMethods } from './SpellingDictionaryMethods';
import { createSpellingDictionary } from './createSpellingDictionary';
import { SpellingDictionaryFromTrie } from './SpellingDictionaryFromTrie';
import { Trie } from 'cspell-trie-lib';
import { FunctionArgs } from '../util/types';

Expand Down Expand Up @@ -131,28 +133,29 @@ describe('Validate wordSearchForms', () => {
type TestCase = FunctionArgs<typeof testCase>;
// cspell:ignore café
const tests: TestCase[] = [
// word, dic is case sensitive, ignoreCase on lookup, expected
['house', false, false, ['house']],
['House', false, false, ['House', 'house']],
['House', false, false, ['House', 'house']],
['House', false, false, ['house']],
['House', false, false, ['house']],
['House', true, false, ['House', 'house']],
['HOUSE', false, false, ['HOUSE', 'House', 'house']],
['HOUSE', false, false, ['house']],
['HOUSE', true, false, ['HOUSE', 'House', 'house']],
['café', false, false, ['cafe', 'café']],
['café', false, false, ['café']],
['café', true, false, ['café']],
['café', true, true, ['café', '>cafe']],
['Café', false, false, ['Cafe', 'Café', 'cafe', 'café']],
['Café', false, true, ['Café', 'Cafe', 'cafe', 'café']],
['café', true, true, ['cafe']],
['Café', false, false, ['café']],
['Café', false, true, ['cafe', 'café']],
['Café', true, false, ['Café', 'café']],
['Café', true, true, ['Café', '>Cafe', '>cafe', 'café']],
['CAFÉ', false, false, ['CAFÉ', 'CAFE', 'Café', 'café', 'cafe']],
['CAFÉ', false, true, ['CAFÉ', 'CAFE', 'Café', 'café', 'cafe']],
['Café', true, true, ['cafe']],
['CAFÉ', false, false, ['café']],
['CAFÉ', false, true, ['cafe', 'café']],
['CAFÉ', true, false, ['CAFÉ', 'Café', 'café']],
['CAFÉ', true, true, ['CAFÉ', 'Café', 'café', '>CAFE', '>Cafe', '>cafe']],
['CAFÉ', true, true, ['cafe']],
// Make sure all accent forms work.
['café'.normalize(), false, false, ['cafe', 'café']],
['café'.normalize('NFD'), false, false, ['cafe', 'café']],
['café'.normalize('NFKC'), false, false, ['cafe', 'café']],
['café'.normalize('NFKD'), false, false, ['cafe', 'café']],
['café'.normalize(), false, false, ['café']],
['café'.normalize('NFD'), false, false, ['café']],
['café'.normalize('NFKC'), false, false, ['café']],
['café'.normalize('NFKD'), false, false, ['café']],
];
tests.forEach(t => testCase(...t));
});
Expand Down Expand Up @@ -187,9 +190,6 @@ describe('Verify Case Sensitive Dictionaries', () => {
const sugs = dict.suggest('kuln'); // cspell:disable-line
const sugWords = sugs.map(s => s.word);
expect(sugWords).toEqual([
'koln',
'köln',
'Koln',
'Köln',
]);
});
Expand Down

0 comments on commit 0c19dc7

Please sign in to comment.