Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,54 @@ describe('Verify building Dictionary', () => {
expect(dict.has('MCGREYER', ignoreCase)).toBe(true); // cspell:disable-line
});

// cspell:ignore erroRcode eRRorcODE eRRor
test('case-sensitive legacy compounds keep the written case', () => {
const dict = createSpellingDictionary(
['error', 'code', 'Paris'],
'words',
'test',
opts({ caseSensitive: true, useCompounds: true }),
);
const useCase = { ignoreCase: false };

expect(dict.has('erroRcode', useCase)).toBe(false);
expect(dict.has('eRRorcODE', useCase)).toBe(false);
expect(dict.has('errorCode', useCase)).toBe(false);
expect(dict.find('erroRcode', useCase)).toBe(undefined);
expect(dict.find('error', useCase)?.found).toBe('error');

expect(dict.has('error', useCase)).toBe(true);
expect(dict.has('code', useCase)).toBe(true);
expect(dict.has('Paris', useCase)).toBe(true);
expect(dict.has('errorcode', useCase)).toBe(true);
expect(dict.has('errorParis', useCase)).toBe(true);
expect(dict.has('ERRORCODE', useCase)).toBe(true);
expect(dict.has('PARIS', useCase)).toBe(true);

expect(dict.has('eRRor', useCase)).toBe(true);
expect(dict.has('paris', useCase)).toBe(false);
expect(dict.has('erroRcode', { ignoreCase: true, useCompounds: true })).toBe(true);
expect(dict.has('errorCode', { ignoreCase: true, useCompounds: true })).toBe(true);

const titled = createSpellingDictionary(
['Error', 'Code'],
'words',
'test',
opts({ caseSensitive: true, useCompounds: true }),
);
expect(titled.has('ErrorCode', useCase)).toBe(true);

const plain = createSpellingDictionary(
['error', 'code', 'Paris'],
'words',
'test',
opts({ caseSensitive: true }),
);
expect(plain.has('errorcode', useCase)).toBe(false);
expect(plain.has('ERRORCODE', useCase)).toBe(false);
expect(plain.has('erroRcode', { ignoreCase: false, useCompounds: true })).toBe(false);
});

test('Suggest Trie', () => {
const words = [
'apple',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { CompoundWordsMethod, decodeTrie, suggestionCollector } from 'cspell-tri

import { clean } from '../util/clean.js';
import { measurePerf } from '../util/performance.js';
import { isUpperCase } from '../util/text.js';
import * as Defaults from './defaults.js';
import type {
FindOptionsRO,
Expand Down Expand Up @@ -166,10 +167,16 @@ export class SpellingDictionaryFromTrie implements SpellingDictionary {
if (findResult.found !== false) {
return findResult;
}
for (const w of forms) {
const findResult = this.trie.findWord(w, optsUseCompounds);
if (findResult.found !== false) {
return findResult;
// cspell:ignore eRRorcODE ERRORCODE
// Compound the word as written. Retrying the lower-case form would accept
// mixed case (`eRRorcODE` as `error` + `code`). All-caps still retries,
// matching `wordSearchAlternateForms`, so `ERRORCODE` can match.
if (ignoreCase || !this.isDictionaryCaseSensitive || isUpperCase(mWord)) {
for (const w of forms) {
const findResult = this.trie.findWord(w, optsUseCompounds);
if (findResult.found !== false) {
return findResult;
}
}
}
}
Expand Down
Loading