@testable import PureYAML import Testing @Suite("Inline nested block mappings are rejected") struct InlineNestedMappingTests { @Test("A second mapping pair on a block line is rejected", arguments: [ "a: b: c: d\n", // a plain value followed by another key "a: 'b': c\n", // a quoted value followed by another key "key2: \"q\" no key: nor value\n", // trailing content after a quoted value "x: { y: z }in: valid\n", // trailing content after a flow value ]) func test_inlineNestedMappingRejected(_ yaml: String) throws { #expect(throws: PureYAML.Parsing.ParseError.self) { try PureYAML.parse(yaml) } } @Test("Mappings spread across lines, and flow mappings, stay valid", arguments: [ "a: b\nc: d\n", // two pairs on separate lines "a:\n b: c\n", // a nested mapping on the next line "- key: value\n", // a sequence item that is a mapping "{a: b, c: d}\n", // a flow mapping with several pairs on one line "a: http://x\n", // a colon inside a plain scalar value ]) func test_validMappingsStillParse(_ yaml: String) throws { _ = try PureYAML.parse(yaml) } @Test("An explicit key's value may be a compact mapping on the value line") func test_explicitKeyCompactMappingValue() throws { // The `:` opens the line, so it is an explicit-key value indicator whose value may be a // compact block mapping, unlike an implicit key's same-line value. let value = try PureYAML.parse("? k\n: minLength: 14\n pattern: x\n") #expect(value == .mapping(.init([ .init(keyNode: .string("k"), value: .mapping(.init([ .init(key: "minLength", value: .int(14)), .init(key: "pattern", value: .string("x")), ]))), ]))) } }