PureYAML/Tests/DirectiveTests.swift
Mihaela M 82d5b57fd6 fix(parsing): ignore an unrecognized directive instead of rejecting it
A directive the processor does not recognize (e.g. %FOO) before a
document is now ignored, matching the YAML spec (emit a warning, otherwise
no effect), rather than failing the whole document with an
unsupportedDirective error. %YAML and %TAG handling is unchanged, and a
directive after content, where a directive cannot legally appear, is still
rejected via the existing guard.

Two tests and a fixture that pinned the old reject-everything behavior are
updated: the unknown-directive case moves from the unsupported-gaps list,
and the scanner-error test now exercises a directive-after-content case
(still an error) rather than an unknown directive before content.

Measured against the official YAML test-suite, parse-level conformance
rises from 227/333 (68.2%) to 229/333 (68.8%), with the two newly-parsed
documents also value-correct and no regression.
2026-06-26 22:20:18 +02:00

17 lines
588 B
Swift

@testable import PureYAML
import Testing
@Suite("Directives")
struct DirectiveTests {
@Test("An unrecognized directive is ignored, not rejected")
func test_unknownDirectiveIsIgnored() throws {
// The YAML spec ignores a directive it does not recognize (with a warning), so the
// document still parses.
#expect(try PureYAML.parse("%FOO bar baz\n---\n\"foo\"\n") == .string("foo"))
#expect(
try PureYAML.parse("%FOO bar\nvalue: one\n")
== .mapping(.init([.init(key: "value", value: .string("one"))])),
)
}
}