From 706ce781f37d36ef0e1bbd5edaa2e9e794164874 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Thu, 2 May 2019 12:59:19 +0100 Subject: [PATCH] Rename flatten to transformToBoxTree, rename tests (#97) After a close look `flatten` doesn't actually flatten anything, it only transforms a tree of `XMLCoderElement`s to a tree of `Box`es. * Rename flatten to transformToBoxTree, rename tests * Rename FlattenTests file and header * Update KeyedStorage.swift --- Sources/XMLCoder/Auxiliaries/KeyedStorage.swift | 6 +++--- Sources/XMLCoder/Auxiliaries/XMLCoderElement.swift | 2 +- Sources/XMLCoder/Auxiliaries/XMLStackParser.swift | 2 +- .../Minimal/{FlattenTests.swift => BoxTreeTests.swift} | 8 ++++---- XMLCoder.xcodeproj/project.pbxproj | 8 ++++---- 5 files changed, 13 insertions(+), 13 deletions(-) rename Tests/XMLCoderTests/Minimal/{FlattenTests.swift => BoxTreeTests.swift} (83%) diff --git a/Sources/XMLCoder/Auxiliaries/KeyedStorage.swift b/Sources/XMLCoder/Auxiliaries/KeyedStorage.swift index 12b48873..9ae780eb 100644 --- a/Sources/XMLCoder/Auxiliaries/KeyedStorage.swift +++ b/Sources/XMLCoder/Auxiliaries/KeyedStorage.swift @@ -33,8 +33,8 @@ struct KeyedStorage { return buffer.count } - var keys: Buffer.Keys { - return buffer.keys + var keys: [Key] { + return order } init(_ sequence: S) where S: Sequence, S.Element == (Key, Value) { @@ -102,7 +102,7 @@ private extension KeyedStorage where Key == String, Value == Box { let hasValue = element.value != nil let key = element.key - let content = element.flatten() + let content = element.transformToBoxTree() switch self[key] { case var unkeyedBox as UnkeyedBox: unkeyedBox.append(content) diff --git a/Sources/XMLCoder/Auxiliaries/XMLCoderElement.swift b/Sources/XMLCoder/Auxiliaries/XMLCoderElement.swift index 206ddcb8..766adb3a 100644 --- a/Sources/XMLCoder/Auxiliaries/XMLCoderElement.swift +++ b/Sources/XMLCoder/Auxiliaries/XMLCoderElement.swift @@ -46,7 +46,7 @@ struct XMLCoderElement: Equatable { elements.append(element) } - func flatten() -> KeyedBox { + func transformToBoxTree() -> KeyedBox { let attributes = KeyedStorage(self.attributes.map { key, value in (key: key, value: StringBox(value) as SimpleBox) }) diff --git a/Sources/XMLCoder/Auxiliaries/XMLStackParser.swift b/Sources/XMLCoder/Auxiliaries/XMLStackParser.swift index 8bc40552..6aada60d 100644 --- a/Sources/XMLCoder/Auxiliaries/XMLStackParser.swift +++ b/Sources/XMLCoder/Auxiliaries/XMLStackParser.swift @@ -32,7 +32,7 @@ class XMLStackParser: NSObject { shouldProcessNamespaces: shouldProcessNamespaces ) - return node.flatten() + return node.transformToBoxTree() } func parse( diff --git a/Tests/XMLCoderTests/Minimal/FlattenTests.swift b/Tests/XMLCoderTests/Minimal/BoxTreeTests.swift similarity index 83% rename from Tests/XMLCoderTests/Minimal/FlattenTests.swift rename to Tests/XMLCoderTests/Minimal/BoxTreeTests.swift index bd1cde92..7daa6e21 100644 --- a/Tests/XMLCoderTests/Minimal/FlattenTests.swift +++ b/Tests/XMLCoderTests/Minimal/BoxTreeTests.swift @@ -1,5 +1,5 @@ // -// FlattenTests.swift +// BoxTreeTests.swift // XMLCoderTests // // Created by Max Desiatov on 07/04/2019. @@ -8,7 +8,7 @@ import XCTest @testable import XMLCoder -class FlattenTests: XCTestCase { +class BoxTreeTests: XCTestCase { func testNestedValues() { let e1 = XMLCoderElement( key: "foo", @@ -29,9 +29,9 @@ class FlattenTests: XCTestCase { attributes: [:] ) - let flattened = root.flatten() + let boxTree = root.transformToBoxTree() - guard let foo = flattened.elements["foo"] as? UnkeyedBox else { + guard let foo = boxTree.elements["foo"] as? UnkeyedBox else { XCTAssert( false, """ diff --git a/XMLCoder.xcodeproj/project.pbxproj b/XMLCoder.xcodeproj/project.pbxproj index 635adc1e..f9d9961b 100644 --- a/XMLCoder.xcodeproj/project.pbxproj +++ b/XMLCoder.xcodeproj/project.pbxproj @@ -95,7 +95,7 @@ D1CFC8242226B13F00B03222 /* NamespaceTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1CFC8222226AFB400B03222 /* NamespaceTest.swift */; }; D1E0C85321D8E65E0042A261 /* ErrorContextTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1E0C85121D8E6540042A261 /* ErrorContextTest.swift */; }; D1E0C85521D91EBF0042A261 /* Metatypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1E0C85421D91EBF0042A261 /* Metatypes.swift */; }; - D1EC3E62225A32F500C610E3 /* FlattenTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1EC3E61225A32F500C610E3 /* FlattenTests.swift */; }; + D1EC3E62225A32F500C610E3 /* BoxTreeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1EC3E61225A32F500C610E3 /* BoxTreeTests.swift */; }; D1EC3E65225A38EC00C610E3 /* KeyedStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1EC3E64225A38EC00C610E3 /* KeyedStorage.swift */; }; D1FC040521C7EF8200065B43 /* RJISample.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1FC040421C7EF8200065B43 /* RJISample.swift */; }; OBJ_48 /* DecodingErrorExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_10 /* DecodingErrorExtension.swift */; }; @@ -216,7 +216,7 @@ D1CFC8222226AFB400B03222 /* NamespaceTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NamespaceTest.swift; sourceTree = ""; }; D1E0C85121D8E6540042A261 /* ErrorContextTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ErrorContextTest.swift; sourceTree = ""; }; D1E0C85421D91EBF0042A261 /* Metatypes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Metatypes.swift; sourceTree = ""; }; - D1EC3E61225A32F500C610E3 /* FlattenTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlattenTests.swift; sourceTree = ""; }; + D1EC3E61225A32F500C610E3 /* BoxTreeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BoxTreeTests.swift; sourceTree = ""; }; D1EC3E63225A334C00C610E3 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = ""; }; D1EC3E64225A38EC00C610E3 /* KeyedStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyedStorage.swift; sourceTree = ""; }; D1FC040421C7EF8200065B43 /* RJISample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RJISample.swift; sourceTree = ""; }; @@ -353,7 +353,7 @@ A61FE03721E4D4F10015D993 /* UnkeyedIntTests.swift */, BF9457E721CBB6BC005ACFDE /* UnkeyedTests.swift */, BF63EF0921CD7C1A001D38C5 /* URLTests.swift */, - D1EC3E61225A32F500C610E3 /* FlattenTests.swift */, + D1EC3E61225A32F500C610E3 /* BoxTreeTests.swift */, ); path = Minimal; sourceTree = ""; @@ -656,7 +656,7 @@ B3B6902E220A71DF0084D407 /* AttributedIntrinsicTest.swift in Sources */, D11815C1227788C8008836E4 /* SpacePreserveTest.swift in Sources */, D1FC040521C7EF8200065B43 /* RJISample.swift in Sources */, - D1EC3E62225A32F500C610E3 /* FlattenTests.swift in Sources */, + D1EC3E62225A32F500C610E3 /* BoxTreeTests.swift in Sources */, BF63EF0A21CD7C1A001D38C5 /* URLTests.swift in Sources */, BF9457CE21CBB516005ACFDE /* StringBoxTests.swift in Sources */, D1CFC8242226B13F00B03222 /* NamespaceTest.swift in Sources */,