From f4ac07ea851fe9f4bbe5ee21b35fccf99887e638 Mon Sep 17 00:00:00 2001 From: Vincent Esche Date: Sun, 23 Dec 2018 23:08:49 +0100 Subject: [PATCH 1/4] Add a bunch of trivial yet missing unit tests to box types --- Tests/XMLCoderTests/Box/BoolBoxTests.swift | 5 +++ Tests/XMLCoderTests/Box/DataBoxTests.swift | 7 +++- Tests/XMLCoderTests/Box/DateBoxTests.swift | 5 +++ Tests/XMLCoderTests/Box/DecimalBoxTests.swift | 5 +++ Tests/XMLCoderTests/Box/FloatBoxTests.swift | 5 +++ Tests/XMLCoderTests/Box/IntBoxTests.swift | 5 +++ Tests/XMLCoderTests/Box/KeyedBoxTests.swift | 35 ++++++++++++++++- Tests/XMLCoderTests/Box/NullBoxTests.swift | 15 +++++++- Tests/XMLCoderTests/Box/StringBoxTests.swift | 5 +++ Tests/XMLCoderTests/Box/UIntBoxTests.swift | 5 +++ Tests/XMLCoderTests/Box/URLBoxTests.swift | 5 +++ Tests/XMLCoderTests/Box/UnkeyedBoxTests.swift | 38 ++++++++++++++++++- 12 files changed, 130 insertions(+), 5 deletions(-) diff --git a/Tests/XMLCoderTests/Box/BoolBoxTests.swift b/Tests/XMLCoderTests/Box/BoolBoxTests.swift index 12538de8..46a50496 100644 --- a/Tests/XMLCoderTests/Box/BoolBoxTests.swift +++ b/Tests/XMLCoderTests/Box/BoolBoxTests.swift @@ -11,6 +11,11 @@ import XCTest class BoolBoxTests: XCTestCase { typealias Boxed = BoolBox + func testIsNull() { + let box = Boxed(false) + XCTAssertEqual(box.isNull, false) + } + func testUnbox() { let values: [Boxed.Unboxed] = [ false, diff --git a/Tests/XMLCoderTests/Box/DataBoxTests.swift b/Tests/XMLCoderTests/Box/DataBoxTests.swift index 344c0c76..a557cd42 100644 --- a/Tests/XMLCoderTests/Box/DataBoxTests.swift +++ b/Tests/XMLCoderTests/Box/DataBoxTests.swift @@ -11,8 +11,11 @@ import XCTest class DataBoxTests: XCTestCase { typealias Boxed = DataBox - typealias FromXMLString = (String) -> Boxed? - + func testIsNull() { + let box = Boxed(Data(), format: .base64) + XCTAssertEqual(box.isNull, false) + } + func testUnbox() { let values: [Boxed.Unboxed] = [ Data(base64Encoded: "bG9yZW0gaXBzdW0=")!, diff --git a/Tests/XMLCoderTests/Box/DateBoxTests.swift b/Tests/XMLCoderTests/Box/DateBoxTests.swift index 36d19351..8d5923dd 100644 --- a/Tests/XMLCoderTests/Box/DateBoxTests.swift +++ b/Tests/XMLCoderTests/Box/DateBoxTests.swift @@ -17,6 +17,11 @@ class DateBoxTests: XCTestCase { return formatter }() + func testIsNull() { + let box = Boxed(Date(), format: .iso8601) + XCTAssertEqual(box.isNull, false) + } + func testUnbox() { let values: [Boxed.Unboxed] = [ Date(timeIntervalSince1970: 0.0), diff --git a/Tests/XMLCoderTests/Box/DecimalBoxTests.swift b/Tests/XMLCoderTests/Box/DecimalBoxTests.swift index a2a7596d..786fe215 100644 --- a/Tests/XMLCoderTests/Box/DecimalBoxTests.swift +++ b/Tests/XMLCoderTests/Box/DecimalBoxTests.swift @@ -11,6 +11,11 @@ import XCTest class DecimalBoxTests: XCTestCase { typealias Boxed = DecimalBox + func testIsNull() { + let box = Boxed(42.0) + XCTAssertEqual(box.isNull, false) + } + func testUnbox() { let values: [Boxed.Unboxed] = [ -1.23, diff --git a/Tests/XMLCoderTests/Box/FloatBoxTests.swift b/Tests/XMLCoderTests/Box/FloatBoxTests.swift index f17acd3c..9760a9cc 100644 --- a/Tests/XMLCoderTests/Box/FloatBoxTests.swift +++ b/Tests/XMLCoderTests/Box/FloatBoxTests.swift @@ -11,6 +11,11 @@ import XCTest class FloatBoxTests: XCTestCase { typealias Boxed = FloatBox + func testIsNull() { + let box = Boxed(42.0) + XCTAssertEqual(box.isNull, false) + } + func testUnbox() { let values: [Boxed.Unboxed] = [ -3e2, diff --git a/Tests/XMLCoderTests/Box/IntBoxTests.swift b/Tests/XMLCoderTests/Box/IntBoxTests.swift index 94f12325..9b07af59 100644 --- a/Tests/XMLCoderTests/Box/IntBoxTests.swift +++ b/Tests/XMLCoderTests/Box/IntBoxTests.swift @@ -11,6 +11,11 @@ import XCTest class IntBoxTests: XCTestCase { typealias Boxed = IntBox + func testIsNull() { + let box = Boxed(-42) + XCTAssertEqual(box.isNull, false) + } + func testUnbox() { let values: [Boxed.Unboxed] = [ -42, diff --git a/Tests/XMLCoderTests/Box/KeyedBoxTests.swift b/Tests/XMLCoderTests/Box/KeyedBoxTests.swift index 34b35ad5..d39c701e 100644 --- a/Tests/XMLCoderTests/Box/KeyedBoxTests.swift +++ b/Tests/XMLCoderTests/Box/KeyedBoxTests.swift @@ -9,11 +9,18 @@ import XCTest @testable import XMLCoder class KeyedBoxTests: XCTestCase { - lazy var box = KeyedBox( + typealias Boxed = KeyedBox + + var box = Boxed( elements: ["foo": StringBox("bar"), "baz": IntBox(42)], attributes: ["baz": StringBox("blee")] ) + func testIsNull() { + let box = Boxed() + XCTAssertEqual(box.isNull, false) + } + func testUnbox() { let (elements, attributes) = box.unbox() @@ -28,4 +35,30 @@ class KeyedBoxTests: XCTestCase { func testXMLString() { XCTAssertEqual(box.xmlString(), nil) } + + func testDescription() { + // FIXME: once we have an order-preserving storage + // we can check against the full description: + let description = box.description + XCTAssertTrue(description.contains("\"foo\": bar")) + XCTAssertTrue(description.contains("\"baz\": 42")) + } + + func testSequence() { + var sortedElements: [(String, Box)] = Array(box.elements) + sortedElements.sort { $0.0 < $1.0 } + + XCTAssertEqual(sortedElements[0].0, "baz") + XCTAssertEqual(sortedElements[1].0, "foo") + } + + func testSubscript() { + let box = Boxed( + elements: ["foo": StringBox("bar"), "baz": IntBox(42)], + attributes: ["baz": StringBox("blee")] + ) + box.elements["bar"] = NullBox() + XCTAssertEqual(box.elements.count, 3) + XCTAssertEqual(box.elements["bar"] as? NullBox, NullBox()) + } } diff --git a/Tests/XMLCoderTests/Box/NullBoxTests.swift b/Tests/XMLCoderTests/Box/NullBoxTests.swift index 0656f8cb..dda02f55 100644 --- a/Tests/XMLCoderTests/Box/NullBoxTests.swift +++ b/Tests/XMLCoderTests/Box/NullBoxTests.swift @@ -11,8 +11,21 @@ import XCTest class NullBoxTests: XCTestCase { typealias Boxed = NullBox + let box = Boxed() + + func testIsNull() { + XCTAssertEqual(box.isNull, true) + } + func testXMLString() { - let box = Boxed() XCTAssertEqual(box.xmlString(), nil) } + + func testEqual() { + XCTAssertEqual(box, Boxed()) + } + + func testDescription() { + XCTAssertEqual(box.description, "null") + } } diff --git a/Tests/XMLCoderTests/Box/StringBoxTests.swift b/Tests/XMLCoderTests/Box/StringBoxTests.swift index 8f593864..3a7210bb 100644 --- a/Tests/XMLCoderTests/Box/StringBoxTests.swift +++ b/Tests/XMLCoderTests/Box/StringBoxTests.swift @@ -11,6 +11,11 @@ import XCTest class StringBoxTests: XCTestCase { typealias Boxed = StringBox + func testIsNull() { + let box = Boxed("lorem ipsum") + XCTAssertEqual(box.isNull, false) + } + func testUnbox() { let values: [Boxed.Unboxed] = [ "", diff --git a/Tests/XMLCoderTests/Box/UIntBoxTests.swift b/Tests/XMLCoderTests/Box/UIntBoxTests.swift index e320a110..9aed4873 100644 --- a/Tests/XMLCoderTests/Box/UIntBoxTests.swift +++ b/Tests/XMLCoderTests/Box/UIntBoxTests.swift @@ -11,6 +11,11 @@ import XCTest class UIntBoxTests: XCTestCase { typealias Boxed = UIntBox + func testIsNull() { + let box = Boxed(UInt(42)) + XCTAssertEqual(box.isNull, false) + } + func testUnbox() { let values: [Boxed.Unboxed] = [ 1, diff --git a/Tests/XMLCoderTests/Box/URLBoxTests.swift b/Tests/XMLCoderTests/Box/URLBoxTests.swift index 8117775a..3c447b75 100644 --- a/Tests/XMLCoderTests/Box/URLBoxTests.swift +++ b/Tests/XMLCoderTests/Box/URLBoxTests.swift @@ -11,6 +11,11 @@ import XCTest class URLBoxTests: XCTestCase { typealias Boxed = URLBox + func testIsNull() { + let box = Boxed(URL(string: "http://example.com")!) + XCTAssertEqual(box.isNull, false) + } + func testUnbox() { let values: [Boxed.Unboxed] = [ URL(string: "file:///")!, diff --git a/Tests/XMLCoderTests/Box/UnkeyedBoxTests.swift b/Tests/XMLCoderTests/Box/UnkeyedBoxTests.swift index 05d75fd1..aa351fb3 100644 --- a/Tests/XMLCoderTests/Box/UnkeyedBoxTests.swift +++ b/Tests/XMLCoderTests/Box/UnkeyedBoxTests.swift @@ -9,8 +9,15 @@ import XCTest @testable import XMLCoder class UnkeyedBoxTests: XCTestCase { - lazy var box = UnkeyedBox([StringBox("foo"), IntBox(42)]) + typealias Boxed = UnkeyedBox + + let box = Boxed([StringBox("foo"), IntBox(42)]) + func testIsNull() { + let box = Boxed() + XCTAssertEqual(box.isNull, false) + } + func testUnbox() { let unboxed = box.unbox() XCTAssertEqual(unboxed.count, 2) @@ -21,4 +28,33 @@ class UnkeyedBoxTests: XCTestCase { func testXMLString() { XCTAssertEqual(box.xmlString(), nil) } + + func testDescription() { + XCTAssertEqual(box.description, "[foo, 42]") + } + + func testSequence() { + let sequence = IteratorSequence(box.makeIterator()) + let array: [Box] = Array(sequence) + XCTAssertEqual(array[0] as? StringBox, StringBox("foo")) + XCTAssertEqual(array[1] as? IntBox, IntBox(42)) + } + + func testSubscript() { + let box = Boxed([StringBox("foo"), IntBox(42)]) + box[0] = NullBox() + XCTAssertEqual(box.count, 2) + XCTAssertEqual(box[0] as? NullBox, NullBox()) + XCTAssertEqual(box[1] as? IntBox, IntBox(42)) + } + + func testInsertAt() { + let box = Boxed([StringBox("foo"), IntBox(42)]) + box.insert(NullBox(), at: 1) + XCTAssertEqual(box.count, 3) + + XCTAssertEqual(box[0] as? StringBox, StringBox("foo")) + XCTAssertEqual(box[1] as? NullBox, NullBox()) + XCTAssertEqual(box[2] as? IntBox, IntBox(42)) + } } From c8b3358d6d02e54c653921b05f4e993f3194d7c6 Mon Sep 17 00:00:00 2001 From: Vincent Esche Date: Sun, 23 Dec 2018 23:09:11 +0100 Subject: [PATCH 2/4] Remove unused methods from `UnkeyedBox` & `KeyedBox` --- Sources/XMLCoder/Box/KeyedBox.swift | 32 +++++++++++++-------------- Sources/XMLCoder/Box/UnkeyedBox.swift | 14 +----------- 2 files changed, 16 insertions(+), 30 deletions(-) diff --git a/Sources/XMLCoder/Box/KeyedBox.swift b/Sources/XMLCoder/Box/KeyedBox.swift index cb9225cb..ab00cb51 100644 --- a/Sources/XMLCoder/Box/KeyedBox.swift +++ b/Sources/XMLCoder/Box/KeyedBox.swift @@ -7,7 +7,7 @@ import Foundation -struct KeyedStorage { +struct KeyedStorage { typealias Buffer = [Key: Value] fileprivate var buffer: Buffer = [:] @@ -33,10 +33,6 @@ struct KeyedStorage { } } - func filter(_ isIncluded: (Key, Value) throws -> Bool) rethrows -> [(Key, Value)] { - return try buffer.filter(isIncluded) - } - func map(_ transform: (Key, Value) throws -> T) rethrows -> [T] { return try buffer.map(transform) } @@ -44,18 +40,6 @@ struct KeyedStorage { func compactMap(_ transform: ((Key, Value)) throws -> T?) rethrows -> [T] { return try buffer.compactMap(transform) } - - func mapValues(_ transform: (Value) throws -> T) rethrows -> [Key: T] { - return try buffer.mapValues(transform) - } - - func mapValues(_ transform: (Value) throws -> T) rethrows -> [(Key, T)] { - return Array(try mapValues(transform)) - } - - func mapValues(_ transform: (Value) throws -> Value) rethrows -> KeyedStorage { - return KeyedStorage(try mapValues(transform)) - } } extension KeyedStorage: Sequence { @@ -72,6 +56,14 @@ extension KeyedStorage: ExpressibleByDictionaryLiteral { } } +extension KeyedStorage: CustomStringConvertible + where Key: Comparable +{ + var description: String { + return "[\(buffer)]" + } +} + class KeyedBox { typealias Key = String typealias Attribute = SimpleBox @@ -116,3 +108,9 @@ extension KeyedBox: Box { return nil } } + +extension KeyedBox: CustomStringConvertible { + var description: String { + return "\(elements)" + } +} diff --git a/Sources/XMLCoder/Box/UnkeyedBox.swift b/Sources/XMLCoder/Box/UnkeyedBox.swift index a5755b3a..b931934d 100644 --- a/Sources/XMLCoder/Box/UnkeyedBox.swift +++ b/Sources/XMLCoder/Box/UnkeyedBox.swift @@ -42,18 +42,6 @@ class UnkeyedBox { func insert(_ newElement: Element, at index: Int) { unboxed.insert(newElement, at: index) } - - func filter(_ isIncluded: (Element) throws -> Bool) rethrows -> [Element] { - return try unboxed.filter(isIncluded) - } - - func map(_ transform: (Element) throws -> T) rethrows -> [T] { - return try unboxed.map(transform) - } - - func compactMap(_ transform: (Element) throws -> T?) rethrows -> [T] { - return try unboxed.compactMap(transform) - } } extension UnkeyedBox: Box { @@ -76,6 +64,6 @@ extension UnkeyedBox: Sequence { extension UnkeyedBox: CustomStringConvertible { var description: String { - return unboxed.description + return "\(unboxed)" } } From 133586cb47d25816557b19d1ec0d9640bb8a1ce5 Mon Sep 17 00:00:00 2001 From: Vincent Esche Date: Sun, 23 Dec 2018 23:13:50 +0100 Subject: [PATCH 3/4] Fix formatting --- Sources/XMLCoder/Box/KeyedBox.swift | 3 +-- Tests/XMLCoderTests/Box/DataBoxTests.swift | 2 +- Tests/XMLCoderTests/Box/DateBoxTests.swift | 2 +- Tests/XMLCoderTests/Box/DecimalBoxTests.swift | 2 +- Tests/XMLCoderTests/Box/FloatBoxTests.swift | 2 +- Tests/XMLCoderTests/Box/IntBoxTests.swift | 2 +- Tests/XMLCoderTests/Box/KeyedBoxTests.swift | 10 +++++----- Tests/XMLCoderTests/Box/NullBoxTests.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 | 16 ++++++++-------- 12 files changed, 26 insertions(+), 27 deletions(-) diff --git a/Sources/XMLCoder/Box/KeyedBox.swift b/Sources/XMLCoder/Box/KeyedBox.swift index ab00cb51..a6aa1691 100644 --- a/Sources/XMLCoder/Box/KeyedBox.swift +++ b/Sources/XMLCoder/Box/KeyedBox.swift @@ -57,8 +57,7 @@ extension KeyedStorage: ExpressibleByDictionaryLiteral { } extension KeyedStorage: CustomStringConvertible - where Key: Comparable -{ + where Key: Comparable { var description: String { return "[\(buffer)]" } diff --git a/Tests/XMLCoderTests/Box/DataBoxTests.swift b/Tests/XMLCoderTests/Box/DataBoxTests.swift index a557cd42..48727da3 100644 --- a/Tests/XMLCoderTests/Box/DataBoxTests.swift +++ b/Tests/XMLCoderTests/Box/DataBoxTests.swift @@ -15,7 +15,7 @@ class DataBoxTests: XCTestCase { let box = Boxed(Data(), format: .base64) XCTAssertEqual(box.isNull, false) } - + func testUnbox() { let values: [Boxed.Unboxed] = [ Data(base64Encoded: "bG9yZW0gaXBzdW0=")!, diff --git a/Tests/XMLCoderTests/Box/DateBoxTests.swift b/Tests/XMLCoderTests/Box/DateBoxTests.swift index 8d5923dd..6448b066 100644 --- a/Tests/XMLCoderTests/Box/DateBoxTests.swift +++ b/Tests/XMLCoderTests/Box/DateBoxTests.swift @@ -21,7 +21,7 @@ class DateBoxTests: XCTestCase { let box = Boxed(Date(), format: .iso8601) XCTAssertEqual(box.isNull, false) } - + func testUnbox() { let values: [Boxed.Unboxed] = [ Date(timeIntervalSince1970: 0.0), diff --git a/Tests/XMLCoderTests/Box/DecimalBoxTests.swift b/Tests/XMLCoderTests/Box/DecimalBoxTests.swift index 786fe215..79db864a 100644 --- a/Tests/XMLCoderTests/Box/DecimalBoxTests.swift +++ b/Tests/XMLCoderTests/Box/DecimalBoxTests.swift @@ -15,7 +15,7 @@ class DecimalBoxTests: XCTestCase { let box = Boxed(42.0) XCTAssertEqual(box.isNull, false) } - + func testUnbox() { let values: [Boxed.Unboxed] = [ -1.23, diff --git a/Tests/XMLCoderTests/Box/FloatBoxTests.swift b/Tests/XMLCoderTests/Box/FloatBoxTests.swift index 9760a9cc..1523389a 100644 --- a/Tests/XMLCoderTests/Box/FloatBoxTests.swift +++ b/Tests/XMLCoderTests/Box/FloatBoxTests.swift @@ -15,7 +15,7 @@ class FloatBoxTests: XCTestCase { let box = Boxed(42.0) XCTAssertEqual(box.isNull, false) } - + func testUnbox() { let values: [Boxed.Unboxed] = [ -3e2, diff --git a/Tests/XMLCoderTests/Box/IntBoxTests.swift b/Tests/XMLCoderTests/Box/IntBoxTests.swift index 9b07af59..272adb61 100644 --- a/Tests/XMLCoderTests/Box/IntBoxTests.swift +++ b/Tests/XMLCoderTests/Box/IntBoxTests.swift @@ -15,7 +15,7 @@ class IntBoxTests: XCTestCase { let box = Boxed(-42) XCTAssertEqual(box.isNull, false) } - + func testUnbox() { let values: [Boxed.Unboxed] = [ -42, diff --git a/Tests/XMLCoderTests/Box/KeyedBoxTests.swift b/Tests/XMLCoderTests/Box/KeyedBoxTests.swift index d39c701e..c8f3c43b 100644 --- a/Tests/XMLCoderTests/Box/KeyedBoxTests.swift +++ b/Tests/XMLCoderTests/Box/KeyedBoxTests.swift @@ -10,7 +10,7 @@ import XCTest class KeyedBoxTests: XCTestCase { typealias Boxed = KeyedBox - + var box = Boxed( elements: ["foo": StringBox("bar"), "baz": IntBox(42)], attributes: ["baz": StringBox("blee")] @@ -20,7 +20,7 @@ class KeyedBoxTests: XCTestCase { let box = Boxed() XCTAssertEqual(box.isNull, false) } - + func testUnbox() { let (elements, attributes) = box.unbox() @@ -35,7 +35,7 @@ class KeyedBoxTests: XCTestCase { func testXMLString() { XCTAssertEqual(box.xmlString(), nil) } - + func testDescription() { // FIXME: once we have an order-preserving storage // we can check against the full description: @@ -43,11 +43,11 @@ class KeyedBoxTests: XCTestCase { XCTAssertTrue(description.contains("\"foo\": bar")) XCTAssertTrue(description.contains("\"baz\": 42")) } - + func testSequence() { var sortedElements: [(String, Box)] = Array(box.elements) sortedElements.sort { $0.0 < $1.0 } - + XCTAssertEqual(sortedElements[0].0, "baz") XCTAssertEqual(sortedElements[1].0, "foo") } diff --git a/Tests/XMLCoderTests/Box/NullBoxTests.swift b/Tests/XMLCoderTests/Box/NullBoxTests.swift index dda02f55..a504fcdb 100644 --- a/Tests/XMLCoderTests/Box/NullBoxTests.swift +++ b/Tests/XMLCoderTests/Box/NullBoxTests.swift @@ -12,19 +12,19 @@ class NullBoxTests: XCTestCase { typealias Boxed = NullBox let box = Boxed() - + func testIsNull() { XCTAssertEqual(box.isNull, true) } - + func testXMLString() { XCTAssertEqual(box.xmlString(), nil) } - + func testEqual() { XCTAssertEqual(box, Boxed()) } - + func testDescription() { XCTAssertEqual(box.description, "null") } diff --git a/Tests/XMLCoderTests/Box/StringBoxTests.swift b/Tests/XMLCoderTests/Box/StringBoxTests.swift index 3a7210bb..9fb2921c 100644 --- a/Tests/XMLCoderTests/Box/StringBoxTests.swift +++ b/Tests/XMLCoderTests/Box/StringBoxTests.swift @@ -15,7 +15,7 @@ class StringBoxTests: XCTestCase { let box = Boxed("lorem ipsum") XCTAssertEqual(box.isNull, false) } - + func testUnbox() { let values: [Boxed.Unboxed] = [ "", diff --git a/Tests/XMLCoderTests/Box/UIntBoxTests.swift b/Tests/XMLCoderTests/Box/UIntBoxTests.swift index 9aed4873..bffee127 100644 --- a/Tests/XMLCoderTests/Box/UIntBoxTests.swift +++ b/Tests/XMLCoderTests/Box/UIntBoxTests.swift @@ -15,7 +15,7 @@ class UIntBoxTests: XCTestCase { let box = Boxed(UInt(42)) XCTAssertEqual(box.isNull, false) } - + func testUnbox() { let values: [Boxed.Unboxed] = [ 1, diff --git a/Tests/XMLCoderTests/Box/URLBoxTests.swift b/Tests/XMLCoderTests/Box/URLBoxTests.swift index 3c447b75..486267b7 100644 --- a/Tests/XMLCoderTests/Box/URLBoxTests.swift +++ b/Tests/XMLCoderTests/Box/URLBoxTests.swift @@ -15,7 +15,7 @@ class URLBoxTests: XCTestCase { let box = Boxed(URL(string: "http://example.com")!) XCTAssertEqual(box.isNull, false) } - + func testUnbox() { let values: [Boxed.Unboxed] = [ URL(string: "file:///")!, diff --git a/Tests/XMLCoderTests/Box/UnkeyedBoxTests.swift b/Tests/XMLCoderTests/Box/UnkeyedBoxTests.swift index aa351fb3..7daebf1b 100644 --- a/Tests/XMLCoderTests/Box/UnkeyedBoxTests.swift +++ b/Tests/XMLCoderTests/Box/UnkeyedBoxTests.swift @@ -10,14 +10,14 @@ import XCTest class UnkeyedBoxTests: XCTestCase { typealias Boxed = UnkeyedBox - + let box = Boxed([StringBox("foo"), IntBox(42)]) func testIsNull() { let box = Boxed() XCTAssertEqual(box.isNull, false) } - + func testUnbox() { let unboxed = box.unbox() XCTAssertEqual(unboxed.count, 2) @@ -28,31 +28,31 @@ class UnkeyedBoxTests: XCTestCase { func testXMLString() { XCTAssertEqual(box.xmlString(), nil) } - + func testDescription() { XCTAssertEqual(box.description, "[foo, 42]") } - + func testSequence() { let sequence = IteratorSequence(box.makeIterator()) let array: [Box] = Array(sequence) XCTAssertEqual(array[0] as? StringBox, StringBox("foo")) XCTAssertEqual(array[1] as? IntBox, IntBox(42)) } - + func testSubscript() { let box = Boxed([StringBox("foo"), IntBox(42)]) box[0] = NullBox() - XCTAssertEqual(box.count, 2) + XCTAssertEqual(box.count, 2) XCTAssertEqual(box[0] as? NullBox, NullBox()) XCTAssertEqual(box[1] as? IntBox, IntBox(42)) } - + func testInsertAt() { let box = Boxed([StringBox("foo"), IntBox(42)]) box.insert(NullBox(), at: 1) XCTAssertEqual(box.count, 3) - + XCTAssertEqual(box[0] as? StringBox, StringBox("foo")) XCTAssertEqual(box[1] as? NullBox, NullBox()) XCTAssertEqual(box[2] as? IntBox, IntBox(42)) From 267c7ed6787027ca83ee8a34b51ef85cbfb785a5 Mon Sep 17 00:00:00 2001 From: Vincent Esche Date: Sun, 23 Dec 2018 23:37:36 +0100 Subject: [PATCH 4/4] Made test fixture of `KeyedBoxTests` immutable --- Tests/XMLCoderTests/Box/KeyedBoxTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/XMLCoderTests/Box/KeyedBoxTests.swift b/Tests/XMLCoderTests/Box/KeyedBoxTests.swift index c8f3c43b..262c5646 100644 --- a/Tests/XMLCoderTests/Box/KeyedBoxTests.swift +++ b/Tests/XMLCoderTests/Box/KeyedBoxTests.swift @@ -11,7 +11,7 @@ import XCTest class KeyedBoxTests: XCTestCase { typealias Boxed = KeyedBox - var box = Boxed( + let box = Boxed( elements: ["foo": StringBox("bar"), "baz": IntBox(42)], attributes: ["baz": StringBox("blee")] )