Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prior to this fix, we found that decoding an empty string (represented as a null element), `<string/>` was confusing the decoder. * Treat corner case of empty string value intrinsic * Remove xcodeproj junk * Add some logging to assess where we're at * Add cases for empty string as null element decoding * Swiftformat * Transform precondition to where clause in switch statement * Remove print statements * Remove nested syntax test * Fix forcecast (cherry picked from commit e6ec42a) * Fix formatting * Update LinuxMain * Remove warnings * Add fix for new empty string issue * Add back missing missingTest - remove "value" special casing from implementation * Fix formatting * Recover missing test! * Update linuxmain
- Loading branch information
1 parent
bf09326
commit 0eba4c6
Showing
6 changed files
with
115 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// | ||
// EmptyElementEmptyStringTests.swift | ||
// XMLCoderTests | ||
// | ||
// Created by James Bean on 9/29/19. | ||
// | ||
|
||
import XCTest | ||
import XMLCoder | ||
|
||
class EmptyElementEmptyStringTests: XCTestCase { | ||
struct Parent: Equatable, Codable { | ||
let thing: Thing | ||
} | ||
|
||
struct Thing: Equatable, Codable { | ||
let attribute: String? | ||
let value: String | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case attribute | ||
case value = "" | ||
} | ||
} | ||
|
||
func testEmptyElementEmptyStringDecoding() throws { | ||
let xml = """ | ||
<thing></thing> | ||
""" | ||
let expected = Thing(attribute: nil, value: "") | ||
let result = try XMLDecoder().decode(Thing.self, from: xml.data(using: .utf8)!) | ||
XCTAssertEqual(expected, result) | ||
} | ||
|
||
func testEmptyElementEmptyStringWithAttributeDecoding() throws { | ||
let xml = """ | ||
<thing attribute="x"></thing> | ||
""" | ||
let expected = Thing(attribute: "x", value: "") | ||
let result = try XMLDecoder().decode(Thing.self, from: xml.data(using: .utf8)!) | ||
XCTAssertEqual(expected, result) | ||
} | ||
|
||
func testArrayOfEmptyElementStringDecoding() throws { | ||
let xml = """ | ||
<container> | ||
<thing></thing> | ||
<thing attribute="x"></thing> | ||
<thing></thing> | ||
</container> | ||
""" | ||
let expected = [ | ||
Thing(attribute: nil, value: ""), | ||
Thing(attribute: "x", value: ""), | ||
Thing(attribute: nil, value: ""), | ||
] | ||
let result = try XMLDecoder().decode([Thing].self, from: xml.data(using: .utf8)!) | ||
XCTAssertEqual(expected, result) | ||
} | ||
|
||
func testNestedEmptyElementEmptyStringDecoding() throws { | ||
let xml = """ | ||
<parent> | ||
<thing/> | ||
</parent> | ||
""" | ||
let expected = Parent(thing: Thing(attribute: nil, value: "")) | ||
let result = try XMLDecoder().decode(Parent.self, from: xml.data(using: .utf8)!) | ||
XCTAssertEqual(expected, result) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters