@@ -453,16 +453,18 @@ private static KeyValuePair<int, string> Map(int codePage, string webName)
453
453
}
454
454
455
455
[ Fact ]
456
+ // Specific asserts which would fail on Unix are conditionally not run.
457
+ // [ActiveIssue(846, PlatformID.AnyUnix)]
456
458
public static void TestDefaultEncodings ( )
457
459
{
458
- // Check which encodings are available by default.
459
- foreach ( var mapping in CrossplatformDefaultEncodings ( ) )
460
+ ValidateDefaultEncodings ( ) ;
461
+
462
+ foreach ( object [ ] mapping in CodePageInfo ( ) )
460
463
{
461
- Encoding encoding = Encoding . GetEncoding ( mapping . Key ) ;
462
- Assert . NotNull ( encoding ) ;
463
- Assert . Equal ( mapping . Value , encoding . WebName ) ;
464
+ Assert . Throws < NotSupportedException > ( ( ) => Encoding . GetEncoding ( ( int ) mapping [ 0 ] ) ) ;
465
+ Assert . Throws < ArgumentException > ( ( ) => Encoding . GetEncoding ( ( string ) mapping [ 2 ] ) ) ;
464
466
}
465
- // Currently the class EncodingInfo isn't present in corefx, but this method should check for the exhaustive list
467
+ // Currently the class EncodingInfo isn't present in corefx, so this checks none of the code pages are present.
466
468
// When it is, comment out this line and remove the previous foreach/assert.
467
469
// Assert.Equal(CrossplatformDefaultEncodings, Encoding.GetEncodings().OrderBy(i => i.CodePage).Select(i => Map(i.CodePage, i.WebName)));
468
470
@@ -478,32 +480,42 @@ public static void TestDefaultEncodings()
478
480
// Make sure added code pages are identical between the provider and the Encoding class.
479
481
foreach ( object [ ] mapping in CodePageInfo ( ) )
480
482
{
481
- // Get encoding via query string.
482
- Encoding encoding = Encoding . GetEncoding ( ( string ) mapping [ 2 ] ) ;
483
- Encoding codePageEncoding = CodePagesEncodingProvider . Instance . GetEncoding ( ( string ) mapping [ 2 ] ) ;
483
+ Encoding encoding = Encoding . GetEncoding ( ( int ) mapping [ 0 ] ) ;
484
+ Encoding codePageEncoding = CodePagesEncodingProvider . Instance . GetEncoding ( ( int ) mapping [ 0 ] ) ;
484
485
Assert . Equal ( encoding , codePageEncoding ) ;
485
486
Assert . Equal ( encoding . CodePage , ( int ) mapping [ 0 ] ) ;
486
487
Assert . Equal ( encoding . WebName , ( string ) mapping [ 1 ] ) ;
488
+ // Get encoding via query string.
489
+ Assert . Equal ( Encoding . GetEncoding ( ( string ) mapping [ 2 ] ) , CodePagesEncodingProvider . Instance . GetEncoding ( ( string ) mapping [ 2 ] ) ) ;
487
490
}
488
-
489
491
// Adding the code page provider should keep the originals, too.
490
- foreach ( var mapping in CrossplatformDefaultEncodings ( ) )
491
- {
492
- Encoding encoding = Encoding . GetEncoding ( mapping . Key ) ;
493
- Assert . NotNull ( encoding ) ;
494
- Assert . Equal ( mapping . Value , encoding . WebName ) ;
495
- }
496
- // Currently the class EncodingInfo isn't present in corefx, but this method should check for the exhaustive list
492
+ ValidateDefaultEncodings ( ) ;
493
+ // Currently the class EncodingInfo isn't present in corefx, so this checks the complete list
497
494
// When it is, comment out this line and remove the previous foreach/assert.
498
495
// Assert.Equal(CrossplatformDefaultEncodings().Union(CodePageInfo().Select(i => Map((int)i[0], (string)i[1])).OrderBy(i => i.Key)),
499
496
// Encoding.GetEncodings().OrderBy(i => i.CodePage).Select(i => Map(i.CodePage, i.WebName)));
500
497
498
+ // Default encoding may have changed, should still be something on the combined list.
501
499
defaultEncoding = Encoding . GetEncoding ( 0 ) ;
502
500
Assert . NotNull ( defaultEncoding ) ;
503
501
mappedEncoding = Map ( defaultEncoding . CodePage , defaultEncoding . WebName ) ;
504
502
Assert . Contains ( mappedEncoding , CrossplatformDefaultEncodings ( ) . Union ( CodePageInfo ( ) . Select ( i => Map ( ( int ) i [ 0 ] , ( string ) i [ 1 ] ) ) ) ) ;
505
503
}
506
504
505
+ private static void ValidateDefaultEncodings ( )
506
+ {
507
+ foreach ( var mapping in CrossplatformDefaultEncodings ( ) )
508
+ {
509
+ Encoding encoding = Encoding . GetEncoding ( mapping . Key ) ;
510
+ Assert . NotNull ( encoding ) ;
511
+ Assert . Equal ( encoding , Encoding . GetEncoding ( mapping . Value ) ) ;
512
+ #if ! PLATFORM_UNIX
513
+ // Currently Unix seems to only have UTF-8 as a default...
514
+ Assert . Equal ( mapping . Value , encoding . WebName ) ;
515
+ #endif
516
+ }
517
+ }
518
+
507
519
[ Theory ]
508
520
[ MemberData ( "SpecificCodepageEncodings" ) ]
509
521
public static void TestRoundtrippingSpecificCodepageEncoding ( string encodingName , byte [ ] bytes , string expected )
0 commit comments