diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b5d52c..4f1bb2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Keep the final line break of a block scalar that ends at end of input without a + trailing newline. A whitespace-only last line still counts as one line break + under keep (`+`) chomping, so `- |+` followed by a spaces-only unterminated line + yields `"\n"` rather than `""`. With this the ported engine emits the exact + canonical event stream for every valid case in the vendored YAML test suite + (308/308), surpassing libyaml (252) and the previous hand-rolled parser (267). + Surpasses libyaml on JEF9/02. - End a root-level block scalar at a `---` or `...` document marker in column 0. Now that a root block scalar can take indentation 0, its content loop reaches column-0 lines, so a marker line must end the scalar instead of being folded diff --git a/Sources/Parsing/LibYAML.Scanner.BlockScalar.swift b/Sources/Parsing/LibYAML.Scanner.BlockScalar.swift index 50f64cc..20974fa 100644 --- a/Sources/Parsing/LibYAML.Scanner.BlockScalar.swift +++ b/Sources/Parsing/LibYAML.Scanner.BlockScalar.swift @@ -118,6 +118,7 @@ extension PureYAML.Parsing.LibYAML.Scanner { // indentation. During auto-detection the floor is the parent indent + 1. let tabFloor = indent >= 0 ? indent : max(0, indentEngine.indent + 1) while true { + let lineStart = reader.column while indent < 0 || reader.column < indent, reader.peek() == " " { reader.skip() } @@ -128,6 +129,12 @@ extension PureYAML.Parsing.LibYAML.Scanner { throw blockError("found a tab character where an indentation space is expected", startMark) } if !Classify.isBreak(reader.peek()) { + // A trailing whitespace-only line that ends at end of input without + // a break still counts as one line break for keep chomping (as the + // test-suite reference does), even with no break byte present. + if reader.peek() == nil, reader.column > lineStart { + state.trailingBreaks += "\n" + } break } state.trailingBreaks += readBlockLine() diff --git a/Tests/CanonicalEventConformanceTests.swift b/Tests/CanonicalEventConformanceTests.swift index 786f131..e7b919c 100644 --- a/Tests/CanonicalEventConformanceTests.swift +++ b/Tests/CanonicalEventConformanceTests.swift @@ -11,19 +11,13 @@ import Testing struct CanonicalEventConformanceTests { /// Valid suite cases whose event stream PureYAML does NOT yet emit exactly. /// This is the authoritative gap set: a fix removes an id (and the test fails - /// until it is removed), a regression adds one (and the test fails). Of these, - /// The one remaining gap emits a wrong event stream (it does not throw). - static let knownEventGaps: Set = [ - // Gap set for the ported libyaml engine. Verified against the libyaml - // reference dumper: on all but four of these the port matches libyaml - // exactly, so the gap is libyaml's own deviation from YAML 1.2, not a port - // bug. Surpassing libyaml means shrinking this set beyond what libyaml - // itself handles. - // - // wrong event stream: the port matches libyaml but both deviate from the - // canonical events (libyaml quirks to be surpassed). - "JEF9/02", - ] + /// until it is removed), a regression adds one (and the test fails). + /// + /// The ported libyaml engine now emits the exact canonical event stream for + /// every valid case in the vendored YAML test suite, so this set is empty. + /// Each entry that used to live here was a libyaml deviation from YAML 1.2 that + /// the port has since surpassed; adding any id back means a regression. + static let knownEventGaps: Set = [] @Test("Every valid case emits canonical events, except the recorded gaps") func test_canonicalEventConformance() throws {