@testable import PureYAML import Testing @Suite("Flow collections reject empty entries") struct FlowEmptyEntryTests { @Test("A leading or repeated comma is an empty entry and is rejected", arguments: [ "[ , a, b, c ]\n", // leading comma in a sequence "[ a, b, c, , ]\n", // repeated comma in a sequence "{ , a: 1 }\n", // leading comma in a mapping "{ a: 1, , b: 2 }\n", // repeated comma in a mapping ]) func test_emptyEntryIsRejected(_ yaml: String) throws { #expect(throws: PureYAML.Parsing.ParseError.self) { try PureYAML.parse(yaml) } } @Test("A single trailing comma and empty collections stay valid") func test_trailingCommaAndEmptyCollectionsAccepted() throws { #expect(try PureYAML.parse("[ a, b, ]\n") == .sequence(.init([.string("a"), .string("b")]))) #expect(try PureYAML.parse("[]\n") == .sequence(.init([]))) #expect(try PureYAML.parse("{ a: 1, }\n") == .mapping(.init([.init(key: "a", value: .int(1))]))) #expect(try PureYAML.parse("{}\n") == .mapping(.init([]))) } }