Fill the highest-value coverage gaps found in the Codable bridge and parser: the full integer-width decode ladder and per-width out-of-range errors, Float round-trip, NaN equality and hash consistency (the bespoke nan == nan invariant), unkeyed decodeNil false-branch and nested-index mismatch, and the previously untested expectedNode, unterminated flow mapping, explicit block-scalar under-indent, and buffered invalid-merge error paths.
45 lines
1.6 KiB
Swift
45 lines
1.6 KiB
Swift
@testable import PureYAML
|
|
import Testing
|
|
|
|
@Suite("Value Hashing")
|
|
struct ValueHashableTests {
|
|
typealias Value = PureYAML.Model.Value
|
|
|
|
@Test("NaN double values compare equal to themselves")
|
|
func test_doubleNaNValuesAreEqual() {
|
|
#expect(Value.double(.nan) == Value.double(.nan))
|
|
#expect(Value.double(.nan) != Value.double(1.0))
|
|
#expect(Value.double(1.0) == Value.double(1.0))
|
|
}
|
|
|
|
@Test("Value hashing is consistent with equality, including NaN")
|
|
func test_valueHashingIsConsistentWithEqualityIncludingNaN() {
|
|
// Two equal NaN values must collapse to one Set element, which only
|
|
// holds if hash(into:) agrees with the custom == for NaN.
|
|
let set: Set<Value> = [.double(.nan), .double(.nan)]
|
|
#expect(set.count == 1)
|
|
|
|
// Distinct values stay distinct as dictionary keys.
|
|
let table: [Value: Int] = [
|
|
.double(.nan): 1,
|
|
.int(1): 2,
|
|
.string("1"): 3,
|
|
.bool(true): 4,
|
|
.null: 5,
|
|
]
|
|
#expect(table.count == 5)
|
|
#expect(table[.double(.nan)] == 1)
|
|
#expect(table[.int(1)] == 2)
|
|
}
|
|
|
|
@Test("Equal values across cases hash and compare distinctly")
|
|
func test_distinctCasesAreNotEqual() {
|
|
#expect(Value.int(1) != Value.string("1"))
|
|
#expect(Value.int(1) != Value.double(1.0))
|
|
#expect(Value.bool(true) != Value.int(1))
|
|
#expect(Value.null != Value.string("null"))
|
|
let set: Set<Value> = [.int(1), .string("1"), .double(1.0), .bool(true), .null]
|
|
#expect(set.count == 5)
|
|
}
|
|
}
|