@testable import PureYAML import Testing @Suite("Parsing Block Scalar Indicators") struct ParsingBlockScalarIndicatorTests { @Test("Parses block scalar text that starts with YAML indicators") func test_blockScalarTextThatStartsWithYAMLIndicators() throws { let root = try requireMapping(PureYAML.parse( """ description: | **Fine-grained access tokens** * [GitHub App user access tokens](https://docs.github.com) - dash list item stays text """, )) // A literal block scalar preserves the blank line between the heading and // the list (YAML 1.2 line 8.1.1.1); clip keeps a single trailing newline. #expect(root?["description"] == .string( """ **Fine-grained access tokens** * [GitHub App user access tokens](https://docs.github.com) - dash list item stays text """, )) } @Test("Block scalars keep a leading '#' as literal content, not a comment") func test_blockScalarLeadingHashIsLiteralContent() throws { let root = try requireMapping(PureYAML.parse( """ folded: $ref: >- #/components/schemas/foo literal: $ref: |- #/components/schemas/bar """, )) #expect(root?.mapping("folded")?["$ref"] == .string("#/components/schemas/foo")) #expect(root?.mapping("literal")?["$ref"] == .string("#/components/schemas/bar")) } @Test("A leading '#' is preserved across every line of a block scalar") func test_blockScalarLeadingHashAcrossMultipleLines() throws { let root = try requireMapping(PureYAML.parse( """ doc: |- #/components/schemas/foo plain line #/components/schemas/bar after: tail """, )) #expect(root?["doc"] == .string( """ #/components/schemas/foo plain line #/components/schemas/bar """, )) // The block scalar ends at the dedent; the following key is unaffected. #expect(root?["after"] == .string("tail")) } }