ObjFW  Diff

Differences From Artifact [356111a391]:

To Artifact [4e0f09b991]:


30
31
32
33
34
35
36
37

38
39
40
41
42
43
44
30
31
32
33
34
35
36

37
38
39
40
41
42
43
44







-
+







#import "OFInvalidEncodingException.h"
#import "OFInvalidFormatException.h"
#import "OFOutOfRangeException.h"
#import "OFUnknownXMLEntityException.h"

#import "TestsAppDelegate.h"

static OFString *module = @"OFString";
static OFString *module = nil;
static OFString* whitespace[] = {
	@" \r \t\n\t \tasd  \t \t\t\r\n",
	@" \t\t  \t\t  \t \t"
};
static of_unichar_t ucstr[] = {
	0xFEFF, 'f', 0xF6, 0xF6, 'b', 0xE4, 'r', 0x1F03A, 0
};
65
66
67
68
69
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
65
66
67
68
69
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







-
+
+













+
+
+
+
-
-
+
+







-
-
-
-
-
-
+
+
+
+
+
+



-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+


-
-
-
-
+
+
+
+
+







		return @"bar";

	return nil;
}
@end

@implementation TestsAppDelegate (OFStringTests)
- (void)stringTests
- (void)stringTestsWithClass: (Class)stringClass
		mutableClass: (Class)mutableStringClass
{
	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;
#endif

	module = [stringClass className];

#define C(s) [stringClass stringWithString: s]

	s[0] = [OFMutableString stringWithString: @"täs€"];
	s[1] = [OFMutableString string];
	s[0] = [mutableStringClass stringWithString: @"täs€"];
	s[1] = [mutableStringClass string];
	s[2] = [[s[0] copy] autorelease];

	TEST(@"-[isEqual:]", [s[0] isEqual: s[2]] &&
	    ![s[0] isEqual: [[[OFObject alloc] init] autorelease]])

	TEST(@"-[compare:]", [s[0] compare: s[2]] == OF_ORDERED_SAME &&
	    [s[0] compare: @""] != OF_ORDERED_SAME &&
	    [@"" compare: @"a"] == OF_ORDERED_ASCENDING &&
	    [@"a" compare: @"b"] == OF_ORDERED_ASCENDING &&
	    [@"cd" compare: @"bc"] == OF_ORDERED_DESCENDING &&
	    [@"ä" compare: @"ö"] == OF_ORDERED_ASCENDING &&
	    [@"€" compare: @"ß"] == OF_ORDERED_DESCENDING &&
	    [@"aa" compare: @"z"] == OF_ORDERED_ASCENDING)
	    [C(@"") compare: @"a"] == OF_ORDERED_ASCENDING &&
	    [C(@"a") compare: @"b"] == OF_ORDERED_ASCENDING &&
	    [C(@"cd") compare: @"bc"] == OF_ORDERED_DESCENDING &&
	    [C(@"ä") compare: @"ö"] == OF_ORDERED_ASCENDING &&
	    [C(@"€") compare: @"ß"] == OF_ORDERED_DESCENDING &&
	    [C(@"aa") compare: @"z"] == OF_ORDERED_ASCENDING)

#ifdef OF_HAVE_UNICODE_TABLES
	TEST(@"-[caseInsensitiveCompare:]",
	    [@"a" caseInsensitiveCompare: @"A"] == OF_ORDERED_SAME &&
	    [@"Ä" caseInsensitiveCompare: @"ä"] == OF_ORDERED_SAME &&
	    [@"я" caseInsensitiveCompare: @"Я"] == OF_ORDERED_SAME &&
	    [@"€" caseInsensitiveCompare: @"ß"] == OF_ORDERED_DESCENDING &&
	    [@"ß" caseInsensitiveCompare: @"→"] == OF_ORDERED_ASCENDING &&
	    [@"AA" caseInsensitiveCompare: @"z"] == OF_ORDERED_ASCENDING &&
	    [[OFString stringWithUTF8String: "ABC"] caseInsensitiveCompare:
	    [OFString stringWithUTF8String: "AbD"]] == [@"abc" compare: @"abd"])
	    [C(@"a") caseInsensitiveCompare: @"A"] == OF_ORDERED_SAME &&
	    [C(@"Ä") caseInsensitiveCompare: @"ä"] == OF_ORDERED_SAME &&
	    [C(@"я") caseInsensitiveCompare: @"Я"] == OF_ORDERED_SAME &&
	    [C(@"€") caseInsensitiveCompare: @"ß"] == OF_ORDERED_DESCENDING &&
	    [C(@"ß") caseInsensitiveCompare: @"→"] == OF_ORDERED_ASCENDING &&
	    [C(@"AA") caseInsensitiveCompare: @"z"] == OF_ORDERED_ASCENDING &&
	    [[stringClass stringWithUTF8String: "ABC"] caseInsensitiveCompare:
	    [stringClass stringWithUTF8String: "AbD"]] ==
	    [C(@"abc") compare: @"abd"])
#else
	TEST(@"-[caseInsensitiveCompare:]",
	    [@"a" caseInsensitiveCompare: @"A"] == OF_ORDERED_SAME &&
	    [@"AA" caseInsensitiveCompare: @"z"] == OF_ORDERED_ASCENDING &&
	    [[OFString stringWithUTF8String: "ABC"] caseInsensitiveCompare:
	    [OFString stringWithUTF8String: "AbD"]] == [@"abc" compare: @"abd"])
	    [C(@"a") caseInsensitiveCompare: @"A"] == OF_ORDERED_SAME &&
	    [C(@"AA") caseInsensitiveCompare: @"z"] == OF_ORDERED_ASCENDING &&
	    [[stringClass stringWithUTF8String: "ABC"] caseInsensitiveCompare:
	    [stringClass stringWithUTF8String: "AbD"]] ==
	    [C(@"abc") compare: @"abd"])
#endif

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

	TEST(@"-[description]", [[s[0] description] isEqual: s[0]])

140
141
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
169
170
171
172
173
174
175
176
177
178
179
180
181

182
183
184
185
186
187
188



189
190
191
192

193
194

195
196
197
198

199
200

201
202
203
204

205
206
207
208
209

210
211
212
213
214
215
216
217
218
219
220
221
222

223
224
225

226
227
228
229
230
231
232
233


234
235
236
237
238
239


240
241
242
243
244
245
246
247
248
249





250
251
252
253
254
255
256


257
258
259
260
261

262
263
264
265

266

267
268
269

270
271
272
273


274
275
276
277
278

279
280
281
282


283
284
285
286
287
288

289
290
291
292

293
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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352












353
354
355
356
357


358
359
360


361
362


363
364
365

366
367
368

369
370
371


372
373
374


375
376
377
378
379


380
381
382
383
384
385
386
387
388
389

390
391
392
393
394
395
396
397
398
399
400
401
402
403

404
405
406

407
408
409
410
411
412
413

414
415
416
417

418
419
420
421

422
423
424

425
426
427
428

429
430
431
432
433

434
435
436

437
438
439
440
441
442
443
444






445
446
447
448
449
450




451
452
453
454
455



456
457
458
459




460
461
462
463
464
465
466
467
468
469



470
471

472
473
474
475



476
477
478
479
480
481
482




483
484
485
486
487
488
489
490






491
492
493
494
495
496




497
498
499
500
501
502
503
504
505



506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524


525
526
527
528
529

530
531

532
533

534
535
536

537
538

539
540

541
542

543
544
545

546
547

548
549
550
551
552
553
554

555
556
557
558

559
560

561
562
563
564
565
566
567

568
569
570
571
572
573


574
575
576
577
578
579


580
581
582

583
584
585
586
587
588
589
590

591
592

593
594
595
596

597
598

599

600

601
602
603
604

605
606
607

608
609
610

611
612
613

614
615
616
617

618
619
620
621

622
623
624
625

626
627
628
629

630

631
632

633

634
635
636

637
638
639
640
641
642


643
644
645

646
647
648

649
650
651
652
653
654
655
656
657
658
659
660
661
662
663

664
665
666
667
668
669
670

671
672
673
674
675
676
677
678
679
680
681
682
683
684

685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705

706
707
708
709
710

711
712
713
714
715
716

717
718
719
720
721
722
723
724
725

726
727
728

729
730
731
732

733
734
735

736
737
738
739

740
741

742
743
744
745
746


747
748
749
750
751
752
753





754
755
756

757
758


759
760

761
762

763
764

765
766


767
768
769
770

771
772
773
774
775

776
777
778
779
780
781
782
783
784

785
786
787
788
789
790
791
147
148
149
150
151
152
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

188
189
190
191
192



193
194
195
196
197
198

199
200

201
202
203
204

205
206

207
208
209
210

211
212
213
214
215

216
217
218
219
220
221
222
223
224
225
226
227
228

229
230
231

232
233




234


235
236
237
238
239
240


241
242
243
244
245
246
247





248
249
250
251
252
253
254
255
256
257


258
259
260
261
262
263

264
265
266
267
268
269

270
271
272

273
274
275
276

277
278
279
280
281
282

283
284
285
286

287
288
289
290
291
292
293

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
337
338

339
340
341
342
343
344
345
346
347












348
349
350
351
352
353
354
355
356
357
358
359

360
361


362
363
364
365

366
367
368

369
370
371
372

373
374
375

376
377


378
379
380


381
382
383
384
385


386
387
388
389
390
391
392
393
394
395
396

397
398
399
400
401
402
403
404
405
406
407
408
409
410

411
412
413

414
415
416
417
418
419
420

421
422
423
424

425
426
427
428

429
430
431

432
433
434
435

436
437
438
439
440

441
442
443

444
445
446






447
448
449
450
451
452
453
454




455
456
457
458
459
460



461
462
463
464



465
466
467
468
469
470
471
472
473
474
475



476
477
478
479

480
481



482
483
484
485
486
487




488
489
490
491
492
493






494
495
496
497
498
499
500
501




502
503
504
505
506
507
508
509
510
511



512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531


532
533
534
535
536
537

538
539

540
541

542
543
544

545
546

547
548

549
550

551
552
553

554
555

556
557
558
559
560
561
562

563
564
565
566

567
568

569
570
571
572
573
574
575

576
577
578
579
580


581
582
583
584
585
586


587
588
589
590

591
592
593
594
595
596
597
598

599
600

601
602
603
604

605
606

607
608
609

610
611
612
613

614
615
616

617
618
619

620
621
622

623
624
625
626

627
628
629
630

631
632
633
634

635
636
637
638
639
640

641
642
643
644

645
646
647

648
649
650
651
652
653

654
655
656
657

658
659
660

661
662
663
664
665
666
667
668
669
670
671
672
673
674
675

676
677
678
679
680
681
682

683
684
685
686
687
688
689
690
691
692
693
694
695
696

697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717

718
719
720
721
722

723
724
725
726
727
728

729
730
731
732
733
734
735
736
737

738
739
740

741
742
743
744

745
746
747

748
749
750
751

752
753

754
755
756
757


758
759
760
761





762
763
764
765
766
767
768

769
770

771
772
773

774
775

776
777

778
779

780
781
782
783
784

785
786
787
788
789

790
791
792
793
794
795
796
797
798

799
800
801
802
803
804
805
806







-
+
















-
+
















-
+




-
-
-
+
+
+



-
+

-
+



-
+

-
+



-
+




-
+












-
+


-
+

-
-
-
-

-
-
+
+




-
-
+
+





-
-
-
-
-
+
+
+
+
+





-
-
+
+




-
+




+
-
+


-
+



-
+
+




-
+



-
+
+





-
+



-
+





-
+



-
+




-
+



-
+




-
+





-
+





-
+




-
+
+







-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-


-
-
+
+


-
+
+

-
+
+


-
+


-
+

-
-
+
+

-
-
+
+



-
-
+
+









-
+













-
+


-
+






-
+



-
+



-
+


-
+



-
+




-
+


-
+


-
-
-
-
-
-
+
+
+
+
+
+


-
-
-
-
+
+
+
+


-
-
-
+
+
+

-
-
-
+
+
+
+







-
-
-
+
+
+

-
+

-
-
-
+
+
+



-
-
-
-
+
+
+
+


-
-
-
-
-
-
+
+
+
+
+
+


-
-
-
-
+
+
+
+






-
-
-
+
+
+

















-
-
+
+




-
+

-
+

-
+


-
+

-
+

-
+

-
+


-
+

-
+






-
+



-
+

-
+






-
+




-
-
+
+




-
-
+
+


-
+







-
+

-
+



-
+

-
+

+
-
+



-
+


-
+


-
+


-
+



-
+



-
+



-
+




+
-
+


+
-
+


-
+





-
+
+


-
+


-
+














-
+






-
+













-
+




















-
+




-
+





-
+








-
+


-
+



-
+


-
+



-
+

-
+



-
-
+
+


-
-
-
-
-
+
+
+
+
+


-
+

-
+
+

-
+

-
+

-
+

-
+
+



-
+




-
+








-
+







	    [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"];
	s[1] = [mutableStringClass stringWithString: @"abc"];

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

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

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

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

	TEST(@"-[capitalizedString]", [[@"džbla tdžst TDŽST" capitalizedString]
	TEST(@"-[capitalizedString]", [[C(@"džbla tdžst TDŽST") capitalizedString]
	    isEqual: @"Džbla Tdžst Tdžst"])
#else
	TEST(@"-[uppercase]", R([s[0] uppercase]) &&
	    [s[0] isEqual: @"3𝄞1€SäT"] &&
	    R([s[1] uppercase]) && [s[1] isEqual: @"ABC"])

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

	TEST(@"-[uppercaseString]",
	    [[s[0] uppercaseString] isEqual: @"3𝄞1€SäT"])

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

	TEST(@"-[capitalizedString]", [[@"džbla tdžst TDŽST" capitalizedString]
	TEST(@"-[capitalizedString]", [[C(@"džbla tdžst TDŽST") capitalizedString]
	    isEqual: @"džbla Tdžst TDŽst"])
#endif

	TEST(@"+[stringWithUTF8String:length:]",
	    (s[0] = [OFMutableString stringWithUTF8String: "\xEF\xBB\xBF"
							   "foobar"
						   length: 6]) &&
	    (s[0] = [mutableStringClass stringWithUTF8String: "\xEF\xBB\xBF"
							      "foobar"
						      length: 6]) &&
	    [s[0] isEqual: @"foo"])

	TEST(@"+[stringWithUTF16String:]",
	    (is = [OFString stringWithUTF16String: utf16str]) &&
	    (is = [stringClass stringWithUTF16String: utf16str]) &&
	    [is isEqual: @"fööbär🀺"] &&
	    (is = [OFString stringWithUTF16String: sutf16str]) &&
	    (is = [stringClass stringWithUTF16String: sutf16str]) &&
	    [is isEqual: @"fööbär🀺"])

	TEST(@"+[stringWithUTF32String:]",
	    (is = [OFString stringWithUTF32String: ucstr]) &&
	    (is = [stringClass stringWithUTF32String: ucstr]) &&
	    [is isEqual: @"fööbär🀺"] &&
	    (is = [OFString stringWithUTF32String: sucstr]) &&
	    (is = [stringClass stringWithUTF32String: sucstr]) &&
	    [is isEqual: @"fööbär🀺"])

#ifdef OF_HAVE_FILES
	TEST(@"+[stringWithContentsOfFile:encoding]", (is = [OFString
	TEST(@"+[stringWithContentsOfFile:encoding]", (is = [stringClass
	    stringWithContentsOfFile: @"testfile.txt"
			    encoding: OF_STRING_ENCODING_ISO_8859_1]) &&
	    [is isEqual: @"testäöü"])

	TEST(@"+[stringWithContentsOfURL:encoding]", (is = [OFString
	TEST(@"+[stringWithContentsOfURL:encoding]", (is = [stringClass
	    stringWithContentsOfURL: [OFURL URLWithString:
					 @"file://testfile.txt"]
			   encoding: OF_STRING_ENCODING_ISO_8859_1]) &&
	    [is isEqual: @"testäöü"])
#endif

	TEST(@"-[appendUTFString:length:]",
	    R([s[0] appendUTF8String: "foo\xEF\xBB\xBF" "barqux" + 3
			      length: 6]) && [s[0] isEqual: @"foobar"])

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

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

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

#ifdef HAVE_ISO_8859_15
	TEST(@"Conversion of ISO 8859-15 to Unicode",
	    [[OFString stringWithCString: "\xA4\xA6\xA8\xB4\xB8\xBC\xBD\xBE"
				encoding: OF_STRING_ENCODING_ISO_8859_15]
	    [[stringClass stringWithCString: "\xA4\xA6\xA8\xB4\xB8\xBC\xBD\xBE"
				   encoding: OF_STRING_ENCODING_ISO_8859_15]
	    isEqual: @"€ŠšŽžŒœŸ"])
#endif

#ifdef HAVE_WINDOWS_1252
	TEST(@"Conversion of Windows 1252 to Unicode",
	    [[OFString stringWithCString: "\x80\x82\x83\x84\x85\x86\x87\x88"
					  "\x89\x8A\x8B\x8C\x8E\x91\x92\x93"
					  "\x94\x95\x96\x97\x98\x99\x9A\x9B"
					  "\x9C\x9E\x9F"
				encoding: OF_STRING_ENCODING_WINDOWS_1252]
	    [[stringClass stringWithCString: "\x80\x82\x83\x84\x85\x86\x87\x88"
					     "\x89\x8A\x8B\x8C\x8E\x91\x92\x93"
					     "\x94\x95\x96\x97\x98\x99\x9A\x9B"
					     "\x9C\x9E\x9F"
				   encoding: OF_STRING_ENCODING_WINDOWS_1252]
	    isEqual: @"€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ"])
#endif

#ifdef HAVE_CODEPAGE_437
	TEST(@"Conversion of Codepage 437 to Unicode",
	    [[OFString stringWithCString: "\xB0\xB1\xB2\xDB"
				encoding: OF_STRING_ENCODING_CODEPAGE_437]
	    [[stringClass stringWithCString: "\xB0\xB1\xB2\xDB"
				   encoding: OF_STRING_ENCODING_CODEPAGE_437]
	    isEqual: @"░▒▓█"])
#endif

	TEST(@"Conversion of Unicode to ASCII #1",
	    !strcmp([@"This is a test" cStringWithEncoding:
	    !strcmp([C(@"This is a test") cStringWithEncoding:
	    OF_STRING_ENCODING_ASCII], "This is a test"))

	EXPECT_EXCEPTION(@"Conversion of Unicode to ASCII #2",
	    OFInvalidEncodingException,
	    [C(@"This is a tést")
	    [@"This is a tést" cStringWithEncoding: OF_STRING_ENCODING_ASCII])
	    cStringWithEncoding: OF_STRING_ENCODING_ASCII])

	TEST(@"Conversion of Unicode to ISO-8859-1 #1",
	    !strcmp([@"This is ä test" cStringWithEncoding:
	    !strcmp([C(@"This is ä test") cStringWithEncoding:
	    OF_STRING_ENCODING_ISO_8859_1], "This is \xE4 test"))

	EXPECT_EXCEPTION(@"Conversion of Unicode to ISO-8859-1 #2",
	    OFInvalidEncodingException, [@"This is ä t€st" cStringWithEncoding:
	    OFInvalidEncodingException,
	    [C(@"This is ä t€st") cStringWithEncoding:
	    OF_STRING_ENCODING_ISO_8859_1])

#ifdef HAVE_ISO_8859_15
	TEST(@"Conversion of Unicode to ISO-8859-15 #1",
	    !strcmp([@"This is ä t€st" cStringWithEncoding:
	    !strcmp([C(@"This is ä t€st") cStringWithEncoding:
	    OF_STRING_ENCODING_ISO_8859_15], "This is \xE4 t\xA4st"))

	EXPECT_EXCEPTION(@"Conversion of Unicode to ISO-8859-15 #2",
	    OFInvalidEncodingException, [@"This is ä t€st…" cStringWithEncoding:
	    OFInvalidEncodingException,
	    [C(@"This is ä t€st…") cStringWithEncoding:
	    OF_STRING_ENCODING_ISO_8859_15])
#endif

#ifdef HAVE_WINDOWS_1252
	TEST(@"Conversion of Unicode to Windows-1252 #1",
	    !strcmp([@"This is ä t€st…" cStringWithEncoding:
	    !strcmp([C(@"This is ä t€st…") cStringWithEncoding:
	    OF_STRING_ENCODING_WINDOWS_1252], "This is \xE4 t\x80st\x85"))

	EXPECT_EXCEPTION(@"Conversion of Unicode to Windows-1252 #2",
	    OFInvalidEncodingException, [@"This is ä t€st…‼"
	    OFInvalidEncodingException, [C(@"This is ä t€st…‼")
	    cStringWithEncoding: OF_STRING_ENCODING_WINDOWS_1252])
#endif

#ifdef HAVE_CODEPAGE_437
	TEST(@"Conversion of Unicode to Codepage 437 #1",
	    !strcmp([@"Tést strîng ░▒▓" cStringWithEncoding:
	    !strcmp([C(@"Tést strîng ░▒▓") cStringWithEncoding:
	    OF_STRING_ENCODING_CODEPAGE_437], "T\x82st str\x8Cng \xB0\xB1\xB2"))

	EXPECT_EXCEPTION(@"Conversion of Unicode to Codepage 437 #2",
	    OFInvalidEncodingException, [@"T€st strîng ░▒▓"
	    OFInvalidEncodingException, [C(@"T€st strîng ░▒▓")
	    cStringWithEncoding: OF_STRING_ENCODING_CODEPAGE_437])
#endif

	TEST(@"Lossy conversion of Unicode to ASCII",
	    !strcmp([@"This is a tést" lossyCStringWithEncoding:
	    !strcmp([C(@"This is a tést") lossyCStringWithEncoding:
	    OF_STRING_ENCODING_ASCII], "This is a t?st"))

	TEST(@"Lossy conversion of Unicode to ISO-8859-1",
	    !strcmp([@"This is ä t€st" lossyCStringWithEncoding:
	    !strcmp([C(@"This is ä t€st") lossyCStringWithEncoding:
	    OF_STRING_ENCODING_ISO_8859_1], "This is \xE4 t?st"))

#ifdef HAVE_ISO_8859_15
	TEST(@"Lossy conversion of Unicode to ISO-8859-15",
	    !strcmp([@"This is ä t€st…" lossyCStringWithEncoding:
	    !strcmp([C(@"This is ä t€st…") lossyCStringWithEncoding:
	    OF_STRING_ENCODING_ISO_8859_15], "This is \xE4 t\xA4st?"))
#endif

#ifdef HAVE_WINDOWS_1252
	TEST(@"Lossy conversion of Unicode to Windows-1252",
	    !strcmp([@"This is ä t€st…‼" lossyCStringWithEncoding:
	    !strcmp([C(@"This is ä t€st…‼") lossyCStringWithEncoding:
	    OF_STRING_ENCODING_WINDOWS_1252], "This is \xE4 t\x80st\x85?"))
#endif

#ifdef HAVE_CODEPAGE_437
	TEST(@"Lossy conversion of Unicode to Codepage 437",
	    !strcmp([@"T€st strîng ░▒▓" lossyCStringWithEncoding:
	    !strcmp([C(@"T€st strîng ░▒▓") lossyCStringWithEncoding:
	    OF_STRING_ENCODING_CODEPAGE_437], "T?st str\x8Cng \xB0\xB1\xB2"))
#endif

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

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

	TEST(@"-[rangeOfString:]",
	    [@"𝄞öö" rangeOfString: @"öö"].location == 1 &&
	    [@"𝄞öö" rangeOfString: @"ö"].location == 1 &&
	    [@"𝄞öö" rangeOfString: @"𝄞"].location == 0 &&
	    [@"𝄞öö" rangeOfString: @"x"].location == OF_NOT_FOUND &&
	    [@"𝄞öö" rangeOfString: @"öö"
			  options: OF_STRING_SEARCH_BACKWARDS].location == 1 &&
	    [@"𝄞öö" rangeOfString: @"ö"
			  options: OF_STRING_SEARCH_BACKWARDS].location == 2 &&
	    [@"𝄞öö" rangeOfString: @"𝄞"
			  options: OF_STRING_SEARCH_BACKWARDS].location == 0 &&
	    [@"𝄞öö" rangeOfString: @"x"
			  options: OF_STRING_SEARCH_BACKWARDS].location ==
	    [C(@"𝄞öö") rangeOfString: @"öö"].location == 1 &&
	    [C(@"𝄞öö") rangeOfString: @"ö"].location == 1 &&
	    [C(@"𝄞öö") rangeOfString: @"𝄞"].location == 0 &&
	    [C(@"𝄞öö") rangeOfString: @"x"].location == OF_NOT_FOUND &&
	    [C(@"𝄞öö") rangeOfString: @"öö"
	    options: OF_STRING_SEARCH_BACKWARDS].location == 1 &&
	    [C(@"𝄞öö") rangeOfString: @"ö"
	    options: OF_STRING_SEARCH_BACKWARDS].location == 2 &&
	    [C(@"𝄞öö") rangeOfString: @"𝄞"
	    options: OF_STRING_SEARCH_BACKWARDS].location == 0 &&
	    [C(@"𝄞öö") rangeOfString: @"x"
	    options: OF_STRING_SEARCH_BACKWARDS].location == OF_NOT_FOUND)
	     OF_NOT_FOUND)

	TEST(@"-[substringWithRange:]",
	    [[@"𝄞öö" substringWithRange: of_range(1, 1)] isEqual: @"ö"] &&
	    [[@"𝄞öö" substringWithRange: of_range(3, 0)] isEqual: @""])
	    [[C(@"𝄞öö") substringWithRange: of_range(1, 1)] isEqual: @"ö"] &&
	    [[C(@"𝄞öö") substringWithRange: of_range(3, 0)] isEqual: @""])

	EXPECT_EXCEPTION(@"Detect out of range in -[substringWithRange:] #1",
	    OFOutOfRangeException, [@"𝄞öö" substringWithRange: of_range(2, 2)])
	    OFOutOfRangeException,
	    [C(@"𝄞öö") substringWithRange: of_range(2, 2)])
	EXPECT_EXCEPTION(@"Detect out of range in -[substringWithRange:] #2",
	    OFOutOfRangeException, [@"𝄞öö" substringWithRange: of_range(4, 0)])
	    OFOutOfRangeException,
	    [C(@"𝄞öö") substringWithRange: of_range(4, 0)])

	TEST(@"-[stringByAppendingString:]",
	    [[@"foo" stringByAppendingString: @"bar"] isEqual: @"foobar"])
	    [[C(@"foo") stringByAppendingString: @"bar"] isEqual: @"foobar"])

	TEST(@"-[stringByPrependingString:]",
	    [[@"foo" stringByPrependingString: @"bar"] isEqual: @"barfoo"])
	    [[C(@"foo") stringByPrependingString: @"bar"] isEqual: @"barfoo"])

	TEST(@"-[hasPrefix:]", [@"foobar" hasPrefix: @"foo"] &&
	    ![@"foobar" hasPrefix: @"foobar0"])
	TEST(@"-[hasPrefix:]", [C(@"foobar") hasPrefix: @"foo"] &&
	    ![C(@"foobar") hasPrefix: @"foobar0"])

	TEST(@"-[hasSuffix:]", [@"foobar" hasSuffix: @"bar"] &&
	    ![@"foobar" hasSuffix: @"foobar0"])
	TEST(@"-[hasSuffix:]", [C(@"foobar") hasSuffix: @"bar"] &&
	    ![C(@"foobar") hasSuffix: @"foobar0"])

	i = 0;
	TEST(@"-[componentsSeparatedByString:]",
	    (a = [@"fooXXbarXXXXbazXXXX" componentsSeparatedByString: @"XX"]) &&
	    [a count] == 6 &&
	    (a = [C(@"fooXXbarXXXXbazXXXX")
	    componentsSeparatedByString: @"XX"]) && [a count] == 6 &&
	    [[a objectAtIndex: i++] isEqual: @"foo"] &&
	    [[a objectAtIndex: i++] isEqual: @"bar"] &&
	    [[a objectAtIndex: i++] isEqual: @""] &&
	    [[a objectAtIndex: i++] isEqual: @"baz"] &&
	    [[a objectAtIndex: i++] isEqual: @""] &&
	    [[a objectAtIndex: i++] isEqual: @""])

	i = 0;
	TEST(@"-[componentsSeparatedByString:options:]",
	    (a = [@"fooXXbarXXXXbazXXXX"
	    (a = [C(@"fooXXbarXXXXbazXXXX")
	    componentsSeparatedByString: @"XX"
				options: OF_STRING_SKIP_EMPTY]) &&
	    [a count] == 3 &&
	    [[a objectAtIndex: i++] isEqual: @"foo"] &&
	    [[a objectAtIndex: i++] isEqual: @"bar"] &&
	    [[a objectAtIndex: i++] isEqual: @"baz"])

#if !defined(OF_WINDOWS) && !defined(OF_MSDOS)
# define EXPECTED @"foo/bar/baz"
#else
# define EXPECTED @"foo\\bar\\baz"
#endif
	TEST(@"+[pathWithComponents:]",
	    (is = [OFString pathWithComponents: [OFArray arrayWithObjects:
	    (is = [stringClass pathWithComponents: [OFArray arrayWithObjects:
	    @"foo", @"bar", @"baz", nil]]) &&
	    [is isEqual: EXPECTED] &&
	    (is = [OFString pathWithComponents:
	    (is = [stringClass pathWithComponents:
	    [OFArray arrayWithObjects: @"foo", nil]]) &&
	    [is isEqual: @"foo"])
#undef EXPECTED

	TEST(@"-[pathComponents]",
	    /* /tmp */
	    (a = [@"/tmp" pathComponents]) && [a count] == 2 &&
	    (a = [C(@"/tmp") pathComponents]) && [a count] == 2 &&
	    [[a objectAtIndex: 0] isEqual: @""] &&
	    [[a objectAtIndex: 1] isEqual: @"tmp"] &&
	    /* /tmp/ */
	    (a = [@"/tmp/" pathComponents]) && [a count] == 2 &&
	    (a = [C(@"/tmp/") pathComponents]) && [a count] == 2 &&
	    [[a objectAtIndex: 0] isEqual: @""] &&
	    [[a objectAtIndex: 1] isEqual: @"tmp"] &&
	    /* / */
	    (a = [@"/" pathComponents]) && [a count] == 1 &&
	    (a = [C(@"/") pathComponents]) && [a count] == 1 &&
	    [[a objectAtIndex: 0] isEqual: @""] &&
	    /* foo/bar */
	    (a = [@"foo/bar" pathComponents]) && [a count] == 2 &&
	    (a = [C(@"foo/bar") pathComponents]) && [a count] == 2 &&
	    [[a objectAtIndex: 0] isEqual: @"foo"] &&
	    [[a objectAtIndex: 1] isEqual: @"bar"] &&
	    /* foo/bar/baz/ */
	    (a = [@"foo/bar/baz" pathComponents]) && [a count] == 3 &&
	    (a = [C(@"foo/bar/baz") pathComponents]) && [a count] == 3 &&
	    [[a objectAtIndex: 0] isEqual: @"foo"] &&
	    [[a objectAtIndex: 1] isEqual: @"bar"] &&
	    [[a objectAtIndex: 2] isEqual: @"baz"] &&
	    /* foo// */
	    (a = [@"foo//" pathComponents]) && [a count] == 2 &&
	    (a = [C(@"foo//") pathComponents]) && [a count] == 2 &&
	    [[a objectAtIndex: 0] isEqual: @"foo"] &&
	    [[a objectAtIndex: 1] isEqual: @""] &&
	    [[@"" pathComponents] count] == 0)
	    [[C(@"") pathComponents] count] == 0)

	TEST(@"-[lastPathComponent]",
	    [[@"/tmp" lastPathComponent] isEqual: @"tmp"] &&
	    [[@"/tmp/" lastPathComponent] isEqual: @"tmp"] &&
	    [[@"/" lastPathComponent] isEqual: @""] &&
	    [[@"foo" lastPathComponent] isEqual: @"foo"] &&
	    [[@"foo/bar" lastPathComponent] isEqual: @"bar"] &&
	    [[@"foo/bar/baz/" lastPathComponent] isEqual: @"baz"])
	    [[C(@"/tmp") lastPathComponent] isEqual: @"tmp"] &&
	    [[C(@"/tmp/") lastPathComponent] isEqual: @"tmp"] &&
	    [[C(@"/") lastPathComponent] isEqual: @""] &&
	    [[C(@"foo") lastPathComponent] isEqual: @"foo"] &&
	    [[C(@"foo/bar") lastPathComponent] isEqual: @"bar"] &&
	    [[C(@"foo/bar/baz/") lastPathComponent] isEqual: @"baz"])

	TEST(@"-[pathExtension]",
	    [[@"foo.bar" pathExtension] isEqual: @"bar"] &&
	    [[@"foo/.bar" pathExtension] isEqual: @""] &&
	    [[@"foo/.bar.baz" pathExtension] isEqual: @"baz"] &&
	    [[@"foo/bar.baz/" pathExtension] isEqual: @"baz"])
	    [[C(@"foo.bar") pathExtension] isEqual: @"bar"] &&
	    [[C(@"foo/.bar") pathExtension] isEqual: @""] &&
	    [[C(@"foo/.bar.baz") pathExtension] isEqual: @"baz"] &&
	    [[C(@"foo/bar.baz/") pathExtension] isEqual: @"baz"])

	TEST(@"-[stringByDeletingLastPathComponent]",
	    [[@"/tmp" stringByDeletingLastPathComponent] isEqual: @"/"] &&
	    [[@"/tmp/" stringByDeletingLastPathComponent] isEqual: @"/"] &&
	    [[@"/tmp/foo/" stringByDeletingLastPathComponent]
	    [[C(@"/tmp") stringByDeletingLastPathComponent] isEqual: @"/"] &&
	    [[C(@"/tmp/") stringByDeletingLastPathComponent] isEqual: @"/"] &&
	    [[C(@"/tmp/foo/") stringByDeletingLastPathComponent]
	    isEqual: @"/tmp"] &&
	    [[@"foo/bar" stringByDeletingLastPathComponent] isEqual: @"foo"] &&
	    [[@"/" stringByDeletingLastPathComponent] isEqual: @"/"] &&
	    [[@"foo" stringByDeletingLastPathComponent] isEqual: @"."])
	    [[C(@"foo/bar") stringByDeletingLastPathComponent]
	    isEqual: @"foo"] &&
	    [[C(@"/") stringByDeletingLastPathComponent] isEqual: @"/"] &&
	    [[C(@"foo") stringByDeletingLastPathComponent] isEqual: @"."])

#if !defined(OF_WINDOWS) && !defined(OF_MSDOS)
# define EXPECTED @"/foo./bar"
#else
# define EXPECTED @"\\foo.\\bar"
#endif
	TEST(@"-[stringByDeletingPathExtension]",
	    [[@"foo.bar" stringByDeletingPathExtension] isEqual: @"foo"] &&
	    [[@"foo..bar" stringByDeletingPathExtension] isEqual: @"foo."] &&
	    [[@"/foo./bar" stringByDeletingPathExtension]
	    [[C(@"foo.bar") stringByDeletingPathExtension] isEqual: @"foo"] &&
	    [[C(@"foo..bar") stringByDeletingPathExtension] isEqual: @"foo."] &&
	    [[C(@"/foo./bar") stringByDeletingPathExtension]
	    isEqual: @"/foo./bar"] &&
	    [[@"/foo./bar.baz" stringByDeletingPathExtension]
	    [[C(@"/foo./bar.baz") stringByDeletingPathExtension]
	    isEqual: EXPECTED] &&
	    [[@"foo.bar/" stringByDeletingPathExtension] isEqual: @"foo"] &&
	    [[@".foo" stringByDeletingPathExtension] isEqual: @".foo"] &&
	    [[@".foo.bar" stringByDeletingPathExtension] isEqual: @".foo"])
	    [[C(@"foo.bar/") stringByDeletingPathExtension] isEqual: @"foo"] &&
	    [[C(@".foo") stringByDeletingPathExtension] isEqual: @".foo"] &&
	    [[C(@".foo.bar") stringByDeletingPathExtension] isEqual: @".foo"])
#undef EXPECTED

	TEST(@"-[decimalValue]",
	    [@"1234" decimalValue] == 1234 &&
	    [@"\r\n+123  " decimalValue] == 123 &&
	    [@"-500\t" decimalValue] == -500 &&
	    [@"\t\t\r\n" decimalValue] == 0)
	    [C(@"1234") decimalValue] == 1234 &&
	    [C(@"\r\n+123  ") decimalValue] == 123 &&
	    [C(@"-500\t") decimalValue] == -500 &&
	    [C(@"\t\t\r\n") decimalValue] == 0)

	TEST(@"-[hexadecimalValue]",
	    [@"123f" hexadecimalValue] == 0x123f &&
	    [@"\t\n0xABcd\r" hexadecimalValue] == 0xABCD &&
	    [@"  xbCDE" hexadecimalValue] == 0xBCDE &&
	    [@"$CdEf" hexadecimalValue] == 0xCDEF &&
	    [@"\rFeh " hexadecimalValue] == 0xFE &&
	    [@"\r\t" hexadecimalValue] == 0)
	    [C(@"123f") hexadecimalValue] == 0x123f &&
	    [C(@"\t\n0xABcd\r") hexadecimalValue] == 0xABCD &&
	    [C(@"  xbCDE") hexadecimalValue] == 0xBCDE &&
	    [C(@"$CdEf") hexadecimalValue] == 0xCDEF &&
	    [C(@"\rFeh ") hexadecimalValue] == 0xFE &&
	    [C(@"\r\t") hexadecimalValue] == 0)

	TEST(@"-[octalValue]",
	    [@"1234567" octalValue] == 01234567 &&
	    [@"\r\n123" octalValue] == 0123 &&
	    [@"765\t" octalValue] == 0765 &&
	    [@"\t\t\r\n" octalValue] == 0)
	    [C(@"1234567") octalValue] == 01234567 &&
	    [C(@"\r\n123") octalValue] == 0123 &&
	    [C(@"765\t") octalValue] == 0765 &&
	    [C(@"\t\t\r\n") octalValue] == 0)

	/*
	 * These test numbers can be generated without rounding if we have IEEE
	 * floating point numbers, thus we can use == on them.
	 */
	TEST(@"-[floatValue]",
	    [@"\t-0.25 " floatValue] == -0.25 &&
	    [@"\r-INFINITY\n" floatValue] == -INFINITY &&
	    isnan([@"   NAN\t\t" floatValue]))
	    [C(@"\t-0.25 ") floatValue] == -0.25 &&
	    [C(@"\r-INFINITY\n") floatValue] == -INFINITY &&
	    isnan([C(@"   NAN\t\t") floatValue]))

#if !defined(__ANDROID__) && !defined(OF_SOLARIS) && !defined(__DJGPP__)
# define INPUT @"\t-0x1.FFFFFFFFFFFFFP-1020 "
# define EXPECTED -0x1.FFFFFFFFFFFFFP-1020
#else
/* Android, Solaris and DJGPP do not accept 0x for strtod() */
# if !defined(OF_SOLARIS) || !defined(OF_X86)
#  define INPUT @"\t-0.123456789 "
#  define EXPECTED -0.123456789
# else
/* Solaris' strtod() has weird rounding on x86, but not on x86_64 */
#  define INPUT @"\t-0.125 "
#  define EXPECTED -0.125
# endif
#endif
	TEST(@"-[doubleValue]",
	    [INPUT doubleValue] == EXPECTED &&
	    [@"\r-INFINITY\n" doubleValue] == -INFINITY &&
	    isnan([@"   NAN\t\t" doubleValue]))
	    [C(@"\r-INFINITY\n") doubleValue] == -INFINITY &&
	    isnan([C(@"   NAN\t\t") doubleValue]))
#undef INPUT
#undef EXPECTED

	EXPECT_EXCEPTION(@"Detect invalid characters in -[decimalValue] #1",
	    OFInvalidFormatException, [@"abc" decimalValue])
	    OFInvalidFormatException, [C(@"abc") decimalValue])
	EXPECT_EXCEPTION(@"Detect invalid characters in -[decimalValue] #2",
	    OFInvalidFormatException, [@"0a" decimalValue])
	    OFInvalidFormatException, [C(@"0a") decimalValue])
	EXPECT_EXCEPTION(@"Detect invalid characters in -[decimalValue] #3",
	    OFInvalidFormatException, [@"0 1" decimalValue])
	    OFInvalidFormatException, [C(@"0 1") decimalValue])

	EXPECT_EXCEPTION(@"Detect invalid chars in -[hexadecimalValue] #1",
	    OFInvalidFormatException, [@"0xABCDEFG" hexadecimalValue])
	    OFInvalidFormatException, [C(@"0xABCDEFG") hexadecimalValue])
	EXPECT_EXCEPTION(@"Detect invalid chars in -[hexadecimalValue] #2",
	    OFInvalidFormatException, [@"0x" hexadecimalValue])
	    OFInvalidFormatException, [C(@"0x") hexadecimalValue])
	EXPECT_EXCEPTION(@"Detect invalid chars in -[hexadecimalValue] #3",
	    OFInvalidFormatException, [@"$" hexadecimalValue])
	    OFInvalidFormatException, [C(@"$") hexadecimalValue])
	EXPECT_EXCEPTION(@"Detect invalid chars in -[hexadecimalValue] #4",
	    OFInvalidFormatException, [@"$ " hexadecimalValue])
	    OFInvalidFormatException, [C(@"$ ") hexadecimalValue])

	EXPECT_EXCEPTION(@"Detect invalid chars in -[floatValue] #1",
	    OFInvalidFormatException, [@"0.0a" floatValue])
	    OFInvalidFormatException, [C(@"0.0a") floatValue])
	EXPECT_EXCEPTION(@"Detect invalid chars in -[floatValue] #2",
	    OFInvalidFormatException, [@"0 0" floatValue])
	    OFInvalidFormatException, [C(@"0 0") floatValue])
#ifdef HAVE_STRTOF_L
	/*
	 * Only do this if we have strtof_l, as the locale might allow the
	 * comma.
	 */
	EXPECT_EXCEPTION(@"Detect invalid chars in -[floatValue] #3",
	    OFInvalidFormatException, [@"0,0" floatValue])
	    OFInvalidFormatException, [C(@"0,0") floatValue])
#endif

	EXPECT_EXCEPTION(@"Detect invalid chars in -[doubleValue] #1",
	    OFInvalidFormatException, [@"0.0a" doubleValue])
	    OFInvalidFormatException, [C(@"0.0a") doubleValue])
	EXPECT_EXCEPTION(@"Detect invalid chars in -[doubleValue] #2",
	    OFInvalidFormatException, [@"0 0" doubleValue])
	    OFInvalidFormatException, [C(@"0 0") doubleValue])
#ifdef HAVE_STRTOD_L
	/*
	 * Only do this if we have strtod_l, as the locale might allow the
	 * comma.
	 */
	EXPECT_EXCEPTION(@"Detect invalid chars in -[doubleValue] #3",
	    OFInvalidFormatException, [@"0,0" doubleValue])
	    OFInvalidFormatException, [C(@"0,0") doubleValue])
#endif

	EXPECT_EXCEPTION(@"Detect out of range in -[decimalValue]",
	    OFOutOfRangeException,
	    [@"12345678901234567890123456789012345678901234567890"
	     @"12345678901234567890123456789012345678901234567890"
	    [C(@"12345678901234567890123456789012345678901234567890"
	       @"12345678901234567890123456789012345678901234567890")
	    decimalValue])

	EXPECT_EXCEPTION(@"Detect out of range in -[hexadecimalValue]",
	    OFOutOfRangeException,
	    [@"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF"
	     @"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF"
	    [C(@"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF"
	       @"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF")
	    hexadecimalValue])

	TEST(@"-[characters]", (ua = [@"fööbär🀺" characters]) &&
	TEST(@"-[characters]", (ua = [C(@"fööbär🀺") characters]) &&
	    !memcmp(ua, ucstr + 1, sizeof(ucstr) - 8))

#ifdef OF_BIG_ENDIAN
# define SWAPPED_BYTE_ORDER OF_BYTE_ORDER_LITTLE_ENDIAN
#else
# define SWAPPED_BYTE_ORDER OF_BYTE_ORDER_BIG_ENDIAN
#endif
	TEST(@"-[UTF16String]", (u16a = [@"fööbär🀺" UTF16String]) &&
	TEST(@"-[UTF16String]", (u16a = [C(@"fööbär🀺") UTF16String]) &&
	    !memcmp(u16a, utf16str + 1, of_string_utf16_length(utf16str) * 2) &&
	    (u16a = [@"fööbär🀺"
	    (u16a = [C(@"fööbär🀺")
	    UTF16StringWithByteOrder: SWAPPED_BYTE_ORDER]) &&
	    !memcmp(u16a, sutf16str + 1, of_string_utf16_length(sutf16str) * 2))

	TEST(@"-[UTF16StringLength]", [@"fööbär🀺" UTF16StringLength] == 8)
	TEST(@"-[UTF16StringLength]", [C(@"fööbär🀺") UTF16StringLength] == 8)

	TEST(@"-[UTF32String]", (ua = [@"fööbär🀺" UTF32String]) &&
	TEST(@"-[UTF32String]", (ua = [C(@"fööbär🀺") UTF32String]) &&
	    !memcmp(ua, ucstr + 1, of_string_utf32_length(ucstr) * 4) &&
	    (ua = [C(@"fööbär🀺") UTF32StringWithByteOrder:
	    (ua = [@"fööbär🀺" UTF32StringWithByteOrder: SWAPPED_BYTE_ORDER]) &&
	    SWAPPED_BYTE_ORDER]) &&
	    !memcmp(ua, sucstr + 1, of_string_utf32_length(sucstr) * 4))
#undef SWAPPED_BYTE_ORDER

	TEST(@"-[MD5Hash]", [[@"asdfoobar" MD5Hash]
	TEST(@"-[MD5Hash]", [[C(@"asdfoobar") MD5Hash]
	    isEqual: @"184dce2ec49b5422c7cfd8728864db4c"])

	TEST(@"-[RIPEMD160Hash]", [[@"asdfoobar" RIPEMD160Hash]
	TEST(@"-[RIPEMD160Hash]", [[C(@"asdfoobar") RIPEMD160Hash]
	    isEqual: @"021d773b0fac06eb6755ca6aa58a580c980f7f13"])

	TEST(@"-[SHA1Hash]", [[@"asdfoobar" SHA1Hash]
	TEST(@"-[SHA1Hash]", [[C(@"asdfoobar") SHA1Hash]
	    isEqual: @"f5f81ac0a8b5cbfdc4585ec1ad32e7b3a12b9b49"])

	TEST(@"-[SHA224Hash]", [[@"asdfoobar" SHA224Hash]
	TEST(@"-[SHA224Hash]", [[C(@"asdfoobar") SHA224Hash]
	    isEqual:
	    @"5a06822dcbd5a874f67d062b80b9d8a9cb9b5b303960b9da9290c192"])

	TEST(@"-[SHA256Hash]", [[@"asdfoobar" SHA256Hash] isEqual:
	TEST(@"-[SHA256Hash]", [[C(@"asdfoobar") SHA256Hash] isEqual:
	    @"28e65b1dcd7f6ce2ea6277b15f87b913"
	    @"628b5500bf7913a2bbf4cedcfa1215f6"])

	TEST(@"-[SHA384Hash]", [[@"asdfoobar" SHA384Hash] isEqual:
	TEST(@"-[SHA384Hash]", [[C(@"asdfoobar") SHA384Hash] isEqual:
	    @"73286da882ffddca2f45e005cfa6b44f3fc65bfb26db1d08"
	    @"7ded2f9c279e5addf8be854044bca0cece073fce28eec7d9"])

	TEST(@"-[SHA512Hash]", [[@"asdfoobar" SHA512Hash] isEqual:
	TEST(@"-[SHA512Hash]", [[C(@"asdfoobar") SHA512Hash] isEqual:
	    @"0464c427da158b02161bb44a3090bbfc594611ef6a53603640454b56412a9247c"
	    @"3579a329e53a5dc74676b106755e3394f9454a2d42273242615d32f80437d61"])

	TEST(@"-[stringByURLEncoding]",
	    [[C(@"foo\"ba'_~$") stringByURLEncoding]
	    [[@"foo\"ba'_~$" stringByURLEncoding] isEqual: @"foo%22ba%27_%7E$"])
	    isEqual: @"foo%22ba%27_%7E$"])

	TEST(@"-[stringByURLDecoding]",
	    [[C(@"foo%20bar%22+%24") stringByURLDecoding]
	    [[@"foo%20bar%22+%24" stringByURLDecoding] isEqual: @"foo bar\"+$"])
	    isEqual: @"foo bar\"+$"])

	TEST(@"-[insertString:atIndex:]",
	    (s[0] = [OFMutableString stringWithString: @"𝄞öööbä€"]) &&
	    (s[0] = [mutableStringClass stringWithString: @"𝄞öööbä€"]) &&
	    R([s[0] insertString: @"äöü"
			 atIndex: 3]) &&
	    [s[0] isEqual: @"𝄞ööäöüöbä€"])

	EXPECT_EXCEPTION(@"Detect invalid format in -[stringByURLDecoding] "
	    @"#1", OFInvalidFormatException, [@"foo%xbar" stringByURLDecoding])
	    @"#1", OFInvalidFormatException,
	    [C(@"foo%xbar") stringByURLDecoding])
	EXPECT_EXCEPTION(@"Detect invalid encoding in -[stringByURLDecoding] "
	    @"#2", OFInvalidEncodingException,
	    [@"foo%FFbar" stringByURLDecoding])
	    [C(@"foo%FFbar") stringByURLDecoding])

	TEST(@"-[setCharacter:atIndex:]",
	    (s[0] = [OFMutableString stringWithString: @"abäde"]) &&
	    (s[0] = [mutableStringClass stringWithString: @"abäde"]) &&
	    R([s[0] setCharacter: 0xF6
			 atIndex: 2]) &&
	    [s[0] isEqual: @"aböde"] &&
	    R([s[0] setCharacter: 'c'
			 atIndex: 2]) &&
	    [s[0] isEqual: @"abcde"] &&
	    R([s[0] setCharacter: 0x20AC
			 atIndex: 3]) &&
	    [s[0] isEqual: @"abc€e"] &&
	    R([s[0] setCharacter: 'x'
			 atIndex: 1]) &&
	    [s[0] isEqual: @"axc€e"])

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

	TEST(@"-[replaceCharactersInRange:withString:]",
	    (s[0] = [OFMutableString stringWithString: @"𝄞öööbä€"]) &&
	    (s[0] = [mutableStringClass stringWithString: @"𝄞öööbä€"]) &&
	    R([s[0] replaceCharactersInRange: of_range(1, 3)
				  withString: @"äöüß"]) &&
	    [s[0] isEqual: @"𝄞äöüßbä€"] &&
	    R([s[0] replaceCharactersInRange: of_range(4, 2)
				  withString: @"b"]) &&
	    [s[0] isEqual: @"𝄞äöübä€"] &&
	    R([s[0] replaceCharactersInRange: of_range(0, 7)
				  withString: @""]) &&
	    [s[0] isEqual: @""])

	EXPECT_EXCEPTION(@"Detect OoR in -[deleteCharactersInRange:] #1",
	    OFOutOfRangeException,
	    {
		s[0] = [OFMutableString stringWithString: @"𝄞öö"];
		s[0] = [mutableStringClass stringWithString: @"𝄞öö"];
		[s[0] deleteCharactersInRange: of_range(2, 2)];
	    })

	EXPECT_EXCEPTION(@"Detect OoR in -[deleteCharactersInRange:] #2",
	    OFOutOfRangeException,
	    [s[0] deleteCharactersInRange: of_range(4, 0)])

	EXPECT_EXCEPTION(@"Detect OoR in "
	    @"-[replaceCharactersInRange:withString:] #1",
	    OFOutOfRangeException,
	    [s[0] replaceCharactersInRange: of_range(2, 2)
				withString: @""])

	EXPECT_EXCEPTION(@"Detect OoR in "
	    @"-[replaceCharactersInRange:withString:] #2",
	    OFOutOfRangeException,
	    [s[0] replaceCharactersInRange: of_range(4, 0)
				withString: @""])

	TEST(@"-[replaceOccurrencesOfString:withString:]",
	    (s[0] = [OFMutableString stringWithString:
	    (s[0] = [mutableStringClass 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"]) &&
	    (s[0] = [mutableStringClass stringWithString: @"XX"]) &&
	    R([s[0] replaceOccurrencesOfString: @"X"
				    withString: @"XX"]) &&
	    [s[0] isEqual: @"XXXX"])

	TEST(@"-[replaceOccurrencesOfString:withString:options:range:]",
	    (s[0] = [OFMutableString stringWithString:
	    (s[0] = [mutableStringClass stringWithString:
	    @"foofoobarfoobarfoo"]) &&
	    R([s[0] replaceOccurrencesOfString: @"oo"
				    withString: @"óò"
				       options: 0
					 range: of_range(2, 15)]) &&
	    [s[0] isEqual: @"foofóòbarfóòbarfoo"])

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

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

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

	TEST(@"-[stringByXMLEscaping]",
	    (s[0] = (id)[@"<hello> &world'\"!&" stringByXMLEscaping]) &&
	    [s[0] isEqual: @"&lt;hello&gt; &amp;world&apos;&quot;!&amp;"])
	    (is = [C(@"<hello> &world'\"!&") stringByXMLEscaping]) &&
	    [is 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: @"€"] &&
	    [[@"&#x1D11E;" stringByXMLUnescaping] isEqual: @"𝄞"])
	    [[is stringByXMLUnescaping] isEqual: @"<hello> &world'\"!&"] &&
	    [[C(@"&#x79;") stringByXMLUnescaping] isEqual: @"y"] &&
	    [[C(@"&#xe4;") stringByXMLUnescaping] isEqual: @"ä"] &&
	    [[C(@"&#8364;") stringByXMLUnescaping] isEqual: @"€"] &&
	    [[C(@"&#x1D11E;") stringByXMLUnescaping] isEqual: @"𝄞"])

	EXPECT_EXCEPTION(@"Detect unknown entities in -[stringByXMLUnescaping]",
	    OFUnknownXMLEntityException, [@"&foo;" stringByXMLUnescaping])
	    OFUnknownXMLEntityException, [C(@"&foo;") stringByXMLUnescaping])
	EXPECT_EXCEPTION(@"Detect invalid entities in -[stringByXMLUnescaping] "
	    @"#1", OFInvalidFormatException, [@"x&amp" stringByXMLUnescaping])
	    @"#1", OFInvalidFormatException,
	    [C(@"x&amp") stringByXMLUnescaping])
	EXPECT_EXCEPTION(@"Detect invalid entities in -[stringByXMLUnescaping] "
	    @"#2", OFInvalidFormatException, [@"&#;" stringByXMLUnescaping])
	    @"#2", OFInvalidFormatException, [C(@"&#;") stringByXMLUnescaping])
	EXPECT_EXCEPTION(@"Detect invalid entities in -[stringByXMLUnescaping] "
	    @"#3", OFInvalidFormatException, [@"&#x;" stringByXMLUnescaping])
	    @"#3", OFInvalidFormatException, [C(@"&#x;") stringByXMLUnescaping])
	EXPECT_EXCEPTION(@"Detect invalid entities in -[stringByXMLUnescaping] "
	    @"#4", OFInvalidFormatException, [@"&#g;" stringByXMLUnescaping])
	    @"#4", OFInvalidFormatException, [C(@"&#g;") stringByXMLUnescaping])
	EXPECT_EXCEPTION(@"Detect invalid entities in -[stringByXMLUnescaping] "
	    @"#5", OFInvalidFormatException, [@"&#xg;" stringByXMLUnescaping])
	    @"#5", OFInvalidFormatException,
	    [C(@"&#xg;") stringByXMLUnescaping])

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

#ifdef OF_HAVE_BLOCKS
	TEST(@"-[stringByXMLUnescapingWithBlock:]",
	    [[@"x&foo;y" stringByXMLUnescapingWithBlock:
	    [[C(@"x&foo;y") stringByXMLUnescapingWithBlock:
	        ^ OFString* (OFString *str, OFString *entity) {
		    if ([entity isEqual: @"foo"])
			    return @"bar";

		    return nil;
	    }] isEqual: @"xbary"])

	ok = true;
	[@"foo\nbar\nbaz" enumerateLinesUsingBlock:
	[C(@"foo\nbar\nbaz") enumerateLinesUsingBlock:
	    ^ (OFString *line, bool *stop) {
		static int i = 0;

		switch (i) {
		case 0:
			if (![line isEqual: @"foo"])
				ok = false;
802
803
804
805
806
807
808


809
810
811






812
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835







+
+



+
+
+
+
+
+

			ok = false;
		}

		i++;
	}];
	TEST(@"-[enumerateLinesUsingBlock:]", ok)
#endif

#undef C

	[pool drain];
}

- (void)stringTests
{
	[self stringTestsWithClass: [OFString class]
		      mutableClass: [OFMutableString class]];
}
@end