A comment opens after white space, a tab as well as a space, but the plain scalar terminator checked only for a space before `#`. So `c: d\t#X` kept the tab and hash as content, giving the value `d\t#X` rather than `d` with a trailing comment. Treat a tab before `#` as a space there, in both the lookahead from a white space character and the check on the accumulated value's last character. A tab inside a plain scalar with no `#` after it stays content, and a `#` glued to content with no white space is still content. Raises yaml-test-suite value-level conformance to 187/194 (96.4%) with the parse-level and should-error rejection rates unchanged. 448 tests pass.
37 lines
1.4 KiB
Swift
37 lines
1.4 KiB
Swift
@testable import PureYAML
|
|
import Testing
|
|
|
|
/// A comment opens after white space, a tab as well as a space, so a `#` preceded by a tab ends a
|
|
/// plain scalar and begins a trailing comment. A tab inside a plain scalar, with no `#` after it,
|
|
/// stays part of the value, and a `#` glued directly to content (no white space) is content.
|
|
@Suite("Plain scalar tab comment")
|
|
struct PlainScalarTabCommentTests {
|
|
@Test("A tab before a hash ends the scalar and starts a comment")
|
|
func test_tabBeforeComment() throws {
|
|
#expect(try PureYAML.parse("c: d\t#X\n") == .mapping(.init([
|
|
.init(key: "c", value: .string("d")),
|
|
])))
|
|
}
|
|
|
|
@Test("A tab inside a plain scalar value is kept")
|
|
func test_internalTabKept() throws {
|
|
#expect(try PureYAML.parse("x: a\tb\n") == .mapping(.init([
|
|
.init(key: "x", value: .string("a\tb")),
|
|
])))
|
|
}
|
|
|
|
@Test("A hash glued to content with no white space stays content")
|
|
func test_hashWithoutWhitespaceIsContent() throws {
|
|
#expect(try PureYAML.parse("c: d#X\n") == .mapping(.init([
|
|
.init(key: "c", value: .string("d#X")),
|
|
])))
|
|
}
|
|
|
|
@Test("A space before a hash still ends the scalar")
|
|
func test_spaceBeforeCommentUnchanged() throws {
|
|
#expect(try PureYAML.parse("c: d #X\n") == .mapping(.init([
|
|
.init(key: "c", value: .string("d")),
|
|
])))
|
|
}
|
|
}
|