PureYAML/Tests/PlainScalarTabFoldingTests.swift
Mihaela M 246e6b1891 fix(parsing): fold tabs in plain scalar continuation lines
Plain scalar line folding strips white space around continuation lines, but
the scanner stripped only spaces, so tabs leaked in. A tab is not indentation,
so the indentation scan left a continuation line's leading tab in place and it
joined the value (`\t3rd` folded as `\t3rd`, not `3rd`), and a line of only
white space holding a tab (`  \t`) was treated as a non-blank continuation,
folding to a space rather than the line break an empty line gives.

Skip leading white space, tabs included, before a continuation line's content,
and treat a whitespace-only line that holds a tab as blank when counting the
folded line breaks.

Raises yaml-test-suite value-level conformance to 183/194 (94.3%) with the
parse-level and should-error rejection rates unchanged. 441 tests pass.
2026-06-28 21:00:32 +02:00

29 lines
1.3 KiB
Swift

@testable import PureYAML
import Testing
/// Plain scalar line folding strips white space, including tabs, around continuation lines: a tab is
/// not indentation, so the leading tab of a continuation line folds away, and a line of only white
/// space (even one holding a tab) is an empty line that folds to a line break, not a space.
@Suite("Plain scalar tab folding")
struct PlainScalarTabFoldingTests {
@Test("A leading tab on a continuation line folds away")
func test_leadingTabFoldsToSpace() throws {
#expect(try PureYAML.parse("1st non-empty\n\n 2nd non-empty \n\t3rd non-empty\n")
== .string("1st non-empty\n2nd non-empty 3rd non-empty"))
}
@Test("A whitespace-only line holding a tab is an empty line, folding to a line break")
func test_whitespaceOnlyTabLineIsBlank() throws {
#expect(try PureYAML.parse("key:\n value\n with\n \t\n tabs\n") == .mapping(.init([
.init(key: "key", value: .string("value with\ntabs")),
])))
}
@Test("A tab after the indentation of a continuation line folds away")
func test_tabAfterIndentFolds() throws {
#expect(try PureYAML.parse("x:\n - x\n \tx\n") == .mapping(.init([
.init(key: "x", value: .sequence([.string("x x")])),
])))
}
}