PureYAML/Tests/IndicatorTabBoundaryTests.swift
Mihaela M 67d72c8b15 fix(parsing): skip tabs as mid-line separation white space
skipSeparation consumed only spaces between tokens, so a tab after an
indicator leaked into the following node: an explicit key written `?\tkey`
became the key `\tkey` rather than `key`. A tab is separation white space in
YAML, forbidden only as indentation, which the line-start scan already handles
before this point.

Skip tabs there too. This closes the post-indicator tab leak left open when
the indicator boundary itself was changed, and handles a run of tabs between a
`:` and its value. The test-suite rates are unchanged, since no comparable
case isolates this, but the parser now matches the spec on tab separation.

435 tests pass.
2026-06-28 20:35:04 +02:00

39 lines
1.6 KiB
Swift

@testable import PureYAML
import Testing
/// A tab is separation white space in YAML (only indentation forbids a tab), so it ends a leading
/// indicator exactly as a space does. A document marker, block entry, or explicit key followed by a
/// tab is recognized as the indicator, not folded into a plain scalar.
@Suite("Indicator tab boundary")
struct IndicatorTabBoundaryTests {
@Test("A document marker followed by a tab introduces an inline root scalar")
func test_documentMarkerTab() throws {
#expect(try PureYAML.parse("---\tscalar\n") == .string("scalar"))
}
@Test("A block entry indicator followed by a tab still starts a sequence item")
func test_blockEntryTab() throws {
#expect(try PureYAML.parse("-\titem\n") == .sequence([.string("item")]))
}
@Test("An explicit key indicator followed by a tab starts a mapping key with the tab stripped")
func test_explicitKeyTab() throws {
#expect(try PureYAML.parse("?\tkey\n: value\n") == .mapping(.init([
.init(key: "key", value: .string("value")),
])))
}
@Test("A run of tabs between tokens is separation, not content")
func test_multipleTabSeparation() throws {
#expect(try PureYAML.parse("a:\t\tb\n") == .mapping(.init([
.init(key: "a", value: .string("b")),
])))
}
@Test("A space after an indicator is unchanged")
func test_spaceStillWorks() throws {
#expect(try PureYAML.parse("--- scalar\n") == .string("scalar"))
#expect(try PureYAML.parse("- item\n") == .sequence([.string("item")]))
}
}