@testable import PureYAML import Testing /// An explicit key (`? foo`) may span lines: its plain scalar folds across the break, and a `:` on /// the last key line is the value indicator, not a new entry. Under an implicit key a continuation /// line ending at `:` is instead a new mapping key, so the scalar stops before it, unchanged. @Suite("Explicit key multiline fold") struct ExplicitKeyMultilineFoldTests { @Test("An explicit key continuation ending at a value colon is rejected") func test_continuationEndingAtColon() { // libyaml rejects a `: value` on a key continuation line ("mapping values are not // allowed here"): the value indicator must sit at the key's own level, on a later // line, as the next test proves. The ported engine agrees with the reference. #expect(throws: PureYAML.Parsing.ParseError.self) { try PureYAML.parse("? foo\n bar : baz\n") } } @Test("An explicit key with the colon on its own line still folds") func test_colonOnOwnLine() throws { #expect(try PureYAML.parse("? foo\n bar\n: baz\n") == .mapping(.init([ .init(key: "foo bar", value: .string("baz")), ]))) } @Test("An implicit key is unaffected: a continuation ending at a colon stays a new key") func test_implicitKeyUnchanged() throws { #expect(try PureYAML.parse("foo: bar\n") == .mapping(.init([ .init(key: "foo", value: .string("bar")), ]))) #expect(try PureYAML.parse("a: 1\nb: 2\n") == .mapping(.init([ .init(key: "a", value: .int(1)), .init(key: "b", value: .int(2)), ]))) } }