PureYAML/Tests/SingleQuotedFoldingTests.swift
Mihaela M 27e8defac6 fix(parsing): fold line breaks in multi-line single-quoted scalars
Single-quoted scalars share the same flow line folding as double-quoted,
which the previous commit added: a single break folds to a space, a blank
line to one newline, whitespace adjacent to a break is stripped, and the
first-line leading and last-line trailing whitespace are kept. The
single-quoted decoder kept its raw breaks; it now reuses the shared
foldFlowScalarLineBreaks helper, while doubled quotes ('') still escape to
one quote.

Measured against the official YAML test-suite, value-level conformance
rises from 143/169 (84.6%) to 147/169 (87.0%) with no regression.
Parse-level is unchanged: these documents already parsed, just to the
wrong tree.
2026-06-26 21:18:55 +02:00

22 lines
854 B
Swift

@testable import PureYAML
import Testing
@Suite("Single-quoted scalar folding")
struct SingleQuotedFoldingTests {
@Test("A multi-line single-quoted scalar folds breaks like a double-quoted one")
func test_singleQuotedLineFolding() throws {
let parsed = try PureYAML.parse("' 1st non-empty\n\n 2nd non-empty \n\t3rd non-empty '")
#expect(parsed == .string(" 1st non-empty\n2nd non-empty 3rd non-empty "))
}
@Test("A doubled quote escapes to one while real breaks fold")
func test_singleQuotedEscapeAndFold() throws {
#expect(try PureYAML.parse("'it''s a test\n folded line'") == .string("it's a test folded line"))
}
@Test("A single-line single-quoted scalar is unchanged")
func test_singleQuotedSingleLine() throws {
#expect(try PureYAML.parse("'single'") == .string("single"))
}
}