@@ -597,6 +597,39 @@ class TestCodable : TestCodableSuper {
597
597
}
598
598
}
599
599
600
+ // MARK: - Optional
601
+ func test_Optional_enum_JSON( ) {
602
+ enum A : Codable , Equatable {
603
+ case a( Int ? )
604
+ }
605
+
606
+ enum B : Codable , Equatable {
607
+ case b( Int ? = nil )
608
+ }
609
+
610
+ enum C : Codable , Equatable {
611
+ case c( x: Int ? )
612
+ }
613
+
614
+ enum D : Codable , Equatable {
615
+ case d( x: Int ? = nil )
616
+ }
617
+
618
+ expectRoundTripEqualityThroughJSON ( for: A . a ( 1 ) , lineNumber: #line)
619
+ expectRoundTripEqualityThroughJSON ( for: A . a ( nil ) , lineNumber: #line)
620
+
621
+ expectRoundTripEqualityThroughJSON ( for: B . b ( 2 ) , lineNumber: #line)
622
+ expectRoundTripEqualityThroughJSON ( for: B . b ( nil ) , lineNumber: #line)
623
+ expectRoundTripEqualityThroughJSON ( for: B . b ( ) , lineNumber: #line)
624
+
625
+ expectRoundTripEqualityThroughJSON ( for: C . c ( x: 3 ) , lineNumber: #line)
626
+ expectRoundTripEqualityThroughJSON ( for: C . c ( x: nil ) , lineNumber: #line)
627
+
628
+ expectRoundTripEqualityThroughJSON ( for: D . d ( x: 4 ) , lineNumber: #line)
629
+ expectRoundTripEqualityThroughJSON ( for: D . d ( x: nil ) , lineNumber: #line)
630
+ expectRoundTripEqualityThroughJSON ( for: D . d ( ) , lineNumber: #line)
631
+ }
632
+
600
633
// MARK: - PartialRangeFrom
601
634
func test_PartialRangeFrom_JSON( ) {
602
635
let value = 0 ...
@@ -899,6 +932,7 @@ var tests = [
899
932
" test_Locale_Plist " : TestCodable . test_Locale_Plist,
900
933
" test_NSRange_JSON " : TestCodable . test_NSRange_JSON,
901
934
" test_NSRange_Plist " : TestCodable . test_NSRange_Plist,
935
+ " test_Optional_enum_JSON " : TestCodable . test_Optional_enum_JSON,
902
936
" test_PartialRangeFrom_JSON " : TestCodable . test_PartialRangeFrom_JSON,
903
937
" test_PartialRangeFrom_Plist " : TestCodable . test_PartialRangeFrom_Plist,
904
938
" test_PartialRangeThrough_JSON " : TestCodable . test_PartialRangeThrough_JSON,
0 commit comments