An alias is a bare reference and cannot carry node properties, so '&b *a' (an anchor on an alias) and a tag on an alias are malformed. parseNode ignored any pending anchor or tag when it reached an alias token, dropping the property and accepting the document. The alias case now rejects a pending anchor or tag, and moves to its own parseAlias helper so parseNode stays within the complexity limit. A bare alias and an anchor or tag on a real node are unaffected. Measured against the official YAML test-suite, parse-level conformance rises from 266/333 (79.9%) to 267/333 (80.2%) with no regression.
25 lines
944 B
Swift
25 lines
944 B
Swift
@testable import PureYAML
|
|
import Testing
|
|
|
|
@Suite("An alias node carries no properties")
|
|
struct AliasPropertiesTests {
|
|
@Test("An anchor or tag on an alias is rejected", arguments: [
|
|
"key1: &a value\nkey2: &b *a\n", // an anchor on an alias
|
|
"key1: &a value\nkey2: !!str *a\n", // a tag on an alias
|
|
])
|
|
func test_aliasWithPropertiesRejected(_ yaml: String) throws {
|
|
#expect(throws: PureYAML.Parsing.ParseError.self) {
|
|
try PureYAML.parse(yaml)
|
|
}
|
|
}
|
|
|
|
@Test("A bare alias, and an anchor on a real node, stay valid")
|
|
func test_validAliasesAndAnchors() throws {
|
|
#expect(try PureYAML.parse("key1: &a value\nkey2: *a\n") == .mapping(.init([
|
|
.init(key: "key1", value: .string("value")),
|
|
.init(key: "key2", value: .string("value")),
|
|
])))
|
|
#expect(try PureYAML.parse("- &a x\n- *a\n") == .sequence(.init([.string("x"), .string("x")])))
|
|
}
|
|
}
|