3 #include "../trivstring.h"
4 #include "../docstring.h"
13 void test_trivstring()
15 string const input[] = {
19 "max sso", // max. string with sso on 64 bit
20 "something which does not fit into sso"
22 size_t const n = sizeof(input) / sizeof(input[0]);
23 for (size_t i = 0; i < n; ++i) {
24 // construction from std::string
25 trivstring const a(input[i]);
26 // construction from trivstring
27 trivstring const b(a);
28 // assignment from trivstring
29 trivstring const c = a;
30 // assignment from std::string
31 trivstring d = input[i];
32 // assignment from trivstring
34 // assignment from trivstring via C string
35 string const f = a.c_str();
40 cout << a.length() << endl;
56 trivstring const b("a");
57 trivstring const c("b");
58 trivstring const d("42");
59 cout << (a == a) << ' ' << (a < a) << endl; // equal strings
60 cout << (a == b) << ' ' << (a < b) << endl; // different strings, same length
61 cout << (b == a) << ' ' << (b < a) << endl; // different strings, same length
62 cout << (a == c) << ' ' << (a < c) << endl; // different strings, different length
63 cout << (c == a) << ' ' << (c < a) << endl; // different strings, different length
66 char const * g = "42";
67 cout << (a == e) << ' ' << (e == a) << endl; // empty strings
68 cout << (c == a) << ' ' << (a == c) << endl; // equal strings
69 cout << (a == f) << ' ' << (f == a) << endl; // different strings, same length
70 cout << (a == g) << ' ' << (g == a) << endl; // different strings, different length
73 void test_trivdocstring()
75 docstring const input[] = {
79 from_ascii("max"), // max. string with sso on 64 bit
80 from_ascii("something which does not fit into sso")
82 size_t const n = sizeof(input) / sizeof(input[0]);
83 for (size_t i = 0; i < n; ++i) {
84 // construction from std::string
85 trivdocstring const a(input[i]);
86 // construction from trivstring
87 trivdocstring const b(a);
88 // assignment from trivstring
89 trivdocstring const c = a;
90 // assignment from std::string
91 trivdocstring d = input[i];
92 // assignment from trivstring
93 docstring const e = a;
94 // assignment from trivstring via C string
95 docstring const f = a.c_str();
100 cout << a.length() << endl;
101 cout << to_ascii(a) << endl;
102 cout << to_ascii(b) << endl;
103 cout << to_ascii(c) << endl;
104 cout << to_ascii(d) << endl;
105 cout << to_ascii(e) << endl;
106 cout << to_ascii(f) << endl;
108 trivdocstring g(from_ascii("swap"));
109 cout << to_ascii(g) << endl;
111 cout << to_ascii(d) << endl;
112 cout << to_ascii(g) << endl;
115 trivdocstring const a;
116 trivdocstring const b(from_ascii("a"));
117 trivdocstring const c(from_ascii("b"));
118 trivdocstring const d(from_ascii("42"));
119 cout << (a == a) << ' ' << (a < a) << endl; // equal strings
120 cout << (a == b) << ' ' << (a < b) << endl; // different strings, same length
121 cout << (b == a) << ' ' << (b < a) << endl; // different strings, same length
122 cout << (a == c) << ' ' << (a < c) << endl; // different strings, different length
123 cout << (c == a) << ' ' << (c < a) << endl; // different strings, different length
124 // per character initialization works also if char_type != wchar
125 char_type const e[1] = {'\0'};
126 char_type const f[2] = {'b', '\0'};
127 char_type const g[3] = {'4', '2', '\0'};
128 cout << (a == e) << ' ' << (e == a) << endl; // empty strings
129 cout << (c == a) << ' ' << (a == c) << endl; // equal strings
130 cout << (a == f) << ' ' << (f == a) << endl; // different strings, same length
131 cout << (a == g) << ' ' << (g == a) << endl; // different strings, different length
137 test_trivdocstring();