Skip to content

Commit 47ececf

Browse files
committedMay 5, 2021
Revert "fix: Correctly handle leading and trailing single quote"
This reverts commit 41152e1.
1 parent 41152e1 commit 47ececf

File tree

4 files changed

+9
-21
lines changed

4 files changed

+9
-21
lines changed
 

‎packages/cspell-lib/src/util/text.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ describe('Validate individual regexp', () => {
300300
test.each`
301301
testName | regexp | text | expectedResult
302302
${'regExWordsAndDigits'} | ${regExWordsAndDigits} | ${''} | ${[]}
303-
${'regExWordsAndDigits'} | ${regExWordsAndDigits} | ${" x = 'Don\\'t'"} | ${['x', 1, "'Don\\'t'", 5]}
303+
${'regExWordsAndDigits'} | ${regExWordsAndDigits} | ${" x = 'Don\\'t'"} | ${['x', 1, "Don\\'t", 6]}
304304
${'regExWordsAndDigits'} | ${regExWordsAndDigits} | ${'12345'} | ${[]}
305305
${'regExWordsAndDigits'} | ${regExWordsAndDigits} | ${'12345a'} | ${['12345a', 0]}
306306
${'regExWordsAndDigits'} | ${regExWordsAndDigits} | ${'b12345'} | ${['b12345', 0]}

‎packages/cspell-lib/src/util/textRegex.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const regExUpperSOrIng = /(\p{Lu}+\\?['’]?(?:s|ing|ies|es|ings|ed|ning)
55
export const regExSplitWords = /(\p{Ll})(\p{Lu})/gu;
66
export const regExSplitWords2 = /(\p{Lu})(\p{Lu}\p{Ll})/gu;
77
export const regExWords = /\p{L}(?:(?:\\?['])?\p{L})*/gu;
8-
export const regExWordsAndDigits = /(?:\d+)?[\p{L}_'-](?:(?:\\?['])?[\p{L}\w'-])*/gu;
8+
export const regExWordsAndDigits = /(?:\d+)?[\p{L}_-](?:(?:\\?['])?[\p{L}\w-])*/gu;
99
export const regExIgnoreCharacters = /\p{sc=Hiragana}|\p{sc=Han}|\p{sc=Katakana}|[\u30A0-\u30FF]|[\p{sc=Hangul}]/gu;
1010
export const regExFirstUpper = /^\p{Lu}\p{Ll}+$/u;
1111
export const regExAllUpper = /^\p{Lu}+$/u;

‎packages/cspell-lib/src/util/wordSplitter.test.ts

+7-17
Original file line numberDiff line numberDiff line change
@@ -65,27 +65,26 @@ describe('Validate wordSplitter', () => {
6565
expect(r).toMatchSnapshot(); // Use snapshots to ensure all possible options are generated.
6666
});
6767

68-
interface PartialTextOffsetWithIsFound {
68+
interface PartialTextOffsetWithValid {
6969
text: string;
7070
offset?: number;
7171
isFound?: boolean;
7272
}
7373

7474
interface TestSplit {
7575
text: string;
76-
expectedWords: PartialTextOffsetWithIsFound[];
76+
expectedWords: PartialTextOffsetWithValid[];
7777
}
7878

79-
/** to PartialTextOffsetWithIsFound */
80-
function tov(p: PartialTextOffsetWithIsFound | string, defaultIsFound = true): PartialTextOffsetWithIsFound {
79+
function tov(p: PartialTextOffsetWithValid | string, isValid = true): PartialTextOffsetWithValid {
8180
if (typeof p === 'string') {
8281
p = { text: p };
8382
}
84-
const { isFound = defaultIsFound } = p;
83+
const { isFound = isValid } = p;
8584
return { ...p, isFound };
8685
}
8786

88-
function splitTov(t: string): PartialTextOffsetWithIsFound[] {
87+
function splitTov(t: string): PartialTextOffsetWithValid[] {
8988
if (!t) return [];
9089
const parts = t.split('|');
9190
return parts.map((p) => tov(p, has({ text: p, offset: 0 })));
@@ -174,13 +173,11 @@ describe('Validate wordSplitter', () => {
174173
${'nstatic'} | ${'static'} | ${1}
175174
${'techo'} | ${'echo'} | ${1}
176175
${`n'cpp`} | ${'cpp'} | ${1}
177-
${`n'log`} | ${'log'} | ${7}
176+
${`n'log`} | ${'log'} | ${4}
178177
${'64-bit'} | ${'bit'} | ${1}
179178
${'128-bit'} | ${'bit'} | ${1}
180179
${'256-sha'} | ${'256-sha'} | ${6}
181180
${`REFACTOR'd`} | ${'REFACTOR'} | ${2}
182-
${`dogs'`} | ${`dogs'`} | ${2}
183-
${`planets’`} | ${`planets’`} | ${2}
184181
`('split `$text` in doc', ({ text, expectedWords, calls }: TestSplit2) => {
185182
const expectedWordSegments = splitTov(expectedWords);
186183
const doc = sampleText();
@@ -321,10 +318,6 @@ function sampleWordSet() {
321318
well educated
322319
words separated by singleQuote
323320
256-sha
324-
dogs'
325-
leashes
326-
writers
327-
planets’
328321
`
329322
.split(/\s+/g)
330323
.map((a) => a.trim())
@@ -350,11 +343,8 @@ function sampleText() {
350343
351344
256-sha
352345
353-
- The dogs' leashes (multiple dogs).
354-
- The writers' desks (multiple writers).
355-
- The planets’ atmospheres (multiple planets).
356-
357346
128-bit values
358347
348+
359349
`;
360350
}

‎packages/cspell-lib/src/util/wordSplitter.ts

-2
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,6 @@ function genSymbolBreaks(line: LineSegment): SortedBreaks[] {
265265
return [
266266
calcBreaksForRegEx(line, regExPossibleWordBreaks, calcBreaks),
267267
calcBreaksForRegEx(line, /\d+/g, calcBreaks),
268-
calcBreaksForRegEx(line, /['](?!\p{L})/gu, calcBreaks), // break on trailing '
269-
calcBreaksForRegEx(line, /(?<!\p{L})[']/gu, calcBreaks), // break on leading '
270268
calcBreaksForRegEx(line, regExEscapeCharacters, calcBreaks),
271269
];
272270
}

0 commit comments

Comments
 (0)
Please sign in to comment.