@@ -579,48 +579,59 @@ struct test_27_data {
579
579
580
580
TEST_CASE (" [String] Begins with" ) {
581
581
test_27_data tc[] = {
582
+ // Test cases for true:
582
583
{ " res://foobar" , " res://" , true },
584
+ { " abc" , " abc" , true },
585
+ { " abc" , " " , true },
586
+ { " " , " " , true },
587
+ // Test cases for false:
583
588
{ " res" , " res://" , false },
584
- { " abc" , " abc" , true }
589
+ { " abcdef" , " foo" , false },
590
+ { " abc" , " ax" , false },
591
+ { " " , " abc" , false }
585
592
};
586
593
size_t count = sizeof (tc) / sizeof (tc[0 ]);
587
594
bool state = true ;
588
- for (size_t i = 0 ; state && i < count; ++i) {
595
+ for (size_t i = 0 ; i < count; ++i) {
589
596
String s = tc[i].data ;
590
597
state = s.begins_with (tc[i].part ) == tc[i].expected ;
591
- if (state) {
592
- String sb = tc[i].part ;
593
- state = s.begins_with (sb) == tc[i].expected ;
594
- }
595
- CHECK (state);
596
- if (!state) {
597
- break ;
598
- }
599
- };
600
- CHECK (state);
598
+ CHECK_MESSAGE (state, " first check failed at: " , i);
599
+
600
+ String sb = tc[i].part ;
601
+ state = s.begins_with (sb) == tc[i].expected ;
602
+ CHECK_MESSAGE (state, " second check failed at: " , i);
603
+ }
604
+
605
+ // Test "const char *" version also with nullptr.
606
+ String s (" foo" );
607
+ state = s.begins_with (nullptr ) == false ;
608
+ CHECK_MESSAGE (state, " nullptr check failed" );
609
+
610
+ String empty (" " );
611
+ state = empty.begins_with (nullptr ) == false ;
612
+ CHECK_MESSAGE (state, " nullptr check with empty string failed" );
601
613
}
602
614
603
615
TEST_CASE (" [String] Ends with" ) {
604
616
test_27_data tc[] = {
617
+ // test cases for true:
605
618
{ " res://foobar" , " foobar" , true },
619
+ { " abc" , " abc" , true },
620
+ { " abc" , " " , true },
621
+ { " " , " " , true },
622
+ // test cases for false:
606
623
{ " res" , " res://" , false },
607
- { " abc" , " abc" , true }
624
+ { " " , " abc" , false },
625
+ { " abcdef" , " foo" , false },
626
+ { " abc" , " xc" , false }
608
627
};
609
628
size_t count = sizeof (tc) / sizeof (tc[0 ]);
610
- bool state = true ;
611
- for (size_t i = 0 ; state && i < count; ++i) {
629
+ for (size_t i = 0 ; i < count; ++i) {
612
630
String s = tc[i].data ;
613
- state = s.ends_with (tc[i].part ) == tc[i].expected ;
614
- if (state) {
615
- String sb = tc[i].part ;
616
- state = s.ends_with (sb) == tc[i].expected ;
617
- }
618
- CHECK (state);
619
- if (!state) {
620
- break ;
621
- }
622
- };
623
- CHECK (state);
631
+ String sb = tc[i].part ;
632
+ bool state = s.ends_with (sb) == tc[i].expected ;
633
+ CHECK_MESSAGE (state, " check failed at: " , i);
634
+ }
624
635
}
625
636
626
637
TEST_CASE (" [String] format" ) {
0 commit comments