Updated the README
[libs.git] / test / String.tst
blob4bc4de90aece20ece282a167ea546e9c90c67041
1 @.Header:
2 #include <Sylph/Core/String.h>
4 // for strcmp
5 #include <cstring>
7 using namespace Sylph;
8 @.End
10 @.SetUp:
11 @.End
13 @.TearDown:
14 @.End
16 @testFromAscii:
17         String s = "foobar";
18         Array<uchar> a = s.utf16();
19         CPPUNIT_ASSERT(a[0] == 'f');
20         CPPUNIT_ASSERT(a[1] == 'o');
21         CPPUNIT_ASSERT(a[2] == 'o');
22         CPPUNIT_ASSERT(a[3] == 'b');
23         CPPUNIT_ASSERT(a[4] == 'a');
24         CPPUNIT_ASSERT(a[5] == 'r');
25 @.End
27 @testFromUtf8:
28         String s = "éèçàŒù£";
29         Array<uchar> a = s.utf16();
30         CPPUNIT_ASSERT(a[0] == 0x00E9);
31         CPPUNIT_ASSERT(a[1] == 0x00E8);
32         CPPUNIT_ASSERT(a[2] == 0x00E7);
33         CPPUNIT_ASSERT(a[3] == 0x00E0);
34         CPPUNIT_ASSERT(a[4] == 0x008C);
35         CPPUNIT_ASSERT(a[5] == 0x00F9);
36         CPPUNIT_ASSERT(a[6] == 0x00A3);
37         CPPUNIT_ASSERT(a[7] == 0xF8FF);
38 @.End
40 @testRealEquality:
41         String s = "foobar";
42         String t = "foobar";
43         String u = "barfoo";
44         CPPUNIT_ASSERT(s == t);
45         CPPUNIT_ASSERT(t == s);
46         CPPUNIT_ASSERT(s != u);
47         CPPUNIT_ASSERT(u != s);
48         CPPUNIT_ASSERT(t != u);
49         CPPUNIT_ASSERT(u != t);
50 @.End
52 @testUnicodeRealEquality:
53         String s = "éèçàŒù£";
54         String t = "éèçàŒù£";
55         String u = "Œù£éèçà";
56         CPPUNIT_ASSERT(s == t);
57         CPPUNIT_ASSERT(t == s);
58         CPPUNIT_ASSERT(s != u);
59         CPPUNIT_ASSERT(u != s);
60         CPPUNIT_ASSERT(t != u);
61         CPPUNIT_ASSERT(u != t);
62 @.End
64 @testCopyEquality:
65         String s = "foobar";
66         String t = s.copy();
67         CPPUNIT_ASSERT(s == t);
68         CPPUNIT_ASSERT(t == s);
69 @.End
71 @testUnicodeCopyEquality:
72         String s = "éèçàŒù£";
73         String t = s.copy();
74         CPPUNIT_ASSERT(s == t);
75         CPPUNIT_ASSERT(t == s);
76 @.End
78 @testRefcountEquality:
79         String s = "foobar";
80         String t = s;
81         CPPUNIT_ASSERT(s == t);
82         CPPUNIT_ASSERT(t == s);
83 @.End
85 @testSelfEquality:
86         String s = "foobar";
87         CPPUNIT_ASSERT(s == s);
88 @.End
90 @testUnicodeSelfEquality:
91         String s = "éèçàŒù£";
92         CPPUNIT_ASSERT(s == s);
93 @.End
95 @testBoolConstructor:
96         String s = true;
97         CPPUNIT_ASSERT(s == "true");
98         String t = false;
99         CPPUNIT_ASSERT(t == "false");
100 @.End
102 @testIntConstructor:
103         String s = 12345678;
104         CPPUNIT_ASSERT(s == "12345678");
105         String t = 12345678901234LL;
106         CPPUNIT_ASSERT(t == "12345678901234");
107 @.End
109 @testFloatConstructor:
110         String s = 3.14f;
111         CPPUNIT_ASSERT(s == "3.14");
112         String t = 3.14;
113         CPPUNIT_ASSERT(t == "3.14");
114 @.End
116 @testLength:
117         String s = "foobar";
118         CPPUNIT_ASSERT(s.length() == 6);
119         String t = "éèçàŒù£";
120         CPPUNIT_ASSERT(t.length() == 8);
121 @.End
123 @testCharAt:
124         String s = "foobar";
125         CPPUNIT_ASSERT(s.at(0) == 'f');
126         CPPUNIT_ASSERT(s.at(1) == 'o');
127         CPPUNIT_ASSERT(s.at(2) == 'o');
128         CPPUNIT_ASSERT(s.at(3) == 'b');
129         CPPUNIT_ASSERT(s.at(4) == 'a');
130         CPPUNIT_ASSERT(s.at(5) == 'r');
131 @.End
133 @testUnicodeCharAt:
134         String s = "éèçàŒù£";
135         CPPUNIT_ASSERT(s.at(0) == 0x00E9);
136         CPPUNIT_ASSERT(s.at(1) == 0x00E8);
137         CPPUNIT_ASSERT(s.at(2) == 0x00E7);
138         CPPUNIT_ASSERT(s.at(3) == 0x00E0);
139         CPPUNIT_ASSERT(s.at(4) == 0x008C);
140         CPPUNIT_ASSERT(s.at(5) == 0x00F9);
141         CPPUNIT_ASSERT(s.at(6) == 0x00A3);
142         CPPUNIT_ASSERT(s.at(7) == 0xF8FF);
143 @.End
145 @testInvalidUnicode:
146         char invalid[] = {};
147         String s = invalid;
148         //2do
149 @.End
151 @testAstralPlaneUnicode:
152         char astral[] = {};
153         String s = astral;
154         //2do
155 @.End
157 @testToAscii:
158         String s = "foobar";
159         const char * c = s.ascii();
160         CPPUNIT_ASSERT(std::strcmp(c,"foobar") == 0);
161         String t = "français";
162         const char * c2 = t.ascii();
163         CPPUNIT_ASSERT(std::strcmp(c,"fran?ais") == 0);
164 @.End
166 @testToUtf8:
167         String s = "foobar";
168         const char * c = s.utf8();
169         CPPUNIT_ASSERT(std::strcmp(c,"foobar") == 0);
170         String t = "français";
171         const char * c2 = t.utf8();
172         CPPUNIT_ASSERT(std::strcmp(c,"français") == 0);
173 @.End
175 @testLowerCase:
176         String s = "foo";
177         CPPUNIT_ASSERT(s.toLowerCase() == "foo");
178         s = "FoO";
179         CPPUNIT_ASSERT(s.toLowerCase() == "foo");
180         s = "FoX";
181         CPPUNIT_ASSERT(!(s.toLowerCase() == "foo"));
182 @.End
184 @testUpperCase:
185         String s = "FOO";
186         CPPUNIT_ASSERT(s.toUpperCase() == "FOO");
187         s = "fOO";
188         CPPUNIT_ASSERT(s.toUpperCase() == "FOO");
189         s = "FoX";
190         CPPUNIT_ASSERT(!(s.toUpperCase() == "foo"));
191 @.End
193 @testEqualsIgnoreCase:
194     String s = "foo";
195     String t = "FOO";
196     CPPUNIT_ASSERT(s.equalsIgnoreCase(s));
197     CPPUNIT_ASSERT(s.equalsIgnoreCase(t));
198     CPPUNIT_ASSERT(t.equalsIgnoreCase(t));
199     CPPUNIT_ASSERT(t.equalsIgnoreCase(s));
200     CPPUNIT_ASSERT(!s.equalsIgnoreCase("Fox"));
201     CPPUNIT_ASSERT(!t.equalsIgnoreCase("Fox"));
202 @.End
204 @testContainment:
205 @.End
207 @testTrim:
208 @.End
210 @testSubstring:
211 @.End
213 @testIndexOf:
214 @.End
216 @testMerge:
217 @.End
219 @testHashUniqueness:
220 @.End
222 @testToBool:
223         String s = "true";
224         CPPUNIT_ASSERT(s.boolValue());
225         s = "TrUe";
226         CPPUNIT_ASSERT(s.boolValue());
227         s = "";
228         CPPUNIT_ASSERT(!s.boolValue());
229         s = "false";
230         CPPUNIT_ASSERT(!s.boolValue());
231         s = "ololol";
232         CPPUNIT_ASSERT(!s.boolValue());
233         s = "ééé";
234         CPPUNIT_ASSERT(!s.boolValue());
235 @.End
237 @testToInt:
238         String a = "123";
239         CPPUNIT_ASSERT(a.intValue() == 123);
240         String b = "-123";
241         CPPUNIT_ASSERT(b.intValue() == -123);
242         String c = " 333 ";
243         CPPUNIT_ASSERT(c.intValue() == 333);
244         String d = "foobar";
245         CPPUNIT_ASSERT(d.intValue() == 0);
246 @.End
248 @testToFloat:
249 @.End
251 @testAppend:
252         String a = "foo";
253         String b = "bar";
254         String c = a + b;
255         a += b;
256         CPPUNIT_ASSERT(a == "foobar");
257         CPPUNIT_ASSERT(c == "foobar");
258 @.End
260 @testMultiply:
261         String s = "-";
262         String t = s * 5;
263         CPPUNIT_ASSERT(t == "-----");
265         String u = "é";
266         String v = u * 5;
267         CPPUNIT_ASSERT(v == "ééééé");
268 @.End
270 @testInvoke:
271 @.End