A block scalar whose only lines are blank never establishes a content indentation, so its blank lines stayed in the leading-blank buffer and were discarded when the scalar ended. `keep: |+` over a blank line then resolved to the empty string rather than the line break keep chomping should preserve. At stream end, flush the buffered blank lines as content wrapped in an indent/dedent pair, so the parser builds a block scalar of those lines and chomping applies: keep preserves the breaks, clip and strip trim them. Only the stream-end case is handled, where no following line constrains token ordering; an empty keep scalar before a sibling key is left for later. Raises yaml-test-suite value-level conformance to 189/194 (97.4%) with the parse-level and should-error rejection rates unchanged. 456 tests pass.
42 lines
1.7 KiB
Swift
42 lines
1.7 KiB
Swift
@testable import PureYAML
|
|
import Testing
|
|
|
|
/// A block scalar whose only lines are blank still carries those blank lines through chomping at
|
|
/// stream end. Keep (`|+` / `>+`) preserves them as line breaks, while clip (default) and strip
|
|
/// (`|-`) trim them away, so an empty keep scalar over one blank line is a single line break.
|
|
@Suite("Empty block scalar chomping")
|
|
struct EmptyBlockScalarChompingTests {
|
|
@Test("Keep chomping over a single blank line yields one line break")
|
|
func test_keepOneBlank() throws {
|
|
#expect(try PureYAML.parse("x: |+\n\n") == .mapping(.init([
|
|
.init(key: "x", value: .string("\n")),
|
|
])))
|
|
}
|
|
|
|
@Test("Keep chomping over two blank lines yields two line breaks")
|
|
func test_keepTwoBlanks() throws {
|
|
#expect(try PureYAML.parse("x: |+\n\n\n") == .mapping(.init([
|
|
.init(key: "x", value: .string("\n\n")),
|
|
])))
|
|
}
|
|
|
|
@Test("Clip and strip on empty content yield the empty string")
|
|
func test_clipAndStripEmpty() throws {
|
|
#expect(try PureYAML.parse("x: |\n\n") == .mapping(.init([
|
|
.init(key: "x", value: .string("")),
|
|
])))
|
|
#expect(try PureYAML.parse("x: >-\n\n") == .mapping(.init([
|
|
.init(key: "x", value: .string("")),
|
|
])))
|
|
}
|
|
|
|
@Test("Mixed chomping keys at stream end each chomp their empty content")
|
|
func test_mixedChompingAtStreamEnd() throws {
|
|
#expect(try PureYAML.parse("strip: >-\n\nclip: >\n\nkeep: |+\n\n") == .mapping(.init([
|
|
.init(key: "strip", value: .string("")),
|
|
.init(key: "clip", value: .string("")),
|
|
.init(key: "keep", value: .string("\n")),
|
|
])))
|
|
}
|
|
}
|