A block scalar terminated by a less-indented comment line failed with a spurious 'unexpected indentation': once the smaller indentation ended the scalar, the comment's own column was processed as a dedent, and because no indentation level held that width the dedent raised an error. A comment's indentation does not participate in block structure, so a comment that ends a block scalar is now left for the main loop to scan, with the block scalar's own first content line (which may itself begin with '#') still treated as content. Separately, a whitespace-only line indented past a block scalar's content level lost its surplus spaces because the width was consumed before the line was recognized as blank; the surplus is now preserved as the line's content, so an over-indented blank contributes the correct value. Measured against the official YAML test-suite, parse-level conformance rises from 240/333 (72.1%) to 243/333 (73.0%) with matching value-level gains, and no regression.
28 lines
1.3 KiB
Swift
28 lines
1.3 KiB
Swift
@testable import PureYAML
|
|
import Testing
|
|
|
|
@Suite("Block scalar indentation edges")
|
|
struct BlockScalarTrailingCommentTests {
|
|
@Test("A comment less indented than block scalar content ends it without error")
|
|
func test_lessIndentedTrailingCommentEndsBlockScalar() throws {
|
|
// The `# comment` sits at column 2, below the content indent (column 3), so it ends the
|
|
// block scalar and is an ordinary comment rather than driving a dedent onto an invalid
|
|
// indentation level.
|
|
#expect(try PureYAML.parse("|\n text\n # comment\n") == .string("text\n"))
|
|
}
|
|
|
|
@Test("An over-indented blank line keeps its surplus spaces as content")
|
|
func test_overIndentedBlankLineKeepsSurplusSpaces() throws {
|
|
// The middle line carries three spaces against a two-space content indent, so one surplus
|
|
// space is preserved as the line's content instead of collapsing to empty.
|
|
#expect(try PureYAML.parse("|\n a\n \n b\n") == .string("a\n \nb\n"))
|
|
}
|
|
|
|
@Test("A block scalar whose own content starts with '#' keeps it as literal text")
|
|
func test_blockScalarContentStartingWithHash() throws {
|
|
#expect(try PureYAML.parse("strip: |-\n # text\n") == .mapping(.init([
|
|
.init(key: "strip", value: .string("# text")),
|
|
])))
|
|
}
|
|
}
|