44 * ------------------------------------------------------------------------------------------ */
55
66import { describe , it } from 'mocha' ;
7- import { doesNotMatch , match , strictEqual } from 'node:assert' ;
8- import { escapePathForSquiggles } from '../../src/Utility/Text/escape' ;
7+ import { deepStrictEqual , doesNotMatch , match , ok , strictEqual } from 'node:assert' ;
8+ import { escapePathForSquiggles , getTextMatchOffsets } from '../../src/Utility/Text/escape' ;
99
1010describe ( 'Text escaping' , ( ) => {
1111 it ( 'escapes paths for matching their JSON spelling' , ( ) => {
@@ -29,4 +29,30 @@ describe('Text escaping', () => {
2929 doesNotMatch ( String . raw `C:\sdk\[headers]+(x)?.h\say\"hello\"and\"goodbye` , pattern ) ;
3030 doesNotMatch ( String . raw `C:\\sdk\\headers+(x)?.h\\say\"hello\"and\"goodbye` , pattern ) ;
3131 } ) ;
32+
33+ it ( 'uses the full source match for a non-first semicolon-delimited path' , ( ) => {
34+ const parsedPath : string = 'second' ;
35+ const sourceMatch : string = '"first;second;third"' ;
36+ const text : string = `"includePath": [${ sourceMatch } ]` ;
37+ const pattern : RegExp = new RegExp ( `"[^"]*?(?<="|;)${ escapePathForSquiggles ( parsedPath ) } (?="|;).*?"` , 'g' ) ;
38+ const matches : string [ ] | null = text . match ( pattern ) ;
39+
40+ ok ( matches ) ;
41+ strictEqual ( matches ?. [ 0 ] , sourceMatch ) ;
42+ const startOffset : number = text . indexOf ( sourceMatch ) ;
43+ deepStrictEqual ( getTextMatchOffsets ( text , matches [ 0 ] ) , [ startOffset , startOffset + sourceMatch . length ] ) ;
44+ } ) ;
45+
46+ it ( 'uses the JSON source length when it differs from the parsed path' , ( ) => {
47+ const parsedPath : string = 'folder"quoted"' ;
48+ const sourceMatch : string = String . raw `"folder\"quoted\""` ;
49+ const text : string = `"includePath": [${ sourceMatch } ]` ;
50+ const pattern : RegExp = new RegExp ( `"[^"]*?(?<="|;)${ escapePathForSquiggles ( parsedPath ) } (?="|;).*?"` , 'g' ) ;
51+ const matches : string [ ] | null = text . match ( pattern ) ;
52+
53+ ok ( matches ) ;
54+ strictEqual ( matches ?. [ 0 ] , sourceMatch ) ;
55+ const startOffset : number = text . indexOf ( sourceMatch ) ;
56+ deepStrictEqual ( getTextMatchOffsets ( text , matches [ 0 ] ) , [ startOffset , startOffset + sourceMatch . length ] ) ;
57+ } ) ;
3258} ) ;
0 commit comments