Three root causes: (1) a '%' begins a directive only in directive position (before document content, outside flow); everywhere else it is plain content, fixing misfires inside plain scalars, flow mappings, and block scalars. (2) %YAML accepts any 1.x (a higher minor is treated as 1.2 without error), rejects major != 1 and duplicate %YAML, and requires a following '---'; reserved and %TAG directives are accepted and ignored. A directive not followed by a document start is rejected with the new directiveWithoutDocument error. (3) An explicit '...' end marker closes the current document so following content begins a fresh document in parseStream; single-document parse still rejects multi-document input at compose time. Tests/UnsupportedYAMLGapsFixtures.swift, StreamParsingTests, ScannerTests, and ParsingErrorTests were updated in lockstep to assert the now-correct behavior (percent-after-content is plain text; '...' then content is two documents; %YAML 1.3 is valid while 2.0 and duplicate %YAML are rejected); no test was weakened and multi-document rejection for single-document parse is still covered. Flips 15 official YAML test suite cases (295/402); SF5V, 9MMA, B63P, H7TQ now correctly rejected. 6LVF and W4TN are reclassified to json-mismatch (blocked by other scalar gaps). Updates the manifest, fixtures, counts, and roadmap.
157 lines
5.2 KiB
Swift
157 lines
5.2 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(
|
|
// A directive must be followed by a `---` document start. A reserved
|
|
// or unknown directive is otherwise ignored, but here it is trailed
|
|
// by bare content rather than a document start, which is invalid.
|
|
name: "directive without a document start",
|
|
yaml: """
|
|
%FOO bar
|
|
value: one
|
|
""",
|
|
expected: .directiveWithoutDocument(line: 2),
|
|
expectedDescription: "directive is not followed by a document start 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")),
|
|
])),
|
|
),
|
|
FallbackValueCase(
|
|
// After document content has begun, a line that starts with `%` is
|
|
// plain text, not a directive, so it reads as an ordinary mapping
|
|
// entry rather than a `%TAG`/`%YAML` directive.
|
|
name: "percent after content is plain text not a directive",
|
|
yaml: """
|
|
value: one
|
|
%TAG !e! tag:example.com,2026:
|
|
""",
|
|
expected: .mapping(.init([
|
|
.init(key: "value", value: .string("one")),
|
|
.init(key: "%TAG !e! tag:example.com,2026", value: .null),
|
|
])),
|
|
),
|
|
FallbackValueCase(
|
|
// The same holds after an explicit `---`: the document has started,
|
|
// so `%` on the next line is plain content, not a directive.
|
|
name: "percent after document start is plain text not a directive",
|
|
yaml: """
|
|
---
|
|
%TAG !e! tag:example.com,2026:
|
|
value: !e!thing one
|
|
""",
|
|
expected: .mapping(.init([
|
|
.init(key: "%TAG !e! tag:example.com,2026", value: .null),
|
|
.init(key: "value", value: .string("one")),
|
|
])),
|
|
),
|
|
]
|
|
|
|
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")]),
|
|
),
|
|
]
|
|
}
|