Skip to content

Commit

Permalink
Rename flatten to transformToBoxTree, rename tests (#97)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
MaxDesiatov committed May 2, 2019
1 parent 9f11e62 commit 706ce78
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions Sources/XMLCoder/Auxiliaries/KeyedStorage.swift
Expand Up @@ -33,8 +33,8 @@ struct KeyedStorage<Key: Hashable & Comparable, Value> {
return buffer.count
}

var keys: Buffer.Keys {
return buffer.keys
var keys: [Key] {
return order
}

init<S>(_ sequence: S) where S: Sequence, S.Element == (Key, Value) {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Sources/XMLCoder/Auxiliaries/XMLCoderElement.swift
Expand Up @@ -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)
})
Expand Down
2 changes: 1 addition & 1 deletion Sources/XMLCoder/Auxiliaries/XMLStackParser.swift
Expand Up @@ -32,7 +32,7 @@ class XMLStackParser: NSObject {
shouldProcessNamespaces: shouldProcessNamespaces
)

return node.flatten()
return node.transformToBoxTree()
}

func parse(
Expand Down
@@ -1,5 +1,5 @@
//
// FlattenTests.swift
// BoxTreeTests.swift
// XMLCoderTests
//
// Created by Max Desiatov on 07/04/2019.
Expand All @@ -8,7 +8,7 @@
import XCTest
@testable import XMLCoder

class FlattenTests: XCTestCase {
class BoxTreeTests: XCTestCase {
func testNestedValues() {
let e1 = XMLCoderElement(
key: "foo",
Expand All @@ -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,
"""
Expand Down
8 changes: 4 additions & 4 deletions XMLCoder.xcodeproj/project.pbxproj
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -216,7 +216,7 @@
D1CFC8222226AFB400B03222 /* NamespaceTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NamespaceTest.swift; sourceTree = "<group>"; };
D1E0C85121D8E6540042A261 /* ErrorContextTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ErrorContextTest.swift; sourceTree = "<group>"; };
D1E0C85421D91EBF0042A261 /* Metatypes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Metatypes.swift; sourceTree = "<group>"; };
D1EC3E61225A32F500C610E3 /* FlattenTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlattenTests.swift; sourceTree = "<group>"; };
D1EC3E61225A32F500C610E3 /* BoxTreeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BoxTreeTests.swift; sourceTree = "<group>"; };
D1EC3E63225A334C00C610E3 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
D1EC3E64225A38EC00C610E3 /* KeyedStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyedStorage.swift; sourceTree = "<group>"; };
D1FC040421C7EF8200065B43 /* RJISample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RJISample.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -353,7 +353,7 @@
A61FE03721E4D4F10015D993 /* UnkeyedIntTests.swift */,
BF9457E721CBB6BC005ACFDE /* UnkeyedTests.swift */,
BF63EF0921CD7C1A001D38C5 /* URLTests.swift */,
D1EC3E61225A32F500C610E3 /* FlattenTests.swift */,
D1EC3E61225A32F500C610E3 /* BoxTreeTests.swift */,
);
path = Minimal;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down

0 comments on commit 706ce78

Please sign in to comment.