From 6b8b050a9b88f6132315d14052379c7ace32625c Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Sat, 5 Oct 2019 20:51:48 +0100 Subject: [PATCH] Fix Float32 decoding, add DoubleBox --- .../XMLCoder/Auxiliaries/Box/BoolBox.swift | 2 +- Sources/XMLCoder/Auxiliaries/Box/Box.swift | 2 +- .../XMLCoder/Auxiliaries/Box/ChoiceBox.swift | 2 +- .../XMLCoder/Auxiliaries/Box/DataBox.swift | 2 +- .../XMLCoder/Auxiliaries/Box/DateBox.swift | 2 +- .../XMLCoder/Auxiliaries/Box/DecimalBox.swift | 2 +- .../XMLCoder/Auxiliaries/Box/DoubleBox.swift | 48 +++++++++++++++++++ .../XMLCoder/Auxiliaries/Box/FloatBox.swift | 10 ++-- Sources/XMLCoder/Auxiliaries/Box/IntBox.swift | 2 +- .../XMLCoder/Auxiliaries/Box/KeyedBox.swift | 2 +- .../XMLCoder/Auxiliaries/Box/NullBox.swift | 2 +- .../XMLCoder/Auxiliaries/Box/SharedBox.swift | 4 +- .../Auxiliaries/Box/SingleKeyedBox.swift | 2 +- .../XMLCoder/Auxiliaries/Box/StringBox.swift | 2 +- .../XMLCoder/Auxiliaries/Box/UIntBox.swift | 2 +- Sources/XMLCoder/Auxiliaries/Box/URLBox.swift | 2 +- .../XMLCoder/Auxiliaries/Box/UnkeyedBox.swift | 2 +- .../XMLCoder/Auxiliaries/Box/ValueBox.swift | 12 +++++ .../Auxiliaries/XMLCoderElement.swift | 4 +- .../Decoder/DecodingErrorExtension.swift | 2 + .../SingleValueDecodingContainer.swift | 6 ++- .../Decoder/XMLDecoderImplementation.swift | 22 +++++---- .../Encoder/XMLEncoderImplementation.swift | 23 +++++++-- Tests/XMLCoderTests/Box/BoolBoxTests.swift | 2 +- Tests/XMLCoderTests/Box/DataBoxTests.swift | 2 +- Tests/XMLCoderTests/Box/DateBoxTests.swift | 8 ++-- Tests/XMLCoderTests/Box/DecimalBoxTests.swift | 2 +- Tests/XMLCoderTests/Box/FloatBoxTests.swift | 4 +- Tests/XMLCoderTests/Box/IntBoxTests.swift | 2 +- Tests/XMLCoderTests/Box/KeyedBoxTests.swift | 2 +- Tests/XMLCoderTests/Box/NullBoxTests.swift | 2 +- Tests/XMLCoderTests/Box/SharedBoxTests.swift | 8 ++-- Tests/XMLCoderTests/Box/StringBoxTests.swift | 2 +- Tests/XMLCoderTests/Box/UIntBoxTests.swift | 2 +- Tests/XMLCoderTests/Box/URLBoxTests.swift | 2 +- Tests/XMLCoderTests/Box/UnkeyedBoxTests.swift | 2 +- Tests/XMLCoderTests/Minimal/FloatTests.swift | 2 + XMLCoder.xcodeproj/project.pbxproj | 10 +++- 38 files changed, 150 insertions(+), 61 deletions(-) create mode 100644 Sources/XMLCoder/Auxiliaries/Box/DoubleBox.swift create mode 100644 Sources/XMLCoder/Auxiliaries/Box/ValueBox.swift diff --git a/Sources/XMLCoder/Auxiliaries/Box/BoolBox.swift b/Sources/XMLCoder/Auxiliaries/Box/BoolBox.swift index c359d529..306cdbb0 100644 --- a/Sources/XMLCoder/Auxiliaries/Box/BoolBox.swift +++ b/Sources/XMLCoder/Auxiliaries/Box/BoolBox.swift @@ -38,7 +38,7 @@ extension BoolBox: Box { /// --- /// /// [Schema definition](https://www.w3.org/TR/xmlschema-2/#boolean) - func xmlString() -> String? { + var xmlString: String? { return (unboxed) ? "true" : "false" } } diff --git a/Sources/XMLCoder/Auxiliaries/Box/Box.swift b/Sources/XMLCoder/Auxiliaries/Box/Box.swift index 1ebb0374..4a396c05 100644 --- a/Sources/XMLCoder/Auxiliaries/Box/Box.swift +++ b/Sources/XMLCoder/Auxiliaries/Box/Box.swift @@ -7,7 +7,7 @@ protocol Box { var isNull: Bool { get } - func xmlString() -> String? + var xmlString: String? { get } } /// A box that only describes a single atomic value. diff --git a/Sources/XMLCoder/Auxiliaries/Box/ChoiceBox.swift b/Sources/XMLCoder/Auxiliaries/Box/ChoiceBox.swift index ad2b6835..b797edcf 100644 --- a/Sources/XMLCoder/Auxiliaries/Box/ChoiceBox.swift +++ b/Sources/XMLCoder/Auxiliaries/Box/ChoiceBox.swift @@ -16,7 +16,7 @@ extension ChoiceBox: Box { return false } - func xmlString() -> String? { + var xmlString: String? { return nil } } diff --git a/Sources/XMLCoder/Auxiliaries/Box/DataBox.swift b/Sources/XMLCoder/Auxiliaries/Box/DataBox.swift index 6896121b..f0a9158f 100644 --- a/Sources/XMLCoder/Auxiliaries/Box/DataBox.swift +++ b/Sources/XMLCoder/Auxiliaries/Box/DataBox.swift @@ -42,7 +42,7 @@ extension DataBox: Box { return false } - func xmlString() -> String? { + var xmlString: String? { return xmlString(format: format) } } diff --git a/Sources/XMLCoder/Auxiliaries/Box/DateBox.swift b/Sources/XMLCoder/Auxiliaries/Box/DateBox.swift index 1f49c441..d4a1c819 100644 --- a/Sources/XMLCoder/Auxiliaries/Box/DateBox.swift +++ b/Sources/XMLCoder/Auxiliaries/Box/DateBox.swift @@ -84,7 +84,7 @@ extension DateBox: Box { return false } - func xmlString() -> String? { + var xmlString: String? { return xmlString(format: format) } } diff --git a/Sources/XMLCoder/Auxiliaries/Box/DecimalBox.swift b/Sources/XMLCoder/Auxiliaries/Box/DecimalBox.swift index ea9d85c9..ae002419 100644 --- a/Sources/XMLCoder/Auxiliaries/Box/DecimalBox.swift +++ b/Sources/XMLCoder/Auxiliaries/Box/DecimalBox.swift @@ -47,7 +47,7 @@ extension DecimalBox: Box { /// --- /// /// [Schema definition](https://www.w3.org/TR/xmlschema-2/#decimal) - func xmlString() -> String? { + var xmlString: String? { return "\(unboxed)" } } diff --git a/Sources/XMLCoder/Auxiliaries/Box/DoubleBox.swift b/Sources/XMLCoder/Auxiliaries/Box/DoubleBox.swift new file mode 100644 index 00000000..d1286863 --- /dev/null +++ b/Sources/XMLCoder/Auxiliaries/Box/DoubleBox.swift @@ -0,0 +1,48 @@ +// +// DoubleBox.swift +// XMLCoder +// +// Created by Max Desiatov on 05/10/2019. +// + +struct DoubleBox: Equatable, ValueBox { + typealias Unboxed = Double + + let unboxed: Unboxed + + init(_ value: Unboxed) { + unboxed = value + } + + init?(xmlString: String) { + guard let unboxed = Double(xmlString) else { return nil } + + self.init(unboxed) + } +} + +extension DoubleBox: Box { + var isNull: Bool { + return false + } + + var xmlString: String? { + guard !unboxed.isNaN else { + return "NaN" + } + + guard !unboxed.isInfinite else { + return (unboxed > 0.0) ? "INF" : "-INF" + } + + return unboxed.description + } +} + +extension DoubleBox: SimpleBox {} + +extension DoubleBox: CustomStringConvertible { + var description: String { + return unboxed.description + } +} diff --git a/Sources/XMLCoder/Auxiliaries/Box/FloatBox.swift b/Sources/XMLCoder/Auxiliaries/Box/FloatBox.swift index 600a6c97..4d4d6faf 100644 --- a/Sources/XMLCoder/Auxiliaries/Box/FloatBox.swift +++ b/Sources/XMLCoder/Auxiliaries/Box/FloatBox.swift @@ -5,8 +5,8 @@ // Created by Vincent Esche on 12/17/18. // -struct FloatBox: Equatable { - typealias Unboxed = Float64 +struct FloatBox: Equatable, ValueBox { + typealias Unboxed = Float let unboxed: Unboxed @@ -20,10 +20,6 @@ struct FloatBox: Equatable { } self.init(unboxed) } - - func unbox() -> Float? { - return Float(exactly: unboxed) - } } extension FloatBox: Box { @@ -59,7 +55,7 @@ extension FloatBox: Box { /// --- /// /// [Schema definition](https://www.w3.org/TR/xmlschema-2/#float) - func xmlString() -> String? { + var xmlString: String? { guard !unboxed.isNaN else { return "NaN" } diff --git a/Sources/XMLCoder/Auxiliaries/Box/IntBox.swift b/Sources/XMLCoder/Auxiliaries/Box/IntBox.swift index 34c8a978..6af0c918 100644 --- a/Sources/XMLCoder/Auxiliaries/Box/IntBox.swift +++ b/Sources/XMLCoder/Auxiliaries/Box/IntBox.swift @@ -44,7 +44,7 @@ extension IntBox: Box { /// --- /// /// [Schema definition](https://www.w3.org/TR/xmlschema-2/#integer) - func xmlString() -> String? { + var xmlString: String? { return unboxed.description } } diff --git a/Sources/XMLCoder/Auxiliaries/Box/KeyedBox.swift b/Sources/XMLCoder/Auxiliaries/Box/KeyedBox.swift index b66094eb..0c2f692d 100644 --- a/Sources/XMLCoder/Auxiliaries/Box/KeyedBox.swift +++ b/Sources/XMLCoder/Auxiliaries/Box/KeyedBox.swift @@ -43,7 +43,7 @@ extension KeyedBox: Box { return false } - func xmlString() -> String? { + var xmlString: String? { return nil } } diff --git a/Sources/XMLCoder/Auxiliaries/Box/NullBox.swift b/Sources/XMLCoder/Auxiliaries/Box/NullBox.swift index ecec12ca..a401828c 100644 --- a/Sources/XMLCoder/Auxiliaries/Box/NullBox.swift +++ b/Sources/XMLCoder/Auxiliaries/Box/NullBox.swift @@ -12,7 +12,7 @@ extension NullBox: Box { return true } - func xmlString() -> String? { + var xmlString: String? { return nil } } diff --git a/Sources/XMLCoder/Auxiliaries/Box/SharedBox.swift b/Sources/XMLCoder/Auxiliaries/Box/SharedBox.swift index 7cb2d61d..18b9b3f0 100644 --- a/Sources/XMLCoder/Auxiliaries/Box/SharedBox.swift +++ b/Sources/XMLCoder/Auxiliaries/Box/SharedBox.swift @@ -22,8 +22,8 @@ extension SharedBox: Box { return unboxed.isNull } - func xmlString() -> String? { - return unboxed.xmlString() + var xmlString: String? { + return unboxed.xmlString } } diff --git a/Sources/XMLCoder/Auxiliaries/Box/SingleKeyedBox.swift b/Sources/XMLCoder/Auxiliaries/Box/SingleKeyedBox.swift index 42f0cbb5..589d42f6 100644 --- a/Sources/XMLCoder/Auxiliaries/Box/SingleKeyedBox.swift +++ b/Sources/XMLCoder/Auxiliaries/Box/SingleKeyedBox.swift @@ -18,7 +18,7 @@ extension SingleKeyedBox: Box { return false } - func xmlString() -> String? { + var xmlString: String? { return nil } } diff --git a/Sources/XMLCoder/Auxiliaries/Box/StringBox.swift b/Sources/XMLCoder/Auxiliaries/Box/StringBox.swift index dcc14f6d..0aacca14 100644 --- a/Sources/XMLCoder/Auxiliaries/Box/StringBox.swift +++ b/Sources/XMLCoder/Auxiliaries/Box/StringBox.swift @@ -24,7 +24,7 @@ extension StringBox: Box { return false } - func xmlString() -> String? { + var xmlString: String? { return unboxed.description } } diff --git a/Sources/XMLCoder/Auxiliaries/Box/UIntBox.swift b/Sources/XMLCoder/Auxiliaries/Box/UIntBox.swift index c9e08ee5..092dbb67 100644 --- a/Sources/XMLCoder/Auxiliaries/Box/UIntBox.swift +++ b/Sources/XMLCoder/Auxiliaries/Box/UIntBox.swift @@ -47,7 +47,7 @@ extension UIntBox: Box { /// --- /// /// [Schema definition](https://www.w3.org/TR/xmlschema-2/#nonNegativeInteger) - func xmlString() -> String? { + var xmlString: String? { return unboxed.description } } diff --git a/Sources/XMLCoder/Auxiliaries/Box/URLBox.swift b/Sources/XMLCoder/Auxiliaries/Box/URLBox.swift index d8e2c3de..26fbabf9 100644 --- a/Sources/XMLCoder/Auxiliaries/Box/URLBox.swift +++ b/Sources/XMLCoder/Auxiliaries/Box/URLBox.swift @@ -29,7 +29,7 @@ extension URLBox: Box { return false } - func xmlString() -> String? { + var xmlString: String? { return unboxed.absoluteString } } diff --git a/Sources/XMLCoder/Auxiliaries/Box/UnkeyedBox.swift b/Sources/XMLCoder/Auxiliaries/Box/UnkeyedBox.swift index 82b79d76..2ca8cd97 100644 --- a/Sources/XMLCoder/Auxiliaries/Box/UnkeyedBox.swift +++ b/Sources/XMLCoder/Auxiliaries/Box/UnkeyedBox.swift @@ -12,7 +12,7 @@ extension Array: Box { return false } - func xmlString() -> String? { + var xmlString: String? { return nil } } diff --git a/Sources/XMLCoder/Auxiliaries/Box/ValueBox.swift b/Sources/XMLCoder/Auxiliaries/Box/ValueBox.swift new file mode 100644 index 00000000..3920ff58 --- /dev/null +++ b/Sources/XMLCoder/Auxiliaries/Box/ValueBox.swift @@ -0,0 +1,12 @@ +// +// File.swift +// XMLCoder +// +// Created by Max Desiatov on 05/10/2019. +// + +protocol ValueBox: SimpleBox { + associatedtype Unboxed + + init(_ value: Unboxed) +} diff --git a/Sources/XMLCoder/Auxiliaries/XMLCoderElement.swift b/Sources/XMLCoder/Auxiliaries/XMLCoderElement.swift index 25f862f7..77b45a5b 100644 --- a/Sources/XMLCoder/Auxiliaries/XMLCoderElement.swift +++ b/Sources/XMLCoder/Auxiliaries/XMLCoderElement.swift @@ -288,7 +288,7 @@ extension XMLCoderElement { } let attributes: [Attribute] = box.attributes.compactMap { key, box in - guard let value = box.xmlString() else { + guard let value = box.xmlString else { return nil } return Attribute(key: key, value: value) @@ -299,7 +299,7 @@ extension XMLCoderElement { init(key: String, box: SimpleBox) { self.init(key: key) - value = box.xmlString() + value = box.xmlString } init(key: String, box: Box) { diff --git a/Sources/XMLCoder/Decoder/DecodingErrorExtension.swift b/Sources/XMLCoder/Decoder/DecodingErrorExtension.swift index 61025d45..2c110661 100644 --- a/Sources/XMLCoder/Decoder/DecodingErrorExtension.swift +++ b/Sources/XMLCoder/Decoder/DecodingErrorExtension.swift @@ -43,6 +43,8 @@ extension DecodingError { return "an unsigned integer value" case is FloatBox: return "a floating-point value" + case is DoubleBox: + return "a double floating-point value" case is UnkeyedBox: return "a array value" case is KeyedBox: diff --git a/Sources/XMLCoder/Decoder/SingleValueDecodingContainer.swift b/Sources/XMLCoder/Decoder/SingleValueDecodingContainer.swift index 1e5f0b55..b297ac8e 100644 --- a/Sources/XMLCoder/Decoder/SingleValueDecodingContainer.swift +++ b/Sources/XMLCoder/Decoder/SingleValueDecodingContainer.swift @@ -31,7 +31,11 @@ extension XMLDecoderImplementation: SingleValueDecodingContainer { return try unbox(try topContainer()) } - public func decode(_: T.Type) throws -> T { + public func decode(_: Float.Type) throws -> Float { + return try unbox(try topContainer()) + } + + public func decode(_: Double.Type) throws -> Double { return try unbox(try topContainer()) } diff --git a/Sources/XMLCoder/Decoder/XMLDecoderImplementation.swift b/Sources/XMLCoder/Decoder/XMLDecoderImplementation.swift index f3ae46f3..d5b6f82a 100644 --- a/Sources/XMLCoder/Decoder/XMLDecoderImplementation.swift +++ b/Sources/XMLCoder/Decoder/XMLDecoderImplementation.swift @@ -286,22 +286,26 @@ extension XMLDecoderImplementation { return uint } - func unbox(_ box: Box) throws -> T { - let stringBox: StringBox = try typedBox(box, for: T.self) + func unbox(_ box: Box) throws -> Float { + let stringBox: StringBox = try typedBox(box, for: Float.self) let string = stringBox.unboxed guard let floatBox = FloatBox(xmlString: string) else { - throw DecodingError.typeMismatch(at: codingPath, expectation: T.self, reality: box) + throw DecodingError.typeMismatch(at: codingPath, expectation: Float.self, reality: box) } - guard let float: T = floatBox.unbox() else { - throw DecodingError.dataCorrupted(DecodingError.Context( - codingPath: codingPath, - debugDescription: "Parsed XML number <\(string)> does not fit in \(T.self)." - )) + return floatBox.unboxed + } + + func unbox(_ box: Box) throws -> Double { + let stringBox: StringBox = try typedBox(box, for: Double.self) + let string = stringBox.unboxed + + guard let doubleBox = DoubleBox(xmlString: string) else { + throw DecodingError.typeMismatch(at: codingPath, expectation: Double.self, reality: box) } - return float + return doubleBox.unboxed } func unbox(_ box: Box) throws -> String { diff --git a/Sources/XMLCoder/Encoder/XMLEncoderImplementation.swift b/Sources/XMLCoder/Encoder/XMLEncoderImplementation.swift index f55d5098..d16c3210 100644 --- a/Sources/XMLCoder/Encoder/XMLEncoderImplementation.swift +++ b/Sources/XMLCoder/Encoder/XMLEncoderImplementation.swift @@ -165,13 +165,26 @@ extension XMLEncoderImplementation { return UIntBox(value) } - func box(_ value: T) throws -> SimpleBox { + func box(_ value: Float) throws -> SimpleBox { + return try box(value, FloatBox.self) + } + + func box(_ value: Double) throws -> SimpleBox { + return try box(value, DoubleBox.self) + } + + func box( + _ value: T, + _: B.Type + ) throws -> SimpleBox where B.Unboxed == T { guard value.isInfinite || value.isNaN else { - return FloatBox(value) + return B(value) } - guard case let .convertToString(positiveInfinity: posInfString, - negativeInfinity: negInfString, - nan: nanString) = options.nonConformingFloatEncodingStrategy else { + guard case let .convertToString( + positiveInfinity: posInfString, + negativeInfinity: negInfString, + nan: nanString + ) = options.nonConformingFloatEncodingStrategy else { throw EncodingError._invalidFloatingPointValue(value, at: codingPath) } if value == T.infinity { diff --git a/Tests/XMLCoderTests/Box/BoolBoxTests.swift b/Tests/XMLCoderTests/Box/BoolBoxTests.swift index fa628249..61e441c8 100644 --- a/Tests/XMLCoderTests/Box/BoolBoxTests.swift +++ b/Tests/XMLCoderTests/Box/BoolBoxTests.swift @@ -36,7 +36,7 @@ class BoolBoxTests: XCTestCase { for (unboxed, string) in values { let box = Boxed(unboxed) - XCTAssertEqual(box.xmlString(), string) + XCTAssertEqual(box.xmlString, string) } } diff --git a/Tests/XMLCoderTests/Box/DataBoxTests.swift b/Tests/XMLCoderTests/Box/DataBoxTests.swift index 6246b69b..41b9b5cf 100644 --- a/Tests/XMLCoderTests/Box/DataBoxTests.swift +++ b/Tests/XMLCoderTests/Box/DataBoxTests.swift @@ -42,7 +42,7 @@ class DataBoxTests: XCTestCase { guard let box = boxOrNil else { continue } - XCTAssertEqual(box.xmlString(), xmlString) + XCTAssertEqual(box.xmlString, xmlString) } } diff --git a/Tests/XMLCoderTests/Box/DateBoxTests.swift b/Tests/XMLCoderTests/Box/DateBoxTests.swift index 2230d0bb..7d4dd83f 100644 --- a/Tests/XMLCoderTests/Box/DateBoxTests.swift +++ b/Tests/XMLCoderTests/Box/DateBoxTests.swift @@ -48,7 +48,7 @@ class DateBoxTests: XCTestCase { guard let box = boxOrNil else { continue } - XCTAssertEqual(box.xmlString(), xmlString) + XCTAssertEqual(box.xmlString, xmlString) } } @@ -65,7 +65,7 @@ class DateBoxTests: XCTestCase { guard let box = boxOrNil else { continue } - XCTAssertEqual(box.xmlString(), xmlString) + XCTAssertEqual(box.xmlString, xmlString) } } @@ -80,7 +80,7 @@ class DateBoxTests: XCTestCase { guard let box = boxOrNil else { continue } - XCTAssertEqual(box.xmlString(), xmlString) + XCTAssertEqual(box.xmlString, xmlString) } } @@ -95,7 +95,7 @@ class DateBoxTests: XCTestCase { guard let box = boxOrNil else { continue } - XCTAssertEqual(box.xmlString(), xmlString) + XCTAssertEqual(box.xmlString, xmlString) } } diff --git a/Tests/XMLCoderTests/Box/DecimalBoxTests.swift b/Tests/XMLCoderTests/Box/DecimalBoxTests.swift index 454c1f89..9e6af64d 100644 --- a/Tests/XMLCoderTests/Box/DecimalBoxTests.swift +++ b/Tests/XMLCoderTests/Box/DecimalBoxTests.swift @@ -38,7 +38,7 @@ class DecimalBoxTests: XCTestCase { for (bool, string) in values { let box = Boxed(bool) - XCTAssertEqual(box.xmlString(), string) + XCTAssertEqual(box.xmlString, string) } } diff --git a/Tests/XMLCoderTests/Box/FloatBoxTests.swift b/Tests/XMLCoderTests/Box/FloatBoxTests.swift index 1523389a..3e06485d 100644 --- a/Tests/XMLCoderTests/Box/FloatBoxTests.swift +++ b/Tests/XMLCoderTests/Box/FloatBoxTests.swift @@ -29,7 +29,7 @@ class FloatBoxTests: XCTestCase { for unboxed in values { let box = Boxed(unboxed) - XCTAssertEqual(box.unbox(), unboxed) + XCTAssertEqual(box.unboxed, unboxed) } } @@ -43,7 +43,7 @@ class FloatBoxTests: XCTestCase { for (double, string) in values { let box = FloatBox(double) - XCTAssertEqual(box.xmlString(), string) + XCTAssertEqual(box.xmlString, string) } } diff --git a/Tests/XMLCoderTests/Box/IntBoxTests.swift b/Tests/XMLCoderTests/Box/IntBoxTests.swift index 272adb61..8f476ed0 100644 --- a/Tests/XMLCoderTests/Box/IntBoxTests.swift +++ b/Tests/XMLCoderTests/Box/IntBoxTests.swift @@ -38,7 +38,7 @@ class IntBoxTests: XCTestCase { for (unboxed, string) in values { let box = Boxed(unboxed) - XCTAssertEqual(box.xmlString(), string) + XCTAssertEqual(box.xmlString, string) } } diff --git a/Tests/XMLCoderTests/Box/KeyedBoxTests.swift b/Tests/XMLCoderTests/Box/KeyedBoxTests.swift index d5d50d29..6a31cb7e 100644 --- a/Tests/XMLCoderTests/Box/KeyedBoxTests.swift +++ b/Tests/XMLCoderTests/Box/KeyedBoxTests.swift @@ -33,7 +33,7 @@ class KeyedBoxTests: XCTestCase { } func testXMLString() { - XCTAssertEqual(box.xmlString(), nil) + XCTAssertEqual(box.xmlString, nil) } func testDescription() { diff --git a/Tests/XMLCoderTests/Box/NullBoxTests.swift b/Tests/XMLCoderTests/Box/NullBoxTests.swift index a504fcdb..b86fa0b6 100644 --- a/Tests/XMLCoderTests/Box/NullBoxTests.swift +++ b/Tests/XMLCoderTests/Box/NullBoxTests.swift @@ -18,7 +18,7 @@ class NullBoxTests: XCTestCase { } func testXMLString() { - XCTAssertEqual(box.xmlString(), nil) + XCTAssertEqual(box.xmlString, nil) } func testEqual() { diff --git a/Tests/XMLCoderTests/Box/SharedBoxTests.swift b/Tests/XMLCoderTests/Box/SharedBoxTests.swift index 748e0a2c..c24f12de 100644 --- a/Tests/XMLCoderTests/Box/SharedBoxTests.swift +++ b/Tests/XMLCoderTests/Box/SharedBoxTests.swift @@ -24,19 +24,19 @@ class SharedBoxTests: XCTestCase { func testXMLString() { let nullBox = NullBox() let sharedNullBox = SharedBox(nullBox) - XCTAssertEqual(sharedNullBox.xmlString(), nullBox.xmlString()) + XCTAssertEqual(sharedNullBox.xmlString, nullBox.xmlString) let boolBox = BoolBox(false) let sharedBoolBox = SharedBox(boolBox) - XCTAssertEqual(sharedBoolBox.xmlString(), boolBox.xmlString()) + XCTAssertEqual(sharedBoolBox.xmlString, boolBox.xmlString) let intBox = IntBox(42) let sharedIntBox = SharedBox(intBox) - XCTAssertEqual(sharedIntBox.xmlString(), intBox.xmlString()) + XCTAssertEqual(sharedIntBox.xmlString, intBox.xmlString) let stringBox = StringBox("lorem ipsum") let sharedStringBox = SharedBox(stringBox) - XCTAssertEqual(sharedStringBox.xmlString(), stringBox.xmlString()) + XCTAssertEqual(sharedStringBox.xmlString, stringBox.xmlString) } func testWithShared() { diff --git a/Tests/XMLCoderTests/Box/StringBoxTests.swift b/Tests/XMLCoderTests/Box/StringBoxTests.swift index 9a2a4186..61122bc6 100644 --- a/Tests/XMLCoderTests/Box/StringBoxTests.swift +++ b/Tests/XMLCoderTests/Box/StringBoxTests.swift @@ -42,7 +42,7 @@ class StringBoxTests: XCTestCase { for (unboxed, string) in values { let box = Boxed(unboxed) - XCTAssertEqual(box.xmlString(), string) + XCTAssertEqual(box.xmlString, string) } } diff --git a/Tests/XMLCoderTests/Box/UIntBoxTests.swift b/Tests/XMLCoderTests/Box/UIntBoxTests.swift index bffee127..735d4609 100644 --- a/Tests/XMLCoderTests/Box/UIntBoxTests.swift +++ b/Tests/XMLCoderTests/Box/UIntBoxTests.swift @@ -38,7 +38,7 @@ class UIntBoxTests: XCTestCase { for (unboxed, string) in values { let box = Boxed(unboxed) - XCTAssertEqual(box.xmlString(), string) + XCTAssertEqual(box.xmlString, string) } } diff --git a/Tests/XMLCoderTests/Box/URLBoxTests.swift b/Tests/XMLCoderTests/Box/URLBoxTests.swift index 8d9109cf..8b1ed1a3 100644 --- a/Tests/XMLCoderTests/Box/URLBoxTests.swift +++ b/Tests/XMLCoderTests/Box/URLBoxTests.swift @@ -36,7 +36,7 @@ class URLBoxTests: XCTestCase { for (bool, string) in values { let box = Boxed(bool) - XCTAssertEqual(box.xmlString(), string) + XCTAssertEqual(box.xmlString, string) } } diff --git a/Tests/XMLCoderTests/Box/UnkeyedBoxTests.swift b/Tests/XMLCoderTests/Box/UnkeyedBoxTests.swift index 1729ba9d..f9e76c18 100644 --- a/Tests/XMLCoderTests/Box/UnkeyedBoxTests.swift +++ b/Tests/XMLCoderTests/Box/UnkeyedBoxTests.swift @@ -23,7 +23,7 @@ class UnkeyedBoxTests: XCTestCase { } func testXMLString() { - XCTAssertEqual(box.xmlString(), nil) + XCTAssertEqual(box.xmlString, nil) } func testDescription() { diff --git a/Tests/XMLCoderTests/Minimal/FloatTests.swift b/Tests/XMLCoderTests/Minimal/FloatTests.swift index 6ae82617..78ad12a9 100644 --- a/Tests/XMLCoderTests/Minimal/FloatTests.swift +++ b/Tests/XMLCoderTests/Minimal/FloatTests.swift @@ -17,7 +17,9 @@ class FloatTests: XCTestCase { let values: [(Value, String)] = [ (-42.0, "-42.0"), + (-3.14, "-3.14"), (0.0, "0.0"), + (3.14, "3.14"), (42.0, "42.0"), ] diff --git a/XMLCoder.xcodeproj/project.pbxproj b/XMLCoder.xcodeproj/project.pbxproj index 6669133a..030787e9 100644 --- a/XMLCoder.xcodeproj/project.pbxproj +++ b/XMLCoder.xcodeproj/project.pbxproj @@ -24,6 +24,8 @@ 4A062D4F2341924E009BCAC1 /* CombineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A062D4E2341924E009BCAC1 /* CombineTests.swift */; }; B5EA3BB6230F237800D8D69B /* NestedChoiceArrayTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5EA3BB4230F235C00D8D69B /* NestedChoiceArrayTest.swift */; }; B5F74472233F74E400BBDB15 /* RootLevelAttributeTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5F74471233F74E400BBDB15 /* RootLevelAttributeTest.swift */; }; + D11E094623491BCE00C24DCB /* DoubleBox.swift in Sources */ = {isa = PBXBuildFile; fileRef = D11E094523491BCE00C24DCB /* DoubleBox.swift */; }; + D11E094A234924C500C24DCB /* ValueBox.swift in Sources */ = {isa = PBXBuildFile; fileRef = D11E0949234924C500C24DCB /* ValueBox.swift */; }; OBJ_148 /* BoolBox.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_12 /* BoolBox.swift */; }; OBJ_149 /* Box.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_13 /* Box.swift */; }; OBJ_150 /* ChoiceBox.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_14 /* ChoiceBox.swift */; }; @@ -158,6 +160,8 @@ 4A062D4E2341924E009BCAC1 /* CombineTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CombineTests.swift; sourceTree = ""; }; B5EA3BB4230F235C00D8D69B /* NestedChoiceArrayTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NestedChoiceArrayTest.swift; sourceTree = ""; }; B5F74471233F74E400BBDB15 /* RootLevelAttributeTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RootLevelAttributeTest.swift; sourceTree = ""; }; + D11E094523491BCE00C24DCB /* DoubleBox.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DoubleBox.swift; sourceTree = ""; }; + D11E0949234924C500C24DCB /* ValueBox.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ValueBox.swift; sourceTree = ""; }; OBJ_100 /* DecimalTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DecimalTests.swift; sourceTree = ""; }; OBJ_101 /* EmptyTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyTests.swift; sourceTree = ""; }; OBJ_102 /* FloatTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FloatTests.swift; sourceTree = ""; }; @@ -330,6 +334,7 @@ OBJ_15 /* DataBox.swift */, OBJ_16 /* DateBox.swift */, OBJ_17 /* DecimalBox.swift */, + D11E094523491BCE00C24DCB /* DoubleBox.swift */, OBJ_18 /* FloatBox.swift */, OBJ_19 /* IntBox.swift */, OBJ_20 /* KeyedBox.swift */, @@ -338,8 +343,9 @@ OBJ_23 /* SingleKeyedBox.swift */, OBJ_24 /* StringBox.swift */, OBJ_25 /* UIntBox.swift */, - OBJ_26 /* URLBox.swift */, OBJ_27 /* UnkeyedBox.swift */, + OBJ_26 /* URLBox.swift */, + D11E0949234924C500C24DCB /* ValueBox.swift */, ); path = Box; sourceTree = ""; @@ -644,11 +650,13 @@ OBJ_168 /* XMLChoiceCodingKey.swift in Sources */, OBJ_169 /* XMLCoderElement.swift in Sources */, OBJ_170 /* XMLHeader.swift in Sources */, + D11E094623491BCE00C24DCB /* DoubleBox.swift in Sources */, OBJ_171 /* XMLKey.swift in Sources */, OBJ_172 /* XMLStackParser.swift in Sources */, OBJ_173 /* DecodingErrorExtension.swift in Sources */, OBJ_174 /* DynamicNodeDecoding.swift in Sources */, OBJ_175 /* SingleValueDecodingContainer.swift in Sources */, + D11E094A234924C500C24DCB /* ValueBox.swift in Sources */, OBJ_176 /* XMLChoiceDecodingContainer.swift in Sources */, OBJ_177 /* XMLDecoder.swift in Sources */, OBJ_178 /* XMLDecoderImplementation.swift in Sources */,