69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
@end
@implementation TestsAppDelegate (OFStringTests)
- (void)stringTests
{
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
OFMutableString *s[3];
OFArray *a;
int i;
const of_unichar_t *ua;
const uint16_t *u16a;
EntityHandler *h;
#ifdef OF_HAVE_BLOCKS
__block BOOL ok;
|
>
|
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
@end
@implementation TestsAppDelegate (OFStringTests)
- (void)stringTests
{
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
OFMutableString *s[3];
OFString *is;
OFArray *a;
int i;
const of_unichar_t *ua;
const uint16_t *u16a;
EntityHandler *h;
#ifdef OF_HAVE_BLOCKS
__block BOOL ok;
|
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
TEST(@"+[stringWithUTF8String:length:]",
(s[0] = [OFMutableString stringWithUTF8String: "\xEF\xBB\xBF"
"foobar"
length: 6]) &&
[s[0] isEqual: @"foo"])
TEST(@"+[stringWithUnicodeString:]",
(s[1] = [OFString stringWithUnicodeString: ucstr]) &&
[s[1] isEqual: @"fööbär🀺"] &&
(s[1] = [OFString stringWithUnicodeString: sucstr]) &&
[s[1] isEqual: @"fööbär🀺"])
TEST(@"+[stringWithUTF16String:]",
(s[1] = [OFString stringWithUTF16String: utf16str]) &&
[s[1] isEqual: @"fööbär🀺"] &&
(s[1] = [OFString stringWithUTF16String: sutf16str]) &&
[s[1] isEqual: @"fööbär🀺"])
TEST(@"+[stringWithContentsOfFile:encoding]", (s[1] = [OFString
stringWithContentsOfFile: @"testfile.txt"
encoding: OF_STRING_ENCODING_ISO_8859_1]) &&
[s[1] isEqual: @"testäöü"])
TEST(@"+[stringWithContentsOfURL:encoding]", (s[1] = [OFString
stringWithContentsOfURL: [OFURL URLWithString:
@"file://testfile.txt"]
encoding: OF_STRING_ENCODING_ISO_8859_1]) &&
[s[1] isEqual: @"testäöü"])
TEST(@"-[appendUTFString:withLength:]",
R([s[0] appendUTF8String: "foo\xEF\xBB\xBF" "barqux" + 3
withLength: 6]) && [s[0] isEqual: @"foobar"])
EXPECT_EXCEPTION(@"Detection of invalid UTF-8 encoding #1",
OFInvalidEncodingException,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
TEST(@"+[stringWithUTF8String:length:]",
(s[0] = [OFMutableString stringWithUTF8String: "\xEF\xBB\xBF"
"foobar"
length: 6]) &&
[s[0] isEqual: @"foo"])
TEST(@"+[stringWithUnicodeString:]",
(is = [OFString stringWithUnicodeString: ucstr]) &&
[is isEqual: @"fööbär🀺"] &&
(is = [OFString stringWithUnicodeString: sucstr]) &&
[is isEqual: @"fööbär🀺"])
TEST(@"+[stringWithUTF16String:]",
(is = [OFString stringWithUTF16String: utf16str]) &&
[is isEqual: @"fööbär🀺"] &&
(is = [OFString stringWithUTF16String: sutf16str]) &&
[is isEqual: @"fööbär🀺"])
TEST(@"+[stringWithContentsOfFile:encoding]", (is = [OFString
stringWithContentsOfFile: @"testfile.txt"
encoding: OF_STRING_ENCODING_ISO_8859_1]) &&
[is isEqual: @"testäöü"])
TEST(@"+[stringWithContentsOfURL:encoding]", (is = [OFString
stringWithContentsOfURL: [OFURL URLWithString:
@"file://testfile.txt"]
encoding: OF_STRING_ENCODING_ISO_8859_1]) &&
[is isEqual: @"testäöü"])
TEST(@"-[appendUTFString:withLength:]",
R([s[0] appendUTF8String: "foo\xEF\xBB\xBF" "barqux" + 3
withLength: 6]) && [s[0] isEqual: @"foobar"])
EXPECT_EXCEPTION(@"Detection of invalid UTF-8 encoding #1",
OFInvalidEncodingException,
|
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
|
skipEmpty: YES]) &&
[a count] == 3 &&
[[a objectAtIndex: i++] isEqual: @"foo"] &&
[[a objectAtIndex: i++] isEqual: @"bar"] &&
[[a objectAtIndex: i++] isEqual: @"baz"])
TEST(@"+[stringWithPath:]",
(s[0] = [OFString stringWithPath: @"foo", @"bar", @"baz", nil]) &&
#ifndef _WIN32
[s[0] isEqual: @"foo/bar/baz"] &&
#else
[s[0] isEqual: @"foo\\bar\\baz"] &&
#endif
(s[0] = [OFString stringWithPath: @"foo", nil]) &&
[s[0] isEqual: @"foo"])
TEST(@"-[pathComponents]",
/* /tmp */
(a = [@"/tmp" pathComponents]) && [a count] == 2 &&
[[a objectAtIndex: 0] isEqual: @""] &&
[[a objectAtIndex: 1] isEqual: @"tmp"] &&
/* /tmp/ */
|
|
|
|
|
|
|
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
|
skipEmpty: YES]) &&
[a count] == 3 &&
[[a objectAtIndex: i++] isEqual: @"foo"] &&
[[a objectAtIndex: i++] isEqual: @"bar"] &&
[[a objectAtIndex: i++] isEqual: @"baz"])
TEST(@"+[stringWithPath:]",
(is = [OFString stringWithPath: @"foo", @"bar", @"baz", nil]) &&
#ifndef _WIN32
[is isEqual: @"foo/bar/baz"] &&
#else
[is isEqual: @"foo\\bar\\baz"] &&
#endif
(is = [OFString stringWithPath: @"foo", nil]) &&
[is isEqual: @"foo"])
TEST(@"-[pathComponents]",
/* /tmp */
(a = [@"/tmp" pathComponents]) && [a count] == 2 &&
[[a objectAtIndex: 0] isEqual: @""] &&
[[a objectAtIndex: 1] isEqual: @"tmp"] &&
/* /tmp/ */
|