@testable import PureYAML import Testing @Suite("A percent inside a block scalar is literal content, not a directive") struct BlockScalarPercentContentTests { /// A zero-indent block scalar sits at column 0, where the directive scan runs, so a content line /// beginning with `%` was misread as a directive and rejected. Inside a block scalar a leading /// `%` is literal text (groundwork for yaml-test-suite W4TN, which also needs block-scalar /// termination by `...` and multi-document directives). @Test("A root literal block scalar keeps a leading percent as content") func test_rootBlockScalarPercentContent() throws { #expect(try PureYAML.parse("--- |\n%foo\n") == .string("%foo\n")) } /// Every content line of the block scalar keeps its leading percent, not only the first. @Test("Each block scalar line keeps its leading percent") func test_multilineBlockScalarPercentContent() throws { #expect(try PureYAML.parse("--- |\n%one\n%two\n") == .string("%one\n%two\n")) } /// The change is scoped to block scalars: a real `%YAML` directive still works, and a stray `%` /// in other content is still rejected rather than silently accepted. @Test("A directive still parses and a stray percent in content still errors") func test_directiveStillWorksAndStrayPercentRejected() throws { #expect(try PureYAML.parse("%YAML 1.2\n---\nx\n") == .string("x")) #expect(throws: PureYAML.Parsing.ParseError.self) { try PureYAML.parse("{ a,\n%x }\n") } } }