@@ -65,26 +65,27 @@ describe('Validate wordSplitter', () => {
65
65
expect ( r ) . toMatchSnapshot ( ) ; // Use snapshots to ensure all possible options are generated.
66
66
} ) ;
67
67
68
- interface PartialTextOffsetWithValid {
68
+ interface PartialTextOffsetWithIsFound {
69
69
text : string ;
70
70
offset ?: number ;
71
71
isFound ?: boolean ;
72
72
}
73
73
74
74
interface TestSplit {
75
75
text : string ;
76
- expectedWords : PartialTextOffsetWithValid [ ] ;
76
+ expectedWords : PartialTextOffsetWithIsFound [ ] ;
77
77
}
78
78
79
- function tov ( p : PartialTextOffsetWithValid | string , isValid = true ) : PartialTextOffsetWithValid {
79
+ /** to PartialTextOffsetWithIsFound */
80
+ function tov ( p : PartialTextOffsetWithIsFound | string , defaultIsFound = true ) : PartialTextOffsetWithIsFound {
80
81
if ( typeof p === 'string' ) {
81
82
p = { text : p } ;
82
83
}
83
- const { isFound = isValid } = p ;
84
+ const { isFound = defaultIsFound } = p ;
84
85
return { ...p , isFound } ;
85
86
}
86
87
87
- function splitTov ( t : string ) : PartialTextOffsetWithValid [ ] {
88
+ function splitTov ( t : string ) : PartialTextOffsetWithIsFound [ ] {
88
89
if ( ! t ) return [ ] ;
89
90
const parts = t . split ( '|' ) ;
90
91
return parts . map ( ( p ) => tov ( p , has ( { text : p , offset : 0 } ) ) ) ;
@@ -173,11 +174,13 @@ describe('Validate wordSplitter', () => {
173
174
${ 'nstatic' } | ${ 'static' } | ${ 1 }
174
175
${ 'techo' } | ${ 'echo' } | ${ 1 }
175
176
${ `n'cpp` } | ${ 'cpp' } | ${ 1 }
176
- ${ `n'log` } | ${ 'log' } | ${ 4 }
177
+ ${ `n'log` } | ${ 'log' } | ${ 7 }
177
178
${ '64-bit' } | ${ 'bit' } | ${ 1 }
178
179
${ '128-bit' } | ${ 'bit' } | ${ 1 }
179
180
${ '256-sha' } | ${ '256-sha' } | ${ 6 }
180
181
${ `REFACTOR'd` } | ${ 'REFACTOR' } | ${ 2 }
182
+ ${ `dogs'` } | ${ `dogs'` } | ${ 2 }
183
+ ${ `planets’` } | ${ `planets’` } | ${ 2 }
181
184
` ( 'split `$text` in doc' , ( { text, expectedWords, calls } : TestSplit2 ) => {
182
185
const expectedWordSegments = splitTov ( expectedWords ) ;
183
186
const doc = sampleText ( ) ;
@@ -318,6 +321,10 @@ function sampleWordSet() {
318
321
well educated
319
322
words separated by singleQuote
320
323
256-sha
324
+ dogs'
325
+ leashes
326
+ writers
327
+ planets’
321
328
`
322
329
. split ( / \s + / g)
323
330
. map ( ( a ) => a . trim ( ) )
@@ -343,8 +350,11 @@ function sampleText() {
343
350
344
351
256-sha
345
352
346
- 128-bit values
353
+ - The dogs' leashes (multiple dogs).
354
+ - The writers' desks (multiple writers).
355
+ - The planets’ atmospheres (multiple planets).
347
356
357
+ 128-bit values
348
358
349
359
` ;
350
360
}
0 commit comments