@@ -248,4 +248,272 @@ final class StringMatchingTests: XCTestCase {
248248 // Then we should get nil because there isn't an index before `startIndex`
249249 XCTAssertNil ( result)
250250 }
251+
252+ func testMatchBuiltinCCAtEnd( ) {
253+ // Given
254+ let sut = " "
255+
256+ // When
257+ let next = sut. matchBuiltinCC (
258+ . any,
259+ at: sut. endIndex,
260+ limitedBy: sut. endIndex,
261+ isInverted: false ,
262+ isStrictASCII: false ,
263+ isScalarSemantics: true
264+ )
265+
266+ // Then
267+ XCTAssertNil ( next)
268+ }
269+ }
270+
271+ // MARK: matchScalar tests
272+ extension StringMatchingTests {
273+ func testMatchScalar( ) {
274+ // Given
275+ let sut = " bar "
276+
277+ // When
278+ let next = sut. matchScalar (
279+ " b " ,
280+ at: sut. startIndex,
281+ limitedBy: sut. endIndex,
282+ boundaryCheck: false ,
283+ isCaseInsensitive: false
284+ )
285+
286+ // Then
287+ XCTAssertEqual ( next, sut. index ( after: sut. startIndex) )
288+ }
289+
290+ func testMatchScalarNoMatch( ) {
291+ // Given
292+ let sut = " bar "
293+
294+ // When
295+ let next = sut. matchScalar (
296+ " a " ,
297+ at: sut. startIndex,
298+ limitedBy: sut. endIndex,
299+ boundaryCheck: false ,
300+ isCaseInsensitive: false
301+ )
302+
303+ // Then
304+ XCTAssertNil ( next)
305+ }
306+
307+ func testMatchScalarCaseInsensitive( ) {
308+ // Given
309+ let sut = " BAR "
310+
311+ // When
312+ let next = sut. matchScalar (
313+ " b " ,
314+ at: sut. startIndex,
315+ limitedBy: sut. endIndex,
316+ boundaryCheck: false ,
317+ isCaseInsensitive: true
318+ )
319+
320+ // Then
321+ XCTAssertEqual ( next, sut. index ( after: sut. startIndex) )
322+ }
323+
324+ func testMatchScalarCaseInsensitiveNoMatch( ) {
325+ // Given
326+ let sut = " BAR "
327+
328+ // When
329+ let next = sut. matchScalar (
330+ " a " ,
331+ at: sut. startIndex,
332+ limitedBy: sut. endIndex,
333+ boundaryCheck: false ,
334+ isCaseInsensitive: true
335+ )
336+
337+ // Then
338+ XCTAssertNil ( next)
339+ }
340+
341+ func testMatchScalarAtEnd( ) {
342+ // Given
343+ let sut = " "
344+
345+ // When
346+ let next = sut. matchScalar (
347+ " a " ,
348+ at: sut. endIndex,
349+ limitedBy: sut. endIndex,
350+ boundaryCheck: false ,
351+ isCaseInsensitive: false
352+ )
353+
354+ // Then
355+ XCTAssertNil ( next)
356+ }
357+
358+ func testMatchScalarBoundaryCheck( ) {
359+ // Given
360+ // \u{62}\u{300}\u{316}\u{65}\u{73}\u{74}
361+ let sut = " b̖̀est "
362+
363+ // When
364+ let next = sut. matchScalar (
365+ " \u{300} " ,
366+ at: sut. unicodeScalars. index ( after: sut. unicodeScalars. startIndex) ,
367+ limitedBy: sut. endIndex,
368+ boundaryCheck: true ,
369+ isCaseInsensitive: false
370+ )
371+
372+ // Then
373+ XCTAssertNil ( next)
374+ }
375+
376+ func testMatchScalarNoBoundaryCheck( ) {
377+ // Given
378+ // \u{62}\u{300}\u{316}\u{65}\u{73}\u{74}
379+ let sut = " b̖̀est "
380+ let atPos = sut. unicodeScalars. index ( after: sut. unicodeScalars. startIndex)
381+
382+ // When
383+ let next = sut. matchScalar (
384+ " \u{300} " ,
385+ at: atPos,
386+ limitedBy: sut. endIndex,
387+ boundaryCheck: false ,
388+ isCaseInsensitive: false
389+ )
390+
391+ // Then
392+ XCTAssertEqual ( next, sut. unicodeScalars. index ( after: atPos) )
393+ }
394+ }
395+
396+ // MARK: reverseMatchScalar tests
397+ extension StringMatchingTests {
398+ func testReverseMatchScalar( ) {
399+ // Given
400+ let sut = " bar "
401+
402+ // When
403+ let previous = sut. reverseMatchScalar (
404+ " a " ,
405+ at: sut. index ( after: sut. startIndex) ,
406+ limitedBy: sut. startIndex,
407+ boundaryCheck: false ,
408+ isCaseInsensitive: false
409+ )
410+
411+ // Then
412+ XCTAssertEqual ( previous, sut. startIndex)
413+ }
414+
415+ func testReverseMatchScalarNoMatch( ) {
416+ // Given
417+ let sut = " bar "
418+
419+ // When
420+ let previous = sut. reverseMatchScalar (
421+ " b " ,
422+ at: sut. index ( after: sut. startIndex) ,
423+ limitedBy: sut. startIndex,
424+ boundaryCheck: false ,
425+ isCaseInsensitive: false
426+ )
427+
428+ // Then
429+ XCTAssertNil ( previous)
430+ }
431+
432+ func testReverseMatchScalarCaseInsensitive( ) {
433+ // Given
434+ let sut = " BAR "
435+
436+ // When
437+ let previous = sut. reverseMatchScalar (
438+ " a " ,
439+ at: sut. index ( after: sut. startIndex) ,
440+ limitedBy: sut. startIndex,
441+ boundaryCheck: false ,
442+ isCaseInsensitive: true
443+ )
444+
445+ // Then
446+ XCTAssertEqual ( previous, sut. startIndex)
447+ }
448+
449+ func testReverseMatchScalarCaseInsensitiveNoMatch( ) {
450+ // Given
451+ let sut = " BAR "
452+
453+ // When
454+ let previous = sut. reverseMatchScalar (
455+ " b " ,
456+ at: sut. index ( after: sut. startIndex) ,
457+ limitedBy: sut. startIndex,
458+ boundaryCheck: false ,
459+ isCaseInsensitive: true
460+ )
461+
462+ // Then
463+ XCTAssertNil ( previous)
464+ }
465+
466+ func testReverseMatchScalarAtStart( ) {
467+ // Given
468+ let sut = " a "
469+
470+ // When
471+ let previous = sut. reverseMatchScalar (
472+ " a " ,
473+ at: sut. startIndex,
474+ limitedBy: sut. startIndex,
475+ boundaryCheck: false ,
476+ isCaseInsensitive: false
477+ )
478+
479+ // Then
480+ XCTAssertNil ( previous)
481+ }
482+
483+ func testReverseMatchScalarBoundaryCheck( ) {
484+ // Given
485+ // \u{61}\u{62}\u{300}\u{316}\u{63}\u{64}
486+ let sut = " ab̖̀cd "
487+
488+ // When
489+ let previous = sut. reverseMatchScalar (
490+ " \u{316} " ,
491+ at: sut. unicodeScalars. index ( sut. unicodeScalars. startIndex, offsetBy: 3 ) ,
492+ limitedBy: sut. startIndex,
493+ boundaryCheck: true ,
494+ isCaseInsensitive: false
495+ )
496+
497+ // Then
498+ XCTAssertNil ( previous)
499+ }
500+
501+ func testReverseMatchScalarNoBoundaryCheck( ) {
502+ // Given
503+ // \u{61}\u{62}\u{300}\u{316}\u{63}\u{64}
504+ let sut = " ab̖̀cd "
505+ let atPos = sut. unicodeScalars. index ( sut. unicodeScalars. startIndex, offsetBy: 3 )
506+
507+ // When
508+ let previous = sut. reverseMatchScalar (
509+ " \u{316} " ,
510+ at: atPos,
511+ limitedBy: sut. startIndex,
512+ boundaryCheck: false ,
513+ isCaseInsensitive: false
514+ )
515+
516+ // Then
517+ XCTAssertEqual ( previous, sut. unicodeScalars. index ( before: atPos) )
518+ }
251519}
0 commit comments