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
72 cout << d[1] << d[0] << endl;
74 cout << d.substr(1) << endl; // default argument
75 cout << d.substr(1, 1) << endl; // maximum length
76 cout << d.substr(1, 2) << endl; // length larger than max
77 cout << d.substr(2) << endl; // maximum pos
80 void test_trivdocstring()
82 docstring const input[] = {
86 from_ascii("max"), // max. string with sso on 64 bit
87 from_ascii("something which does not fit into sso")
89 size_t const n = sizeof(input) / sizeof(input[0]);
90 for (size_t i = 0; i < n; ++i) {
91 // construction from std::string
92 trivdocstring const a(input[i]);
93 // construction from trivstring
94 trivdocstring const b(a);
95 // assignment from trivstring
96 trivdocstring const c = a;
97 // assignment from std::string
98 trivdocstring d = input[i];
99 // assignment from trivstring
100 docstring const e = a;
101 // assignment from trivstring via C string
102 docstring const f = a.c_str();
106 cout << "not empty ";
107 cout << a.length() << endl;
108 cout << to_ascii(a) << endl;
109 cout << to_ascii(b) << endl;
110 cout << to_ascii(c) << endl;
111 cout << to_ascii(d) << endl;
112 cout << to_ascii(e) << endl;
113 cout << to_ascii(f) << endl;
115 trivdocstring g(from_ascii("swap"));
116 cout << to_ascii(g) << endl;
118 cout << to_ascii(d) << endl;
119 cout << to_ascii(g) << endl;
122 trivdocstring const a;
123 trivdocstring const b(from_ascii("a"));
124 trivdocstring const c(from_ascii("b"));
125 trivdocstring const d(from_ascii("42"));
126 cout << (a == a) << ' ' << (a < a) << endl; // equal strings
127 cout << (a == b) << ' ' << (a < b) << endl; // different strings, same length
128 cout << (b == a) << ' ' << (b < a) << endl; // different strings, same length
129 cout << (a == c) << ' ' << (a < c) << endl; // different strings, different length
130 cout << (c == a) << ' ' << (c < a) << endl; // different strings, different length
131 // per character initialization works also if char_type != wchar
132 char_type const e[1] = {'\0'};
133 char_type const f[2] = {'b', '\0'};
134 char_type const g[3] = {'4', '2', '\0'};
135 cout << (a == e) << ' ' << (e == a) << endl; // empty strings
136 cout << (c == a) << ' ' << (a == c) << endl; // equal strings
137 cout << (a == f) << ' ' << (f == a) << endl; // different strings, same length
138 cout << (a == g) << ' ' << (g == a) << endl; // different strings, different length
140 cout << static_cast<char>(d[1]) << static_cast<char>(d[0]) << endl;
142 cout << to_ascii(d.substr(1)) << endl; // default argument
143 cout << to_ascii(d.substr(1, 1)) << endl; // maximum length
144 cout << to_ascii(d.substr(1, 2)) << endl; // length larger than max
145 cout << to_ascii(d.substr(2)) << endl; // maximum pos
151 test_trivdocstring();