@@ -1055,6 +1055,36 @@ data1 = <7465
1055
1055
XCTAssertEqual ( d. timeIntervalSinceReferenceDate, - 63145612800 )
1056
1056
}
1057
1057
1058
+ func test_realEncodeRemoveZeroSuffix( ) throws {
1059
+ // Tests that we encode "whole-value reals" (such as `2.0`, `-5.0`, etc)
1060
+ // **without** the `.0` for backwards compactability
1061
+ let encoder = PropertyListEncoder ( )
1062
+ encoder. outputFormat = . xml
1063
+ let template = " \( _XMLPlistEncodingFormat. Writer. header) <array> \n \t <real><%EXPECTED%></real> \n </array> \n </plist> \n "
1064
+
1065
+ let wholeFloat : Float = 2.0
1066
+ var data = try encoder. encode ( [ wholeFloat] )
1067
+ var str = try XCTUnwrap ( String ( data: data, encoding: String . Encoding. utf8) )
1068
+ var expected = template. replacingOccurrences (
1069
+ of: " <%EXPECTED%> " , with: " 2 " )
1070
+ XCTAssertEqual ( str, expected)
1071
+
1072
+ let wholeDouble : Double = - 5.0
1073
+ data = try encoder. encode ( [ wholeDouble] )
1074
+ str = try XCTUnwrap ( String ( data: data, encoding: String . Encoding. utf8) )
1075
+ expected = template. replacingOccurrences (
1076
+ of: " <%EXPECTED%> " , with: " -5 " )
1077
+ XCTAssertEqual ( str, expected)
1078
+
1079
+ // Make sure other reals are not affacted
1080
+ let notWholeDouble = 0.5
1081
+ data = try encoder. encode ( [ notWholeDouble] )
1082
+ str = try XCTUnwrap ( String ( data: data, encoding: String . Encoding. utf8) )
1083
+ expected = template. replacingOccurrences (
1084
+ of: " <%EXPECTED%> " , with: " 0.5 " )
1085
+ XCTAssertEqual ( str, expected)
1086
+ }
1087
+
1058
1088
func test_farFutureDates( ) throws {
1059
1089
let date = Date ( timeIntervalSince1970: 999999999999.0 )
1060
1090
0 commit comments