@testable import PureYAML import Testing @Suite("Parsing Error Paths") struct ParsingErrorPathTests { @Test("A node property with no following node is an empty (null) node") func test_danglingNodePropertyIsEmptyNode() throws { // A property always attaches to a node, and an empty node is allowed, so a dangling anchor // or tag denotes a null node carrying that property rather than being an error. #expect(try PureYAML.parse("&anchor\n") == .null) #expect(try PureYAML.parse("root:\n key: &a\nother: 1\n") == .mapping(.init([ .init(key: "root", value: .mapping(.init([.init(key: "key", value: .null)]))), .init(key: "other", value: .int(1)), ]))) } @Test("An unterminated flow mapping throws at stream end") func test_unterminatedFlowMappingThrows() { expectParseError("x: {a: b", .malformed( reason: "while parsing a flow mapping, did not find expected ',' or '}'", line: 1, column: 4, )) } @Test("Block scalar content less indented than the explicit indicator throws") func test_explicitBlockScalarIndentationUnderIndentThrows() { expectParseError("k: |2\n a\n", .malformed( reason: "while parsing a block mapping, did not find expected key", line: 1, column: 1, )) } @Test("Diagnostic validation reports an invalid merge value via the buffered composer") func test_diagnosticValidationRejectsInvalidMergeValue() { let report = PureYAML.diagnosticValidationReport("a: &x 1\nb:\n <<: *x\n", file: "merge.yaml") #expect(!report.isValid) #expect(report.diagnostics.count == 1) let diagnostic = report.diagnostics.first #expect(diagnostic?.kind == .parse) #expect(diagnostic?.code == "invalidMergeValue") #expect(diagnostic?.line == 3) } }