static int run_test (int /*unused*/, char* /*unused*/ []) { test_simple_throw (); // constructors test_size_ctor (); test_npos_ctor (); test_max_size_ctor1 (); test_max_size_ctor2 (); test_len_ctor (); // member functions test_resize (); test_reserve (); test_at (); test_append (); test_assign (); test_insert1 (); test_insert2 (); test_erase (); test_replace1 (); test_replace2 (); test_replace3 (); test_copy (); test_substr (); return 0; }
int test_main( int , char* [] ) { const char **p = &test_strings[0]; while ( *p != NULL ) { interop ( *p, *p ); test_substr ( *p ); test_remove ( *p ); null_tests ( *p ); p++; } return 0; }
void test_substr_all(void) { size_t errcount = 0; exscape::string str = "ABCDEF"; std::cout << "Positive start tests:\n"; errcount += test_substr(str, 0, 6, "ABCDEF"); errcount += test_substr(str, 1, 5, "BCDEF"); errcount += test_substr(str, 0, 3, "ABC"); errcount += test_substr(str, 4, 2, "EF"); errcount += test_substr(str, 5, 1, "F"); errcount += test_substr(str, 3, 2, "DE"); errcount += test_substr("Hello, world!", 1, 4, "ello"); errcount += test_substr("1 2 3, anyone there?", 2, 1, "2"); if (errcount == 0) std::cout << "All OK\n"; std::cout << "\n"; std::cout << "Negative start tests:\n"; errcount += test_substr(str, -3, 1, "D"); errcount += test_substr(str, -4, 3, "CDE"); errcount += test_substr(str, -4, 1, "C"); errcount += test_substr(str, -5, 1, "B"); errcount += test_substr(str, -6, 6, "ABCDEF"); errcount += test_substr("Testing, testing", -7, 4, "test"); if (errcount == 0) std::cout << "All OK\n"; std::cout << "\n"; std::cout << "Zero length tests:\n"; errcount += test_substr(str, 0, 0, "ABCDEF"); errcount += test_substr(str, 1, 0, "BCDEF"); errcount += test_substr(str, 4, 0, "EF"); errcount += test_substr(str, 5, 0, "F"); errcount += test_substr("", 0, 0, ""); if (errcount == 0) std::cout << "All OK\n"; std::cout << "\n"; std::cout << "Zero length AND negative start tests:\n"; errcount += test_substr(str, -1, 0, "F"); errcount += test_substr(str, -4, 0, "CDEF"); errcount += test_substr(str, -2, 0, "EF"); if (errcount == 0) std::cout << "All OK\n"; std::cout << "\n"; std::cout << "Negative length (and also start) tests:\n"; errcount += test_substr(str, 0, -1, "ABCDE"); errcount += test_substr(str, 0, -3, "ABC"); errcount += test_substr(str, 0, -4, "AB"); errcount += test_substr(str, 2, -1, "CDE"); errcount += test_substr(str, -3, -1, "DE"); errcount += test_substr(str, 4, -1, "E"); errcount += test_substr(str, 0, -6, ""); if (errcount == 0) std::cout << "All OK\n"; /* std::cout << "\n"; std::cout << "The following should fail:\n"; test_substr(str, 6, 2, "(null)"); test_substr(str, 1, 10, "(null)"); test_substr(str, -10, 0, "(null)"); test_substr(str, -10, 12, "(null)"); test_substr(str, -7, 3, "(null)"); test_substr(str, 0, -7, "(null)"); test_substr(str, -3, -4, "(null)"); test_substr(str, 4, -4, "(null)"); // this would return "" in PHP, but screw that. */ std::cout << "Done testing substr(), " << errcount << " errors" << std::endl; }