@testable import PureYAML import Testing @Suite("Explicit keys") struct ExplicitKeyTests { @Test("Explicit keys with no value each map to null") func test_explicitKeysWithoutValuesMapToNull() throws { // Several `? key` entries in a row (a set, for instance) are valid; each maps to null. let value = try PureYAML.parse(""" ? a ? b c: """) #expect(value == .mapping(.init([ .init(key: "a", value: .null), .init(key: "b", value: .null), .init(key: "c", value: .null), ]))) } @Test("Explicit keys with values still parse") func test_explicitKeysWithValues() throws { let value = try PureYAML.parse(""" ? a : b ? c : d """) #expect(value == .mapping(.init([ .init(key: "a", value: .string("b")), .init(key: "c", value: .string("d")), ]))) } @Test("An explicit key that is only a property is an empty key carrying it") func test_explicitPropertyOnlyKey() throws { // `? &e` is an anchored empty key, `: &a` an anchored empty value: an empty plain scalar // resolves to the empty string as a key and to null as a value, the property binding to each // during construction. The key is no longer rejected for having no scalar before its `:`. #expect(try PureYAML.parse("? &e\n: &a\n") == .mapping(.init([ .init(keyNode: .string(""), value: .null), ]))) #expect(try PureYAML.parse("? !!str\n: !!null\n") == .mapping(.init([ .init(keyNode: .string(""), value: .null), ]))) } }