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.
136 lines
4.1 KiB
Swift
136 lines
4.1 KiB
Swift
@testable import PureYAML
|
|
|
|
enum UnsupportedYAMLGapsFixtures {
|
|
struct ParseErrorCase: CustomStringConvertible {
|
|
var name: String
|
|
var yaml: String
|
|
var expected: PureYAML.Parsing.ParseError
|
|
var expectedDescription: String
|
|
|
|
var description: String {
|
|
name
|
|
}
|
|
}
|
|
|
|
struct FallbackValueCase: CustomStringConvertible {
|
|
var name: String
|
|
var yaml: String
|
|
var expected: PureYAML.Model.Value
|
|
var absentRootKeys: [String]
|
|
|
|
var description: String {
|
|
name
|
|
}
|
|
|
|
init(
|
|
name: String,
|
|
yaml: String,
|
|
expected: PureYAML.Model.Value,
|
|
absentRootKeys: [String] = ["missing"],
|
|
) {
|
|
self.name = name
|
|
self.yaml = yaml
|
|
self.expected = expected
|
|
self.absentRootKeys = absentRootKeys
|
|
}
|
|
}
|
|
|
|
static let parseErrors: [ParseErrorCase] = [
|
|
ParseErrorCase(
|
|
name: "second document start marker",
|
|
yaml: """
|
|
---
|
|
- Mark McGwire
|
|
---
|
|
- Sammy Sosa
|
|
""",
|
|
expected: .unsupportedMultiDocumentStream(line: 3),
|
|
expectedDescription: "multi-document streams are not supported at line 3",
|
|
),
|
|
ParseErrorCase(
|
|
name: "content after explicit document end",
|
|
yaml: """
|
|
name: First
|
|
...
|
|
name: Second
|
|
""",
|
|
expected: .unsupportedMultiDocumentStream(line: 3),
|
|
expectedDescription: "multi-document streams are not supported at line 3",
|
|
),
|
|
ParseErrorCase(
|
|
name: "tag directive after content",
|
|
yaml: """
|
|
value: one
|
|
%TAG !e! tag:example.com,2026:
|
|
""",
|
|
expected: .unsupportedDirective(name: "%TAG", line: 2),
|
|
expectedDescription: "unsupported directive '%TAG' at line 2",
|
|
),
|
|
ParseErrorCase(
|
|
name: "tag directive after document start",
|
|
yaml: """
|
|
---
|
|
%TAG !e! tag:example.com,2026:
|
|
value: !e!thing one
|
|
""",
|
|
expected: .unsupportedDirective(name: "%TAG", line: 2),
|
|
expectedDescription: "unsupported directive '%TAG' at line 2",
|
|
),
|
|
]
|
|
|
|
static let fallbackValues: [FallbackValueCase] = [
|
|
FallbackValueCase(
|
|
name: "unsupported built-in tags remain value trees",
|
|
yaml: """
|
|
date: !!timestamp 2001-01-23
|
|
payload: !!binary |
|
|
YWJj
|
|
set: !!set {a: null}
|
|
omap: !!omap [{a: 1}, {b: 2}]
|
|
""",
|
|
expected: .mapping(.init([
|
|
.init(key: "date", value: .string("2001-01-23")),
|
|
.init(key: "payload", value: .string("YWJj\n")),
|
|
.init(key: "set", value: .mapping(.init([
|
|
.init(key: "a", value: .null),
|
|
]))),
|
|
.init(key: "omap", value: .sequence([
|
|
.mapping(.init([
|
|
.init(key: "a", value: .int(1)),
|
|
])),
|
|
.mapping(.init([
|
|
.init(key: "b", value: .int(2)),
|
|
])),
|
|
])),
|
|
])),
|
|
),
|
|
FallbackValueCase(
|
|
name: "comments after explicit document end stay non-content",
|
|
yaml: """
|
|
name: First
|
|
...
|
|
# trailing comment
|
|
""",
|
|
expected: .mapping(.init([
|
|
.init(key: "name", value: .string("First")),
|
|
])),
|
|
),
|
|
]
|
|
|
|
static let directPreservedValue = PureYAML.Model.Value.mapping(.init([
|
|
.init(key: "<<", value: .mapping(.init([
|
|
.init(key: "enabled", value: .bool(true)),
|
|
]))),
|
|
.init(key: "title", value: .string("First")),
|
|
.init(key: "title", value: .string("Second")),
|
|
]))
|
|
|
|
static let directPreservedIssues: [PureYAML.Validation.Issue] = [
|
|
.init(
|
|
severity: .error,
|
|
reason: "Duplicate mapping key 'title'",
|
|
path: .init([.key("title")]),
|
|
),
|
|
]
|
|
}
|