import XCTest @testable import LCFeatureControl final class FeatureControlJSONTests: XCTestCase { private func decode(_ json: String) throws -> FeatureControlJSON { try JSONDecoder().decode(FeatureControlJSON.self, from: Data(json.utf8)) } func testDecodesNull() throws { XCTAssertEqual(try decode("null"), .null) } func testDecodesBool() throws { XCTAssertEqual(try decode("true"), .bool(true)) } func testDecodesNumber() throws { XCTAssertEqual(try decode("5"), .number(5)) } func testDecodesString() throws { XCTAssertEqual(try decode("\"hello\""), .string("hello")) } func testDecodesArray() throws { XCTAssertEqual(try decode("[\"a\",\"b\"]"), .array([.string("a"), .string("b")])) } func testDecodesNestedObject() throws { let json = #"{"limit": 5, "tags": ["a","b"], "nested": {"x": true}}"# let value = try decode(json) guard case let .object(object) = value else { return XCTFail("expected .object, got \(value)") } XCTAssertEqual(object["limit"], .number(5)) XCTAssertEqual(object["tags"], .array([.string("a"), .string("b")])) XCTAssertEqual(object["nested"], .object(["x": .bool(true)])) } }