Something went wrong. Try again.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637import Foundationimport Testing@testable import CoreATProtocol
@Suite("JSONValue")struct JSONValueTests { @Test("Integers are preserved exactly and doubles stay doubles") func numbers() throws { let value = try JSONValue.parse(#"{"big": 9007199254740993, "small": 1, "float": 1.5, "neg": -42, "text": "7"}"#) #expect(value["big"]?.int64 == 9_007_199_254_740_993) #expect(value["small"]?.int == 1) #expect(value["float"]?.double == 1.5) #expect(value["float"]?.int64 == nil) #expect(value["neg"]?.int64 == -42) #expect(value["text"]?.int64 == 7) #expect(value["missing"] == nil) }
@Test("Serialisation sorts keys and round-trips nested values") func roundTrip() throws { let value: JSONValue = ["b": [1, true, nil], "a": ["nested": "x"]] let text = try value.serializedString() #expect(text == #"{"a":{"nested":"x"},"b":[1,true,null]}"#) #expect(try JSONValue.parse(text) == value) }
@Test("Accessors return nil for the wrong shape") func accessors() throws { let value: JSONValue = ["list": ["a", 1, "b"], "flag": false] #expect(value["list"]?.stringArray == ["a", "b"]) #expect(value["list"]?[1]?.int == 1) #expect(value["flag"]?.bool == false) #expect(value["flag"]?.string == nil) #expect(value["list"]?.object == nil) }}