An explicit block scalar indentation indicator is the content indentation relative to the block scalar's parent node. For an inline mapping value (`- aaa: |2`) the parent is the mapping, but a compact inline mapping never pushes its indentation onto the main stack, so the indicator was added to the stack level (0) rather than the mapping's (2). The content indentation then came out too small and the next mapping key was pulled into the scalar. Capture at the header whether the block scalar is an inline mapping value (a mapping value was seen on its line). When it is, fold the deepest applicable implicit indentation into the indicator's base; a direct sequence item (`- |1`), which has no mapping value on its line, keeps the sequence's own level, so the explicit indicators on sequence items stay correct. Raises yaml-test-suite value-level conformance to 191/194 (98.5%) with the parse-level and should-error rejection rates unchanged. 463 tests pass.
33 lines
1.5 KiB
Swift
33 lines
1.5 KiB
Swift
@testable import PureYAML
|
|
import Testing
|
|
|
|
/// An explicit block scalar indentation indicator (`|2`, `>1`) is the content indentation relative to
|
|
/// the block scalar's parent node. For an inline mapping value (`- aaa: |2`) the parent is the
|
|
/// mapping, which sits at an implicit indentation off the main stack, so the indicator is measured
|
|
/// from there. A direct sequence item (`- |1`) has no such parent and keeps the sequence's own level.
|
|
@Suite("Block scalar indent indicator")
|
|
struct BlockScalarIndentIndicatorTests {
|
|
@Test("An indicator on an inline mapping value is relative to the mapping indent")
|
|
func test_inlineMappingValue() throws {
|
|
#expect(try PureYAML.parse("- aaa: |2\n xxx\n bbb: |\n xxx\n") == .sequence([
|
|
.mapping(.init([
|
|
.init(key: "aaa", value: .string("xxx\n")),
|
|
.init(key: "bbb", value: .string("xxx\n")),
|
|
])),
|
|
]))
|
|
}
|
|
|
|
@Test("An indicator on a root mapping value is relative to the root")
|
|
func test_rootMappingValue() throws {
|
|
#expect(try PureYAML.parse("aaa: |2\n xxx\n") == .mapping(.init([
|
|
.init(key: "aaa", value: .string("xxx\n")),
|
|
])))
|
|
}
|
|
|
|
@Test("An indicator on a direct sequence item keeps the sequence base")
|
|
func test_sequenceItem() throws {
|
|
// `|1` over ` explicit` (indent 2) strips one space at the sequence's own base, not three.
|
|
#expect(try PureYAML.parse("- |1\n explicit\n") == .sequence([.string(" explicit\n")]))
|
|
}
|
|
}
|