@@ -304,6 +304,23 @@ func checkDecodeUTF<Codec : UnicodeCodec & UnicodeEncoding>(
304
304
}
305
305
check ( expected. reversed ( ) , " reverse, repairing: true " )
306
306
307
+ //===--- Transcoded Scalars ---------------------------------------------===//
308
+ for x in decoded. lazy. map ( { UnicodeScalar ( $0) ! } ) {
309
+ expectEqualSequence (
310
+ UTF8 . encode ( x) !,
311
+ UTF8 . transcode ( Codec . encode ( x) !, from: Codec . self) !
312
+ )
313
+ expectEqualSequence (
314
+ UTF16 . encode ( x) !,
315
+ UTF16 . transcode ( Codec . encode ( x) !, from: Codec . self) !
316
+ )
317
+ expectEqualSequence (
318
+ UTF32 . encode ( x) !,
319
+ UTF32 . transcode ( Codec . encode ( x) !, from: Codec . self) !
320
+ )
321
+ }
322
+
323
+ //===--- Scalar View ----------------------------------------------------===//
307
324
let scalars = _Unicode. DefaultScalarView ( utfStr, fromEncoding: Codec . self)
308
325
expectEqualSequence ( expected, scalars. map { $0. value } )
309
326
expectEqualSequence (
@@ -319,6 +336,7 @@ func checkDecodeUTF<Codec : UnicodeCodec & UnicodeEncoding>(
319
336
}
320
337
expectNil ( x. next ( ) )
321
338
}
339
+
322
340
return result
323
341
}
324
342
@@ -337,15 +355,13 @@ func checkDecodeUTF16(
337
355
utf16Str)
338
356
}
339
357
340
- /*
341
358
func checkDecodeUTF32(
342
359
_ expectedHead: [ UInt32 ] ,
343
360
_ expectedRepairedTail: [ UInt32 ] , _ utf32Str: [ UInt32 ]
344
361
) -> AssertionResult {
345
362
return checkDecodeUTF ( UTF32 . self, expectedHead, expectedRepairedTail,
346
363
utf32Str)
347
364
}
348
- */
349
365
350
366
func checkEncodeUTF8( _ expected: [ UInt8 ] ,
351
367
_ scalars: [ UInt32 ] ) -> AssertionResult {
@@ -369,6 +385,147 @@ func checkEncodeUTF8(_ expected: [UInt8],
369
385
return assertionSuccess ( )
370
386
}
371
387
388
+ //===----------------------------------------------------------------------===//
389
+
390
+ var UTF32Decoder = TestSuite ( " UTF32Decoder " )
391
+
392
+ UTF32Decoder . test ( " Empty " ) {
393
+ expectTrue ( checkDecodeUTF32 ( [ ] , [ ] , [ ] ) )
394
+ }
395
+
396
+ UTF32Decoder . test ( " SmokeTest " ) {
397
+ // U+0041 LATIN CAPITAL LETTER A
398
+ expectTrue ( checkDecodeUTF32 ( [ 0x0041 ] , [ ] , [ 0x0000_0041 ] ) )
399
+
400
+ // U+0041 LATIN CAPITAL LETTER A
401
+ // U+0042 LATIN CAPITAL LETTER B
402
+ expectTrue ( checkDecodeUTF32 (
403
+ [ 0x0041 , 0x0042 ] , [ ] ,
404
+ [ 0x0000_0041 , 0x0000_0042 ] ) )
405
+
406
+ // U+0000 NULL
407
+ // U+0041 LATIN CAPITAL LETTER A
408
+ // U+0042 LATIN CAPITAL LETTER B
409
+ // U+0000 NULL
410
+ expectTrue ( checkDecodeUTF32 (
411
+ [ 0x0000 , 0x0041 , 0x0042 , 0x0000 ] , [ ] ,
412
+ [ 0x0000_0000 , 0x0000_0041 , 0x0000_0042 , 0x0000_0000 ] ) )
413
+
414
+ // U+0283 LATIN SMALL LETTER ESH
415
+ expectTrue ( checkDecodeUTF32 ( [ 0x0283 ] , [ ] , [ 0x0000_0283 ] ) )
416
+
417
+ // U+03BA GREEK SMALL LETTER KAPPA
418
+ // U+1F79 GREEK SMALL LETTER OMICRON WITH OXIA
419
+ // U+03C3 GREEK SMALL LETTER SIGMA
420
+ // U+03BC GREEK SMALL LETTER MU
421
+ // U+03B5 GREEK SMALL LETTER EPSILON
422
+ expectTrue ( checkDecodeUTF32 (
423
+ [ 0x03ba , 0x1f79 , 0x03c3 , 0x03bc , 0x03b5 ] , [ ] ,
424
+ [ 0x0000_03ba , 0x0000_1f79 , 0x0000_03c3 , 0x0000_03bc , 0x0000_03b5 ] ) )
425
+
426
+ // U+4F8B CJK UNIFIED IDEOGRAPH-4F8B
427
+ // U+6587 CJK UNIFIED IDEOGRAPH-6587
428
+ expectTrue ( checkDecodeUTF32 (
429
+ [ 0x4f8b , 0x6587 ] , [ ] ,
430
+ [ 0x0000_4f8b , 0x0000_6587 ] ) )
431
+
432
+ // U+D55C HANGUL SYLLABLE HAN
433
+ // U+AE00 HANGUL SYLLABLE GEUL
434
+ expectTrue ( checkDecodeUTF32 (
435
+ [ 0xd55c , 0xae00 ] , [ ] ,
436
+ [ 0x0000_d55c , 0x0000_ae00 ] ) )
437
+
438
+ // U+1112 HANGUL CHOSEONG HIEUH
439
+ // U+1161 HANGUL JUNGSEONG A
440
+ // U+11AB HANGUL JONGSEONG NIEUN
441
+ // U+1100 HANGUL CHOSEONG KIYEOK
442
+ // U+1173 HANGUL JUNGSEONG EU
443
+ // U+11AF HANGUL JONGSEONG RIEUL
444
+ expectTrue ( checkDecodeUTF32 (
445
+ [ 0x1112 , 0x1161 , 0x11ab , 0x1100 , 0x1173 , 0x11af ] , [ ] ,
446
+ [ 0x0000_1112 , 0x0000_1161 , 0x0000_11ab , 0x0000_1100 , 0x0000_1173 ,
447
+ 0x0000_11af ] ) )
448
+
449
+ // U+D7FF (unassigned)
450
+ expectTrue ( checkDecodeUTF16 ( [ 0xd7ff ] , [ ] , [ 0x0000_d7ff ] ) )
451
+
452
+ // U+E000 (private use)
453
+ expectTrue ( checkDecodeUTF16 ( [ 0xe000 ] , [ ] , [ 0x0000_e000 ] ) )
454
+
455
+ // U+FFFD REPLACEMENT CHARACTER
456
+ expectTrue ( checkDecodeUTF16 ( [ 0xfffd ] , [ ] , [ 0x0000_fffd ] ) )
457
+
458
+ // U+FFFF (noncharacter)
459
+ expectTrue ( checkDecodeUTF16 ( [ 0xffff ] , [ ] , [ 0x0000_ffff ] ) )
460
+
461
+ // U+10000 LINEAR B SYLLABLE B008 A
462
+ expectTrue ( checkDecodeUTF32 ( [ 0x00010000 ] , [ ] , [ 0x0001_0000 ] ) )
463
+
464
+ // U+10100 AEGEAN WORD SEPARATOR LINE
465
+ expectTrue ( checkDecodeUTF32 ( [ 0x00010100 ] , [ ] , [ 0x0001_0100 ] ) )
466
+
467
+ // U+103FF (unassigned)
468
+ expectTrue ( checkDecodeUTF32 ( [ 0x000103ff ] , [ ] , [ 0x0001_03ff ] ) )
469
+
470
+ // U+1D800 (unassigned)
471
+ expectTrue ( checkDecodeUTF32 ( [ 0x0001d800 ] , [ ] , [ 0x0001_d800 ] ) )
472
+
473
+
474
+ // U+E0000 (unassigned)
475
+ expectTrue ( checkDecodeUTF32 ( [ 0x000e0000 ] , [ ] , [ 0x000e_0000 ] ) )
476
+
477
+ // U+E0100 VARIATION SELECTOR-17
478
+ expectTrue ( checkDecodeUTF32 ( [ 0x000e0100 ] , [ ] , [ 0x000e_0100 ] ) )
479
+
480
+ // U+E03FF (unassigned)
481
+ expectTrue ( checkDecodeUTF32 ( [ 0x000e03ff ] , [ ] , [ 0x000e_03ff ] ) )
482
+
483
+
484
+ // U+10FC00 (private use)
485
+ expectTrue ( checkDecodeUTF32 ( [ 0x0010fc00 ] , [ ] , [ 0x0010_fc00 ] ) )
486
+
487
+ // U+10FD00 (private use)
488
+ expectTrue ( checkDecodeUTF32 ( [ 0x0010fd00 ] , [ ] , [ 0x0010_fd00 ] ) )
489
+
490
+ // U+10FFFF (private use, noncharacter)
491
+ expectTrue ( checkDecodeUTF32 ( [ 0x0010ffff ] , [ ] , [ 0x0010_ffff ] ) )
492
+ }
493
+
494
+ UTF32Decoder . test ( " IllFormed " ) {
495
+ // U+D800 (high-surrogate)
496
+ expectTrue ( checkDecodeUTF32 ( [ ] , [ 0xfffd ] , [ 0x0000_d800 ] ) )
497
+
498
+ // U+DB40 (high-surrogate)
499
+ expectTrue ( checkDecodeUTF32 ( [ ] , [ 0xfffd ] , [ 0x0000_db40 ] ) )
500
+
501
+ // U+DBFF (high-surrogate)
502
+ expectTrue ( checkDecodeUTF32 ( [ ] , [ 0xfffd ] , [ 0x0000_dbff ] ) )
503
+
504
+ // U+DC00 (low-surrogate)
505
+ expectTrue ( checkDecodeUTF32 ( [ ] , [ 0xfffd ] , [ 0x0000_dc00 ] ) )
506
+
507
+ // U+DD00 (low-surrogate)
508
+ expectTrue ( checkDecodeUTF32 ( [ ] , [ 0xfffd ] , [ 0x0000_dd00 ] ) )
509
+
510
+ // U+DFFF (low-surrogate)
511
+ expectTrue ( checkDecodeUTF32 ( [ ] , [ 0xfffd ] , [ 0x0000_dfff ] ) )
512
+
513
+ // U+110000 (invalid)
514
+ expectTrue ( checkDecodeUTF32 ( [ ] , [ 0xfffd ] , [ 0x0011_0000 ] ) )
515
+
516
+ // U+1000000 (invalid)
517
+ expectTrue ( checkDecodeUTF32 ( [ ] , [ 0xfffd ] , [ 0x0100_0000 ] ) )
518
+
519
+ // U+80000000 (invalid)
520
+ expectTrue ( checkDecodeUTF32 ( [ ] , [ 0xfffd ] , [ 0x8000_0000 ] ) )
521
+
522
+ // U+FFFF0000 (invalid)
523
+ expectTrue ( checkDecodeUTF32 ( [ ] , [ 0xfffd ] , [ 0xffff_0000 ] ) )
524
+
525
+ // U+FFFFFFFF (invalid)
526
+ expectTrue ( checkDecodeUTF32 ( [ ] , [ 0xfffd ] , [ 0xffff_ffff ] ) )
527
+ }
528
+
372
529
var UTF8Decoder = TestSuite ( " UTF8Decoder " )
373
530
374
531
//===----------------------------------------------------------------------===//
0 commit comments