PureYAML/Tests/DirectiveAfterDocumentEndTests.swift
Mihaela M 7e89ba1877 fix(parsing): allow a directive after a document-end marker
A directive following a document-end marker ('...') begins the next
document's directive section, but the scanner rejected it: the
isDocumentClosed flag set by '...' tripped the directive guard, so a
multi-document stream where each document carries its own directives
('%TAG ...' / '--- doc' / '...' / '%TAG ...' / '--- doc') failed.

A directive now reopens the stream when it follows '...', clearing the
closed flag, while a directive after document content within the same
document stays rejected via the content guard. The directive still
requires its own '---', so a directive after '...' with no document start
is still an error. Multi-document streams already composed through the
stream mode; this removes the scanner-side block on per-document
directives.

Measured against the official YAML test-suite, parse-level conformance
rises from 278/333 (83.5%) to 283/333 (85.0%) with no regression.
2026-06-28 02:09:01 +02:00

29 lines
1.1 KiB
Swift

@testable import PureYAML
import Testing
@Suite("Directives after a document-end marker")
struct DirectiveAfterDocumentEndTests {
@Test("A directive after `...` begins the next document")
func test_directiveAfterDocumentEndStartsNextDocument() throws {
let docs = try PureYAML.parseStream("a\n...\n%YAML 1.2\n---\nb\n")
#expect(docs.count == 2)
#expect(docs[0].value == .string("a"))
#expect(docs[1].value == .string("b"))
}
@Test("A %TAG directive may be repeated for each document after `...`")
func test_repeatedTagDirectivePerDocument() throws {
let docs = try PureYAML.parseStream(
"%TAG !m! !my-\n--- !m!light fluorescent\n...\n%TAG !m! !my-\n--- !m!light green\n",
)
#expect(docs.count == 2)
}
@Test("A directive after `...` still requires its own document start")
func test_directiveAfterDocumentEndStillRequiresDocument() throws {
#expect(throws: PureYAML.Parsing.ParseError.self) {
try PureYAML.parseStream("a\n...\n%YAML 1.2\n")
}
}
}