Skip to content

Commit

Permalink
Add whitespace trimming test with copyright symbol (#147)
Browse files Browse the repository at this point in the history
Resolve #141.

* Example of wrong whitespace trimming when copyright symbol is present
* Set decoder.trimValueWhitespaces to false in test
* Move repeated string to constant
  • Loading branch information
MaxDesiatov committed Oct 17, 2019
1 parent 3f76263 commit c1bd6f1
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Tests/XMLCoderTests/SpacePreserveTest.swift
Expand Up @@ -16,12 +16,26 @@ private let nestedXML = """
<si><t xml:space="preserve"> </t></si>
""".data(using: .utf8)!

private let copyright = "Copyright © 2019 Company, Inc."

private let copyrightXML = """
<t>\(copyright)</t>
""".data(using: .utf8)!

private let nestedCopyrightXML = """
<si><t>\(copyright)</t></si>
""".data(using: .utf8)!

private struct Item: Codable, Equatable {
public let text: String?

enum CodingKeys: String, CodingKey {
case text = "t"
}

init(text: String?) {
self.text = text
}
}

final class SpacePreserveTest: XCTestCase {
Expand Down Expand Up @@ -51,4 +65,14 @@ final class SpacePreserveTest: XCTestCase {
).decode(Item.self, from: nestedXML)
XCTAssertFalse(item.text?.isEmpty ?? true)
}

func testCopyright() throws {
let decoder = XMLDecoder()
decoder.trimValueWhitespaces = false
let result = try decoder.decode(String.self, from: copyrightXML)
XCTAssertEqual(result, copyright)

let item = try decoder.decode(Item.self, from: nestedCopyrightXML)
XCTAssertEqual(item, Item(text: copyright))
}
}

0 comments on commit c1bd6f1

Please sign in to comment.