PureYAML/Tests/InlineSequenceItemContinuationTests.swift
Mihaela M 4b06f6e5fc fix(parsing): end an inline item value at a sibling block entry
A block entry with an inline node recorded only the node's indent (one past
the dash) as a valid implicit level, not the dash's own indent. So a plain
scalar that is an inline sequence item value could not tell a sibling entry
that returns to the sequence indent from its own content, and a compact nested
sequence as an explicit key's value folded into one scalar: `? a` / `: - b` /
`  - - c` / `   - d` became `{a: [b -  - c - d]}` instead of `{a: [b, [c, d]]}`.

Record the entry's own indent as a sibling level too, so the continuation
stops there. Skip it under a pending explicit key, whose own sequence key
drives the implicit indentation differently (an explicit key whose key is a
sequence, `? - x`, must keep parsing). A block entry more indented than its
container is still plain content, so a wrapped value beginning a line with
`- ` folds in. The block-entry recording moved to a helper to keep the file
within its length limit.

Brings yaml-test-suite value-level conformance to 197/197 (100.0%) with the
parse-level and should-error rejection rates unchanged. 485 tests pass.
2026-06-29 02:09:57 +02:00

35 lines
1.6 KiB
Swift

@testable import PureYAML
import Testing
/// A plain scalar that is an inline block sequence item value (`: - b`) stops folding when a later
/// block entry returns to the sequence's own indent: those dashes form the rest of the sequence, not
/// content of the first item. A block entry that is more indented than the sequence is still plain
/// content of the scalar, so a wrapped value that happens to begin a line with `- ` folds in.
@Suite("Inline sequence item continuation")
struct InlineSequenceItemContinuationTests {
@Test("An inline item scalar ends at a sibling block entry")
func test_siblingEntryEndsItem() throws {
// `: - b` then ` - c` is the two-item sequence `[b, c]`, not `[b - c]`.
#expect(try PureYAML.parse(": - b\n - c\n") == .mapping(.init([
.init(keyNode: .string(""), value: .sequence([.string("b"), .string("c")])),
])))
}
@Test("A nested compact sequence as an explicit-key value parses with tabs")
func test_explicitKeyNestedSequenceWithTabs() throws {
#expect(try PureYAML.parse("? a\n: -\tb\n - -\tc\n - d\n") == .mapping(.init([
.init(key: "a", value: .sequence([
.string("b"),
.sequence([.string("c"), .string("d")]),
])),
])))
}
@Test("A more-indented dash inside a wrapped value stays content")
func test_moreIndentedDashIsContent() throws {
#expect(try PureYAML.parse("- description: a query\n and 3\n - Other.\n") == .sequence([
.mapping(.init([.init(key: "description", value: .string("a query and 3 - Other."))])),
]))
}
}