The explicit-key compact block-sequence case (`? k\n: - a\n - b\n`) was only
asserted to parse without error, with a comment deferring its value because the
two entries used to fold into a single `"a - b"` scalar. That defect is fixed:
it now parses to `{k: ["a", "b"]}`. Strengthen the test to a value-level
assertion so the correct tree is locked against regression, and drop the
obsolete carve-out comment.
37 lines
1.6 KiB
Swift
37 lines
1.6 KiB
Swift
@testable import PureYAML
|
|
import Testing
|
|
|
|
@Suite("Block sequence as an inline mapping value")
|
|
struct InlineBlockSequenceValueTests {
|
|
@Test("A block sequence on the same line as an implicit key's `:` is rejected")
|
|
func test_inlineBlockSequenceValueRejected() throws {
|
|
#expect(throws: PureYAML.Parsing.ParseError.self) {
|
|
try PureYAML.parse("key: - a\n - b\n")
|
|
}
|
|
}
|
|
|
|
@Test("Block sequences positioned correctly, and look-alikes, stay valid", arguments: [
|
|
"key:\n - a\n - b\n", // sequence indented on the next line
|
|
"key:\n- a\n- b\n", // sequence at the key's indentation
|
|
"- - a\n", // a nested block sequence
|
|
"- key: value\n", // a sequence item that is a mapping
|
|
"key: [a, b]\n", // a flow sequence value
|
|
"key: -1\n", // a negative number, not a block entry
|
|
"a: b - c\n", // a dash inside a plain scalar value
|
|
])
|
|
func test_validSequencesStillParse(_ yaml: String) throws {
|
|
_ = try PureYAML.parse(yaml)
|
|
}
|
|
|
|
@Test("An explicit key's compact block-sequence value parses to its two distinct items")
|
|
func test_explicitKeyCompactSequenceValue() throws {
|
|
// The `:` opens the line, so it is an explicit-key value indicator and the compact sequence
|
|
// after it is a block sequence under `k`: the implicit-key reject above does not apply. The
|
|
// two entries stay distinct items rather than folding into a single `"a - b"` scalar.
|
|
let value = try PureYAML.parse("? k\n: - a\n - b\n")
|
|
#expect(value == .mapping(.init([
|
|
.init(key: "k", value: .sequence([.string("a"), .string("b")])),
|
|
])))
|
|
}
|
|
}
|