@testable import PureYAML import Testing @Suite("Document marker root nodes") struct DocumentMarkerNodeTests { @Test("A block scalar header on the document-marker line is recognized, not discarded") func test_blockScalarHeaderOnDocumentMarkerLine() throws { // `--- >` / `--- |`: the marker scanner used to skip the rest of the line, dropping the // block header so the body was mis-read as a plain scalar (folded, no trailing newline). #expect(try PureYAML.parse("--- >\n a\n b\n") == .string("a b\n")) #expect(try PureYAML.parse("--- |\n a\n b\n") == .string("a\nb\n")) } @Test("A scalar root node may begin on the document-marker line") func test_scalarRootNodeOnDocumentMarkerLine() throws { #expect(try PureYAML.parse("--- folded text\n") == .string("folded text")) // A node still on its own line below the marker keeps working. #expect(try PureYAML.parse("---\nplain text\n") == .string("plain text")) } @Test("A root plain scalar folds across lines, even at column 1") func test_rootPlainScalarFoldsAcrossLines() throws { // A document-root scalar has nothing enclosing it, so a continuation may sit at column 1. #expect(try PureYAML.parse("a\nb \n c\nd\n\ne\n") == .string("a b c d\ne")) } @Test("A root plain scalar stops at a document marker, not folding across it") func test_rootPlainScalarStopsAtDocumentMarker() throws { let documents = try PureYAML.parseStream("document 1\n---\ndocument 2\n") #expect(documents.map(\.value) == [.string("document 1"), .string("document 2")]) } }