@testable import PureYAML import Testing @Suite("Comments and multi-line plain scalars") struct CommentInPlainScalarTests { @Test("A comment interrupting a multi-line plain scalar is rejected", arguments: [ "key: word1\n# xxx\n word2\n", // a comment line between the value and its continuation "plain: a\n b # end of scalar\n c\n", // a comment ends the scalar, then it tries to continue ]) func test_commentInterruptedScalarRejected(_ yaml: String) throws { #expect(throws: PureYAML.Parsing.ParseError.self) { try PureYAML.parse(yaml) } } @Test("Multi-line plain scalars and trailing comments stay valid") func test_validMultilineScalarsAndComments() throws { #expect(try PureYAML.parse("plain: a\n b\n c\n") == .mapping(.init([ .init(key: "plain", value: .string("a b c")), ]))) #expect(try PureYAML.parse("key: a b # comment\n") == .mapping(.init([ .init(key: "key", value: .string("a b")), ]))) #expect(try PureYAML.parse("key: a\n b # comment\n") == .mapping(.init([ .init(key: "key", value: .string("a b")), ]))) #expect(try PureYAML.parse("a: 1\n# comment\nb: 2\n") == .mapping(.init([ .init(key: "a", value: .int(1)), .init(key: "b", value: .int(2)), ]))) } }