Skip to content

Commit

Permalink
Add TopLevelDecoderTests.testDecodeOptionalTypes() to reproduce jpsim…
Browse files Browse the repository at this point in the history
  • Loading branch information
liamnichols committed Jun 9, 2022
1 parent 3969849 commit 0de508f
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions Tests/YamsTests/TopLevelDecoderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,51 @@ class TopLevelDecoderTests: XCTestCase {
)
XCTAssertEqual(foo?.name, "Bird")
}

func testDecodeOptionalTypes() throws {
let yaml = """
A: ''
B:
C: null
D: ~
E: ""
json: {
"F": "",
"G": "null"
}
array:
- one
- ''
- null
- 'null'
- '~'
"""

struct Container: Codable, Equatable {
struct JSON: Codable, Equatable {
var F: String?
var G: String?
}

var A: String?
var B: String?
var C: Int?
var D: String?
var E: String?
var json: JSON
var array: [String?]
}

let container = try YAMLDecoder().decode(Container.self, from: yaml)

XCTAssertEqual(container.A, "")
XCTAssertEqual(container.B, nil)
XCTAssertEqual(container.C, nil)
XCTAssertEqual(container.D, nil)
XCTAssertEqual(container.E, "")
XCTAssertEqual(container.json.F, "")
XCTAssertEqual(container.json.G, "null")
XCTAssertEqual(container.array, ["one", "", nil, "null", "~"])
}
}
#endif

0 comments on commit 0de508f

Please sign in to comment.