1 /*******************************************************
2 * Unit test for the String class
4 * test regular expression operations
5 ******************************************************
14 // TODO: test regex constructors
16 // A simple regular expression
19 // Regular expression matching
21 String s2 = "abd123def";
23 std::cout << "Regular expression matching.\n";
24 assert((s1 == nr) == false);
25 assert((s2 == nr) == true);
27 assert((s1 != nr) == true);
28 assert((s2 != nr) == false);
30 // Select a substring with a regex
35 std::cout << "The matching part of \"" << s2 << "\" is \"" << match << "\"\n";
36 assert(match == "123");
38 // Test a regex with an error
40 bool exception_caught = false;
44 regex wrong_nr("[0-9+");
45 std::cout << "No regex error detected.\n";
47 catch (RegexException rexc)
49 std::cout << "Regex exception: " << rexc.what() << "\n";
50 exception_caught = true;
53 assert(exception_caught);