Added tests for substring and regular expression functions.
[libacl.git] / test / string_substring.cpp
1 /*******************************************************
2  *  Unit test for the String class
3  *
4  * test substring operations
5  ******************************************************
6  *
7  */
8
9 #include "String.h"
10 #include <assert.h>
11
12 int main()
13 {
14    // Default contructor: empty string
15    String s0;
16
17    // Select a substring
18    String s1 = "abcdefghijkl";
19    String s2 = s1(3,5);         // s2 = "defgh"
20
21    std::cout << "The substring (3,5) of " << s1 << " is " << s2 << "\n";
22    assert(s2 == "defgh");
23
24    String s3 = "abcdefghijkl";
25    String s4 = "12345678";
26
27    std::cout << "Replace substring (3,5) of " << s3 << " with " << s4 << " : ";
28    s3(3,5) = s4;           // s3 = "abc12345678ijkl"
29    std::cout << s3 << "\n";
30    assert(s3 == "abc12345678ijkl");
31
32    String s5 = "abcdefghijkl";
33    String s6 = "12345678";
34
35    std::cout << "Insert \"" << s6 << "\" into \"" << s5 << "\" : ";
36    s5(3, 0) = s6;
37    std::cout << s5 << "\n";
38    assert(s5 == "abc12345678defghijkl");
39
40    std::cout << "Remove part of \"" << s5 << "\" : ";
41    s5(11,5) = "";
42    std::cout << s5 << "\n";
43    assert(s5 == "abc12345678ijkl");
44
45    return 0;
46 }
47