Routes the value and stream APIs through the ported scanner+parser (the event API already was), so PureYAML now parses entirely on the libyaml port. Adds the features needed to match and exceed the previous engine: JSON UTF-16 surrogate-pair \u escapes, bare documents after an explicit `...`, reserved-directive handling that still requires a following `---`, and a 64-level nesting bound enforced on the event stream so deeply nested input fails with nestingTooDeep instead of overflowing a recursive consumer. Parser errors are translated to the diagnostic-aware ParseError, recovering precise codes where identifiable and a readable malformed fallback otherwise; error-reporting fixtures are rebased onto the port. Canonical event conformance: 268 -> 271 of 308 (7Z25, HWV9, QT73). 393 tests pass.
151 lines
5.1 KiB
Swift
151 lines
5.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(
|
|
// 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: .malformed(reason: "did not find expected <document start>", line: 2, column: 1),
|
|
expectedDescription: "did not find expected <document start> at line 2, column 1",
|
|
),
|
|
ParseErrorCase(
|
|
// After document content has begun, a line starting with `%` is a
|
|
// misplaced directive (a plain scalar may not start with `%`), so the
|
|
// document is rejected rather than reinterpreting `%` as plain text.
|
|
name: "percent after content is plain text not a directive",
|
|
yaml: """
|
|
value: one
|
|
%TAG !e! tag:example.com,2026:
|
|
""",
|
|
expected: .malformed(reason: "did not find expected <document start>", line: 3, column: 1),
|
|
expectedDescription: "did not find expected <document start> at line 3, column 1",
|
|
),
|
|
ParseErrorCase(
|
|
name: "percent after document start is plain text not a directive",
|
|
yaml: """
|
|
---
|
|
%TAG !e! tag:example.com,2026:
|
|
value: !e!thing one
|
|
""",
|
|
expected: .malformed(reason: "did not find expected <document start>", line: 3, column: 1),
|
|
expectedDescription: "did not find expected <document start> at line 3, column 1",
|
|
),
|
|
]
|
|
|
|
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")]),
|
|
),
|
|
]
|
|
}
|