ObjFW  Diff

Differences From Artifact [ef1e54d79a]:

To Artifact [de363dd9e3]:


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
	    [@"ß" caseInsensitiveCompare: @"→"] == OF_ORDERED_ASCENDING &&
	    [@"AA" caseInsensitiveCompare: @"z"] == OF_ORDERED_ASCENDING)

	TEST(@"-[hash] is the same if -[isEqual:] is YES",
	    [s[0] hash] == [s[2] hash])

	TEST(@"-[appendString:] and -[appendCString:]",
	    [s[1] appendCString: "1𝄞"] && [s[1] appendString: @"3"] &&
	    [[s[0] appendString: s[1]] isEqual: @"täs€1𝄞3"])

	TEST(@"-[length]", [s[0] length] == 7)
	TEST(@"-[cStringLength]", [s[0] cStringLength] == 13)
	TEST(@"-[hash]", [s[0] hash] == 0x8AC1EEF6)

	TEST(@"-[characterAtIndex:]", [s[0] characterAtIndex: 0] == 't' &&
	    [s[0] characterAtIndex: 1] == 0xE4 &&
	    [s[0] characterAtIndex: 3] == 0x20AC &&
	    [s[0] characterAtIndex: 5] == 0x1D11E)

	EXPECT_EXCEPTION(@"Detect out of range in -[characterAtIndex:]",
	    OFOutOfRangeException, [s[0] characterAtIndex: 7])

	TEST(@"-[reverse]", [[s[0] reverse] isEqual: @"3𝄞1€sät"])

	s[1] = [OFMutableString stringWithString: @"abc"];

	TEST(@"-[upper]", [[s[0] upper] isEqual: @"3𝄞1€SÄT"] &&
	    [[s[1] upper] isEqual: @"ABC"])

	TEST(@"-[lower]", [[s[0] lower] isEqual: @"3𝄞1€sät"] &&
	    [[s[1] lower] isEqual: @"abc"])

	TEST(@"+[stringWithCString:length:]",
	    (s[0] = [OFMutableString stringWithCString: "foobar"
					      length: 3]) &&
	    [s[0] isEqual: @"foo"])

	TEST(@"+[stringWithContentsOfFile:encoding]", (s[1] = [OFString
	    stringWithContentsOfFile: @"testfile.txt"
			    encoding: OF_STRING_ENCODING_ISO_8859_1]) &&
	    [s[1] isEqual: @"testäöü"])

	TEST(@"-[appendCStringWithLength:]",
	    [[s[0] appendCString: "foobarqux" + 3
		      withLength: 3] isEqual: @"foobar"])

	EXPECT_EXCEPTION(@"Detection of invalid UTF-8 encoding #1",
	    OFInvalidEncodingException,
	    [OFString stringWithCString: "\xE0\x80"])
	EXPECT_EXCEPTION(@"Detection of invalid UTF-8 encoding #2",
	    OFInvalidEncodingException,
	    [OFString stringWithCString: "\xF0\x80\x80\xC0"])

	TEST(@"-[reverse] on UTF-8 strings",
	    (s[0] = [[OFMutableString stringWithCString: "äöü€𝄞"] reverse]) &&
	    [s[0] isEqual: @"𝄞€üöä"])

	TEST(@"Conversion of ISO 8859-1 to UTF-8",
	    [[OFString stringWithCString: "\xE4\xF6\xFC"
				encoding: OF_STRING_ENCODING_ISO_8859_1]
	    isEqual: @"äöü"])

	TEST(@"Conversion of ISO 8859-15 to UTF-8",







|
|













|



|
|

|
|












|
|









|
|







70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
	    [@"ß" caseInsensitiveCompare: @"→"] == OF_ORDERED_ASCENDING &&
	    [@"AA" caseInsensitiveCompare: @"z"] == OF_ORDERED_ASCENDING)

	TEST(@"-[hash] is the same if -[isEqual:] is YES",
	    [s[0] hash] == [s[2] hash])

	TEST(@"-[appendString:] and -[appendCString:]",
	    R([s[1] appendCString: "1𝄞"]) && R([s[1] appendString: @"3"]) &&
	    R([s[0] appendString: s[1]]) && [s[0] isEqual: @"täs€1𝄞3"])

	TEST(@"-[length]", [s[0] length] == 7)
	TEST(@"-[cStringLength]", [s[0] cStringLength] == 13)
	TEST(@"-[hash]", [s[0] hash] == 0x8AC1EEF6)

	TEST(@"-[characterAtIndex:]", [s[0] characterAtIndex: 0] == 't' &&
	    [s[0] characterAtIndex: 1] == 0xE4 &&
	    [s[0] characterAtIndex: 3] == 0x20AC &&
	    [s[0] characterAtIndex: 5] == 0x1D11E)

	EXPECT_EXCEPTION(@"Detect out of range in -[characterAtIndex:]",
	    OFOutOfRangeException, [s[0] characterAtIndex: 7])

	TEST(@"-[reverse]", R([s[0] reverse]) && [s[0] isEqual: @"3𝄞1€sät"])

	s[1] = [OFMutableString stringWithString: @"abc"];

	TEST(@"-[upper]", R([s[0] upper]) && [s[0] isEqual: @"3𝄞1€SÄT"] &&
	    R([s[1] upper]) && [s[1] isEqual: @"ABC"])

	TEST(@"-[lower]", R([s[0] lower]) && [s[0] isEqual: @"3𝄞1€sät"] &&
	    R([s[1] lower]) && [s[1] isEqual: @"abc"])

	TEST(@"+[stringWithCString:length:]",
	    (s[0] = [OFMutableString stringWithCString: "foobar"
					      length: 3]) &&
	    [s[0] isEqual: @"foo"])

	TEST(@"+[stringWithContentsOfFile:encoding]", (s[1] = [OFString
	    stringWithContentsOfFile: @"testfile.txt"
			    encoding: OF_STRING_ENCODING_ISO_8859_1]) &&
	    [s[1] isEqual: @"testäöü"])

	TEST(@"-[appendCStringWithLength:]",
	    R([s[0] appendCString: "foobarqux" + 3
		       withLength: 3]) && [s[0] isEqual: @"foobar"])

	EXPECT_EXCEPTION(@"Detection of invalid UTF-8 encoding #1",
	    OFInvalidEncodingException,
	    [OFString stringWithCString: "\xE0\x80"])
	EXPECT_EXCEPTION(@"Detection of invalid UTF-8 encoding #2",
	    OFInvalidEncodingException,
	    [OFString stringWithCString: "\xF0\x80\x80\xC0"])

	TEST(@"-[reverse] on UTF-8 strings",
	    (s[0] = [OFMutableString stringWithCString: "äöü€𝄞"]) &&
	    R([s[0] reverse]) && [s[0] isEqual: @"𝄞€üöä"])

	TEST(@"Conversion of ISO 8859-1 to UTF-8",
	    [[OFString stringWithCString: "\xE4\xF6\xFC"
				encoding: OF_STRING_ENCODING_ISO_8859_1]
	    isEqual: @"äöü"])

	TEST(@"Conversion of ISO 8859-15 to UTF-8",
142
143
144
145
146
147
148




149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
				encoding: OF_STRING_ENCODING_WINDOWS_1252]
	    isEqual: @"€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ"])

	TEST(@"+[stringWithFormat:]",
	    [(s[0] = [OFMutableString stringWithFormat: @"%s: %d", "test", 123])
	    isEqual: @"test: 123"])





	TEST(@"+[stringWithPath:]",
	    (s[1] = [OFString stringWithPath: @"foo", @"bar", @"baz", nil]) &&
#ifndef _WIN32
	    [s[1] isEqual: @"foo/bar/baz"] &&
#else
	    [s[1] isEqual: @"foo\\bar\\baz"] &&
#endif
	    (s[1] = [OFString stringWithPath: @"foo", nil]) &&
	    [s[1] isEqual: @"foo"])

	TEST(@"-[appendFormat:]",
	    [([s[0] appendFormat: @"%02X", 15]) isEqual: @"test: 1230F"])

	TEST(@"-[indexOfFirstOccurrenceOfString:]",
	    [@"𝄞öö" indexOfFirstOccurrenceOfString: @"öö"] == 1 &&
	    [@"𝄞öö" indexOfFirstOccurrenceOfString: @"ö"] == 1 &&
	    [@"𝄞öö" indexOfFirstOccurrenceOfString: @"𝄞"] == 0 &&
	    [@"𝄞öö" indexOfFirstOccurrenceOfString: @"x"] == SIZE_MAX)








>
>
>
>

|

|

|

|
|
<
<
<







142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161



162
163
164
165
166
167
168
				encoding: OF_STRING_ENCODING_WINDOWS_1252]
	    isEqual: @"€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ"])

	TEST(@"+[stringWithFormat:]",
	    [(s[0] = [OFMutableString stringWithFormat: @"%s: %d", "test", 123])
	    isEqual: @"test: 123"])

	TEST(@"-[appendFormat:]",
	    R(([s[0] appendFormat: @"%02X", 15])) &&
	    [s[0] isEqual: @"test: 1230F"])

	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(@"-[indexOfFirstOccurrenceOfString:]",
	    [@"𝄞öö" indexOfFirstOccurrenceOfString: @"öö"] == 1 &&
	    [@"𝄞öö" indexOfFirstOccurrenceOfString: @"ö"] == 1 &&
	    [@"𝄞öö" indexOfFirstOccurrenceOfString: @"𝄞"] == 0 &&
	    [@"𝄞öö" indexOfFirstOccurrenceOfString: @"x"] == SIZE_MAX)

267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
	    @"#1", OFInvalidEncodingException, [@"foo%bar" stringByURLDecoding])
	EXPECT_EXCEPTION(@"Detect invalid encoding in -[stringByURLDecoding] "
	    @"#2", OFInvalidEncodingException,
	    [@"foo%FFbar" stringByURLDecoding])

	TEST(@"-[removeCharactersFromIndex:toIndex:]",
	    (s[0] = [OFMutableString stringWithString: @"𝄞öööbä€"]) &&
	    [s[0] removeCharactersFromIndex: 1
				    toIndex: 4] &&
	    [s[0] isEqual: @"𝄞bä€"] &&
	    [s[0] removeCharactersFromIndex: 0
				    toIndex: 4] &&
	    [s[0] isEqual: @""])

	EXPECT_EXCEPTION(@"Detect OoR in "
	    @"-[removeCharactersFromIndex:toIndex:] #1", OFOutOfRangeException,
	    {
		s[0] = [OFMutableString stringWithString: @"𝄞öö"];
		[s[0] substringFromIndex: 2







|
|

|
|







268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
	    @"#1", OFInvalidEncodingException, [@"foo%bar" stringByURLDecoding])
	EXPECT_EXCEPTION(@"Detect invalid encoding in -[stringByURLDecoding] "
	    @"#2", OFInvalidEncodingException,
	    [@"foo%FFbar" stringByURLDecoding])

	TEST(@"-[removeCharactersFromIndex:toIndex:]",
	    (s[0] = [OFMutableString stringWithString: @"𝄞öööbä€"]) &&
	    R([s[0] removeCharactersFromIndex: 1
				      toIndex: 4]) &&
	    [s[0] isEqual: @"𝄞bä€"] &&
	    R([s[0] removeCharactersFromIndex: 0
				      toIndex: 4]) &&
	    [s[0] isEqual: @""])

	EXPECT_EXCEPTION(@"Detect OoR in "
	    @"-[removeCharactersFromIndex:toIndex:] #1", OFOutOfRangeException,
	    {
		s[0] = [OFMutableString stringWithString: @"𝄞öö"];
		[s[0] substringFromIndex: 2
294
295
296
297
298
299
300
301

302
303
304
305
306
307
308
309
310
311

312
313
314
315
316
317

318
319
320
321
322
323
324

325
326

327
328
329
330
331
332
333
334
335
336
	EXPECT_EXCEPTION(@"Detect s > e in "
	    @"-[removeCharactersFromIndex:toIndex:]",
	    OFInvalidArgumentException,
	    [s[0] substringFromIndex: 2
			     toIndex: 0])

	TEST(@"-[replaceOccurrencesOfString:withString:]",
	    [[[OFMutableString stringWithString: @"asd fo asd fofo asd"]

	    replaceOccurrencesOfString: @"fo"
			    withString: @"foo"]
	    isEqual: @"asd foo asd foofoo asd"] &&
	    [[[OFMutableString stringWithString: @"XX"]
	    replaceOccurrencesOfString: @"X"
			    withString: @"XX"]
	    isEqual: @"XXXX"])

	TEST(@"-[removeLeadingWhitespaces]",
	    (s[0] = [OFMutableString stringWithString: whitespace[0]]) &&

	    [[s[0] removeLeadingWhitespaces] isEqual: @"asd  \t \t\t\r\n"] &&
	    (s[0] = [OFMutableString stringWithString: whitespace[1]]) &&
	    [[s[0] removeLeadingWhitespaces] isEqual: @""])

	TEST(@"-[removeTrailingWhitespaces]",
	    (s[0] = [OFMutableString stringWithString: whitespace[0]]) &&

	    [[s[0] removeTrailingWhitespaces] isEqual: @" \r \t\n\t \tasd"] &&
	    (s[0] = [OFMutableString stringWithString: whitespace[1]]) &&
	    [[s[0] removeTrailingWhitespaces] isEqual: @""])

	TEST(@"-[removeLeadingAndTrailingWhitespaces]",
	    (s[0] = [OFMutableString stringWithString: whitespace[0]]) &&
	    [[s[0] removeLeadingAndTrailingWhitespaces] isEqual: @"asd"] &&

	    (s[0] = [OFMutableString stringWithString: whitespace[1]]) &&
	    [[s[0] removeLeadingAndTrailingWhitespaces] isEqual: @""])


	TEST(@"-[stringByXMLEscaping]",
	    (s[0] = [@"<hello> &world'\"!&" stringByXMLEscaping]) &&
	    [s[0] isEqual: @"&lt;hello&gt; &amp;world&apos;&quot;!&amp;"])

	TEST(@"-[stringByXMLUnescaping]",
	    [[s[0] stringByXMLUnescaping] isEqual: @"<hello> &world'\"!&"] &&
	    [[@"&#x79;" stringByXMLUnescaping] isEqual: @"y"] &&
	    [[@"&#xe4;" stringByXMLUnescaping] isEqual: @"ä"] &&
	    [[@"&#8364;" stringByXMLUnescaping] isEqual: @"€"] &&







|
>
|
|
|
|
|
|
|



>
|

|



>
|

|



|
>

|
>


|







295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
	EXPECT_EXCEPTION(@"Detect s > e in "
	    @"-[removeCharactersFromIndex:toIndex:]",
	    OFInvalidArgumentException,
	    [s[0] substringFromIndex: 2
			     toIndex: 0])

	TEST(@"-[replaceOccurrencesOfString:withString:]",
	    (s[0] = [OFMutableString stringWithString:
	    @"asd fo asd fofo asd"]) &&
	    R([s[0] replaceOccurrencesOfString: @"fo"
				    withString: @"foo"]) &&
	    [s[0] isEqual: @"asd foo asd foofoo asd"] &&
	    (s[0] = [OFMutableString stringWithString: @"XX"]) &&
	    R([s[0] replaceOccurrencesOfString: @"X"
				    withString: @"XX"]) &&
	    [s[0] isEqual: @"XXXX"])

	TEST(@"-[removeLeadingWhitespaces]",
	    (s[0] = [OFMutableString stringWithString: whitespace[0]]) &&
	    R([s[0] removeLeadingWhitespaces]) &&
	    [s[0] isEqual: @"asd  \t \t\t\r\n"] &&
	    (s[0] = [OFMutableString stringWithString: whitespace[1]]) &&
	    R([s[0] removeLeadingWhitespaces]) && [s[0] isEqual: @""])

	TEST(@"-[removeTrailingWhitespaces]",
	    (s[0] = [OFMutableString stringWithString: whitespace[0]]) &&
	    R([s[0] removeTrailingWhitespaces]) &&
	    [s[0] isEqual: @" \r \t\n\t \tasd"] &&
	    (s[0] = [OFMutableString stringWithString: whitespace[1]]) &&
	    R([s[0] removeTrailingWhitespaces]) && [s[0] isEqual: @""])

	TEST(@"-[removeLeadingAndTrailingWhitespaces]",
	    (s[0] = [OFMutableString stringWithString: whitespace[0]]) &&
	    R([s[0] removeLeadingAndTrailingWhitespaces]) &&
	    [s[0] isEqual: @"asd"] &&
	    (s[0] = [OFMutableString stringWithString: whitespace[1]]) &&
	    R([s[0] removeLeadingAndTrailingWhitespaces]) &&
	    [s[0] isEqual: @""])

	TEST(@"-[stringByXMLEscaping]",
	    (s[0] = (id)[@"<hello> &world'\"!&" stringByXMLEscaping]) &&
	    [s[0] isEqual: @"&lt;hello&gt; &amp;world&apos;&quot;!&amp;"])

	TEST(@"-[stringByXMLUnescaping]",
	    [[s[0] stringByXMLUnescaping] isEqual: @"<hello> &world'\"!&"] &&
	    [[@"&#x79;" stringByXMLUnescaping] isEqual: @"y"] &&
	    [[@"&#xe4;" stringByXMLUnescaping] isEqual: @"ä"] &&
	    [[@"&#8364;" stringByXMLUnescaping] isEqual: @"€"] &&
347
348
349
350
351
352
353
354
355
356
357
358
359
	EXPECT_EXCEPTION(@"Detect invalid entities in -[stringByXMLUnescaping] "
	    @"#5", OFInvalidEncodingException, [@"&#g;" stringByXMLUnescaping])
	EXPECT_EXCEPTION(@"Detect invalid entities in -[stringByXMLUnescaping] "
	    @"#6", OFInvalidEncodingException, [@"&#xg;" stringByXMLUnescaping])

	TEST(@"-[stringByXMLUnescapingWithHandler:]",
	    (h = [[[EntityHandler alloc] init] autorelease]) &&
	    (s[0] = [@"x&foo;y" stringByXMLUnescapingWithHandler: h]) &&
	    [s[0] isEqual: @"xbary"])

	[pool drain];
}
@end







|
|




353
354
355
356
357
358
359
360
361
362
363
364
365
	EXPECT_EXCEPTION(@"Detect invalid entities in -[stringByXMLUnescaping] "
	    @"#5", OFInvalidEncodingException, [@"&#g;" stringByXMLUnescaping])
	EXPECT_EXCEPTION(@"Detect invalid entities in -[stringByXMLUnescaping] "
	    @"#6", OFInvalidEncodingException, [@"&#xg;" stringByXMLUnescaping])

	TEST(@"-[stringByXMLUnescapingWithHandler:]",
	    (h = [[[EntityHandler alloc] init] autorelease]) &&
	    [[@"x&foo;y" stringByXMLUnescapingWithHandler: h]
	    isEqual: @"xbary"])

	[pool drain];
}
@end