9999end
100100
101101@testset " issue #7248" begin
102- @test_throws BoundsError length (" hello" , 1 , - 1 ) == 0
103- @test prevind (" hello" , 0 , 1 ) == - 1
104- @test_throws BoundsError length (" hellø" , 1 , - 1 ) == 0
105- @test prevind (" hellø" , 0 , 1 ) == - 1
106- @test_throws BoundsError length (" hello" , 1 , 10 ) == 10
102+ @test_throws BoundsError length (" hello" , 1 , - 1 )
103+ @test_throws BoundsError prevind (" hello" , 0 , 1 )
104+ @test_throws BoundsError length (" hellø" , 1 , - 1 )
105+ @test_throws BoundsError prevind (" hellø" , 0 , 1 )
106+ @test_throws BoundsError length (" hello" , 1 , 10 )
107107 @test nextind (" hello" , 0 , 10 ) == 10
108108 @test_throws BoundsError length (" hellø" , 1 , 10 ) == 9
109109 @test nextind (" hellø" , 0 , 10 ) == 11
512512 SubString (" 123∀α>β:α+1>β123" , 4 , 18 ),
513513 SubString (s " 123∀α>β:α+1>β123" , 4 , 18 )]
514514 for s in strs
515- @test thisind (s, - 2 ) == - 2
515+ @test_throws BoundsError thisind (s, - 2 )
516+ @test_throws BoundsError thisind (s, - 1 )
516517 @test thisind (s, 0 ) == 0
517518 @test thisind (s, 1 ) == 1
518519 @test thisind (s, 2 ) == 1
@@ -523,86 +524,97 @@ end
523524 @test thisind (s, 15 ) == 15
524525 @test thisind (s, 16 ) == 15
525526 @test thisind (s, 17 ) == 17
526- @test thisind (s, 30 ) == 30
527+ @test_throws BoundsError thisind (s, 18 )
528+ @test_throws BoundsError thisind (s, 19 )
527529 end
528530 end
529531
530532 let strs = Any[" " , s "" , SubString (" 123" , 2 , 1 ), SubString (s " 123" , 2 , 1 )]
531- for s in strs, i in - 2 : 2
532- @test thisind (s, i) == i
533+ for s in strs
534+ @test_throws BoundsError thisind (s, - 1 )
535+ @test thisind (s, 0 ) == 0
536+ @test thisind (s, 1 ) == 1
537+ @test_throws BoundsError thisind (s, 2 )
533538 end
534539 end
535540end
536541
537542@testset " prevind and nextind" begin
538- let strs = Any[" ∀α>β:α+1>β" , GenericString (" ∀α>β:α+1>β" )]
539- for i in 1 : 2
540- @test prevind (strs[i], 1 ) == 0
541- @test prevind (strs[i], 1 , 1 ) == 0
542- @test prevind (strs[i], 2 ) == 1
543- @test prevind (strs[i], 2 , 1 ) == 1
544- @test prevind (strs[i], 4 ) == 1
545- @test prevind (strs[i], 4 , 1 ) == 1
546- @test prevind (strs[i], 5 ) == 4
547- @test prevind (strs[i], 5 , 1 ) == 4
548- @test prevind (strs[i], 5 , 2 ) == 1
549- @test prevind (strs[i], 5 , 3 ) == 0
550- @test prevind (strs[i], 15 ) == 14
551- @test prevind (strs[i], 15 , 1 ) == 14
552- @test prevind (strs[i], 15 , 2 ) == 13
553- @test prevind (strs[i], 15 , 3 ) == 12
554- @test prevind (strs[i], 15 , 4 ) == 10
555- @test prevind (strs[i], 15 , 10 ) == 0
556- @test prevind (strs[i], 15 , 9 ) == 1
557- @test prevind (strs[i], 16 ) == 15
558- @test prevind (strs[i], 16 , 1 ) == 15
559- @test prevind (strs[i], 16 , 2 ) == 14
560- @test prevind (strs[i], 20 ) == 19
561- @test prevind (strs[i], 20 , 1 ) == 19
562- @test prevind (strs[i], 20 , 10 ) == 7
563- @test prevind (strs[i], 20 , 0 ) == 20
564-
565- @test nextind (strs[i], - 1 ) == 0
566- @test nextind (strs[i], - 1 , 1 ) == 0
567- @test nextind (strs[i], - 1 , 2 ) == 1
568- @test nextind (strs[i], - 1 , 3 ) == 4
569- @test nextind (strs[i], 0 , 2 ) == 4
570- @test nextind (strs[i], 0 , 20 ) == 26
571- @test nextind (strs[i], 0 , 10 ) == 15
572- @test nextind (strs[i], 1 ) == 4
573- @test nextind (strs[i], 1 , 1 ) == 4
574- @test nextind (strs[i], 1 , 2 ) == 6
575- @test nextind (strs[i], 1 , 9 ) == 15
576- @test nextind (strs[i], 1 , 10 ) == 17
577- @test nextind (strs[i], 2 ) == 4
578- @test nextind (strs[i], 2 , 1 ) == 4
579- @test nextind (strs[i], 3 ) == 4
580- @test nextind (strs[i], 3 , 1 ) == 4
581- @test nextind (strs[i], 4 ) == 6
582- @test nextind (strs[i], 4 , 1 ) == 6
583- @test nextind (strs[i], 14 ) == 15
584- @test nextind (strs[i], 14 , 1 ) == 15
585- @test nextind (strs[i], 15 ) == 17
586- @test nextind (strs[i], 15 , 1 ) == 17
587- @test nextind (strs[i], 20 ) == 21
588- @test nextind (strs[i], 20 , 1 ) == 21
589- @test nextind (strs[i], 20 , 0 ) == 20
590-
591- for x in - 10 : 20
592- n = p = x
593- for j in 1 : 40
594- p = prevind (strs[i], p)
595- @test prevind (strs[i], x, j) == p
596- n = nextind (strs[i], n)
597- @test nextind (strs[i], x, j) == n
543+ for s in Any[" ∀α>β:α+1>β" , GenericString (" ∀α>β:α+1>β" )]
544+ @test_throws BoundsError prevind (s, 0 )
545+ @test_throws BoundsError prevind (s, 0 , 0 )
546+ @test_throws BoundsError prevind (s, 0 , 1 )
547+ @test prevind (s, 1 ) == 0
548+ @test prevind (s, 1 , 1 ) == 0
549+ @test prevind (s, 1 , 0 ) == 1
550+ @test prevind (s, 2 ) == 1
551+ @test prevind (s, 2 , 1 ) == 1
552+ @test prevind (s, 4 ) == 1
553+ @test prevind (s, 4 , 1 ) == 1
554+ @test prevind (s, 5 ) == 4
555+ @test prevind (s, 5 , 1 ) == 4
556+ @test prevind (s, 5 , 2 ) == 1
557+ @test prevind (s, 5 , 3 ) == 0
558+ @test prevind (s, 15 ) == 14
559+ @test prevind (s, 15 , 1 ) == 14
560+ @test prevind (s, 15 , 2 ) == 13
561+ @test prevind (s, 15 , 3 ) == 12
562+ @test prevind (s, 15 , 4 ) == 10
563+ @test prevind (s, 15 , 10 ) == 0
564+ @test prevind (s, 15 , 9 ) == 1
565+ @test prevind (s, 16 ) == 15
566+ @test prevind (s, 16 , 1 ) == 15
567+ @test prevind (s, 16 , 2 ) == 14
568+ @test prevind (s, 17 ) == 15
569+ @test prevind (s, 17 , 1 ) == 15
570+ @test prevind (s, 17 , 2 ) == 14
571+ @test_throws BoundsError prevind (s, 18 )
572+ @test_throws BoundsError prevind (s, 18 , 0 )
573+ @test_throws BoundsError prevind (s, 18 , 1 )
574+
575+ @test_throws BoundsError nextind (s, - 1 )
576+ @test_throws BoundsError nextind (s, - 1 , 0 )
577+ @test_throws BoundsError nextind (s, - 1 , 1 )
578+ @test nextind (s, 0 , 2 ) == 4
579+ @test nextind (s, 0 , 20 ) == 26
580+ @test nextind (s, 0 , 10 ) == 15
581+ @test nextind (s, 1 ) == 4
582+ @test nextind (s, 1 , 1 ) == 4
583+ @test nextind (s, 1 , 2 ) == 6
584+ @test nextind (s, 1 , 9 ) == 15
585+ @test nextind (s, 1 , 10 ) == 17
586+ @test nextind (s, 2 ) == 4
587+ @test nextind (s, 2 , 1 ) == 4
588+ @test nextind (s, 3 ) == 4
589+ @test nextind (s, 3 , 1 ) == 4
590+ @test nextind (s, 4 ) == 6
591+ @test nextind (s, 4 , 1 ) == 6
592+ @test nextind (s, 14 ) == 15
593+ @test nextind (s, 14 , 1 ) == 15
594+ @test nextind (s, 15 ) == 17
595+ @test nextind (s, 15 , 1 ) == 17
596+ @test nextind (s, 15 , 2 ) == 18
597+ @test nextind (s, 16 ) == 17
598+ @test nextind (s, 16 , 1 ) == 17
599+ @test nextind (s, 16 , 2 ) == 18
600+ @test nextind (s, 16 , 3 ) == 19
601+ @test_throws BoundsError nextind (s, 17 )
602+ @test_throws BoundsError nextind (s, 17 , 0 )
603+ @test_throws BoundsError nextind (s, 17 , 1 )
604+
605+ for x in 0 : ncodeunits (s)+ 1
606+ n = p = x
607+ for j in 1 : 40
608+ if 1 ≤ p
609+ p = prevind (s, p)
610+ @test prevind (s, x, j) == p
611+ end
612+ if n ≤ ncodeunits (s)
613+ n = nextind (s, n)
614+ @test nextind (s, x, j) == n
598615 end
599616 end
600617 end
601- @test prevind (strs[1 ], - 1 ) == - 2
602- @test prevind (strs[1 ], - 1 , 1 ) == - 2
603-
604- @test prevind (strs[2 ], - 1 ) == - 2
605- @test prevind (strs[2 ], - 1 , 1 ) == - 2
606618 end
607619end
608620
0 commit comments