diff --git a/CoreXLSX.xcodeproj/project.pbxproj b/CoreXLSX.xcodeproj/project.pbxproj index d9b517ef..50049de9 100644 --- a/CoreXLSX.xcodeproj/project.pbxproj +++ b/CoreXLSX.xcodeproj/project.pbxproj @@ -49,6 +49,7 @@ D1B4F8E1221C10AC00C53C42 /* Path.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1B4F8DF221C10AC00C53C42 /* Path.swift */; }; D1B4F8E2221C10AC00C53C42 /* Path.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1B4F8DF221C10AC00C53C42 /* Path.swift */; }; D1B4F8E3221C10AC00C53C42 /* Path.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1B4F8DF221C10AC00C53C42 /* Path.swift */; }; + D1B6A2C42297F0F3005B8A6E /* Border.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1B6A2C32297F0F3005B8A6E /* Border.swift */; }; D1BBD9C6223D0E2F00B28C7B /* Styles.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1BBD9C5223D0E2F00B28C7B /* Styles.swift */; }; D1BBD9C7223D0E2F00B28C7B /* Styles.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1BBD9C5223D0E2F00B28C7B /* Styles.swift */; }; D1BBD9C8223D0E2F00B28C7B /* Styles.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1BBD9C5223D0E2F00B28C7B /* Styles.swift */; }; @@ -125,6 +126,7 @@ D1A8190A21A9D0EF004FCA33 /* Cell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Cell.swift; sourceTree = ""; }; D1A8191021A9D4ED004FCA33 /* CellQueries.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CellQueries.swift; sourceTree = ""; }; D1B4F8DF221C10AC00C53C42 /* Path.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Path.swift; sourceTree = ""; }; + D1B6A2C32297F0F3005B8A6E /* Border.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Border.swift; sourceTree = ""; }; D1BBD9C5223D0E2F00B28C7B /* Styles.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Styles.swift; sourceTree = ""; }; D1BBD9D3223D3D5C00B28C7B /* Styles.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Styles.swift; sourceTree = ""; }; D1C96B7F21A806A500303975 /* Workbook.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Workbook.swift; sourceTree = ""; }; @@ -299,16 +301,17 @@ OBJ_17 /* CoreXLSXTests */ = { isa = PBXGroup; children = ( - D1769CCA225F456300521A47 /* Namespaces.swift */, + D1B6A2C32297F0F3005B8A6E /* Border.swift */, OBJ_18 /* CellReference.swift */, OBJ_19 /* CoreXLSX.swift */, + D12211DB227B555600888BCB /* Formula.swift */, + D1769CCA225F456300521A47 /* Namespaces.swift */, OBJ_20 /* Relationships.swift */, - OBJ_21 /* XCTestManifests.swift */, - D1C96B8121A80E5900303975 /* Workbook.swift */, - D1A8190821A9CB89004FCA33 /* Worksheet.swift */, D1EB1B3321B151440043CD1E /* SharedStrings.swift */, D1BBD9D3223D3D5C00B28C7B /* Styles.swift */, - D12211DB227B555600888BCB /* Formula.swift */, + D1C96B8121A80E5900303975 /* Workbook.swift */, + D1A8190821A9CB89004FCA33 /* Worksheet.swift */, + OBJ_21 /* XCTestManifests.swift */, ); name = CoreXLSXTests; path = Tests/CoreXLSXTests; @@ -720,6 +723,7 @@ buildActionMask = 0; files = ( D1C96B8321A80EC000303975 /* Workbook.swift in Sources */, + D1B6A2C42297F0F3005B8A6E /* Border.swift in Sources */, D1769CCC225F456A00521A47 /* Namespaces.swift in Sources */, OBJ_90 /* CellReference.swift in Sources */, D1EB1B3421B151440043CD1E /* SharedStrings.swift in Sources */, diff --git a/Sources/CoreXLSX/Styles.swift b/Sources/CoreXLSX/Styles.swift index 2bcc5a47..f64398ef 100644 --- a/Sources/CoreXLSX/Styles.swift +++ b/Sources/CoreXLSX/Styles.swift @@ -159,6 +159,13 @@ public struct Borders: Codable, Equatable { case items = "border" case count } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + count = try container.decode(Int.self, forKey: .count) + items = try container.decode([Border?].self, forKey: .items) + .map { $0 ?? Border() } + } } public struct Border: Codable, Equatable { @@ -174,6 +181,16 @@ public struct Border: Codable, Equatable { public let diagonal: Value? public let horizontal: Value? public let vertical: Value? + + init() { + left = nil + right = nil + top = nil + bottom = nil + diagonal = nil + horizontal = nil + vertical = nil + } } public struct CellStyleFormats: Codable, Equatable { diff --git a/Tests/CoreXLSXTests/Border.swift b/Tests/CoreXLSXTests/Border.swift new file mode 100644 index 00000000..b0b0dfc9 --- /dev/null +++ b/Tests/CoreXLSXTests/Border.swift @@ -0,0 +1,24 @@ +// +// Border.swift +// CoreXLSXTests +// +// Created by Max Desiatov on 24/05/2019. +// + +@testable import CoreXLSX +import XCTest +@testable import XMLCoder + +private let xml = """ + + + +""".data(using: .utf8)! + +final class BorderTest: XCTestCase { + func testSingleEmpty() throws { + let result = try XMLDecoder().decode(Borders.self, from: xml) + XCTAssertEqual(result.count, 1) + XCTAssertEqual(result.items[0], Border()) + } +}