PureYAML/Tests/ExplicitKeyMultilineFoldTests.swift
Mihaela Mihaljevic a8950e118c Merge conformance/yaml-test-suite-gaps: the libyaml port becomes the engine on main
The ported engine wins every conflict: main's post-fork patches to the
hand-rolled Scanner and TokenEventParser land on deleted files and are
dropped; their behaviors are carried by the port and guarded by the
whole-suite conformance gate (402/402 passing).

Merge adaptations, all gates green (style, namespacing, forbidden
patterns, changelog, roadmap, swiftformat, swiftlint strict, build,
full test suite, whole-suite conformance sweep):

- PureYAMLJSON representability rules move onto the Check algebra,
  replacing the retired legacy Rule type.
- The permissive tag-handle pre-pass is removed; the port rejects an
  undefined handle at parse time (suite case QLJ7) and the validation
  report carries it as a parse diagnostic.
- EventStreamComposer's nested types split one-per-file per the
  namespacing gate.
- Tests pinned to old-engine behavior were re-verified against the
  reference and updated: libyaml rejects an explicit-key continuation
  ending at a value colon, and suite case QB6E requires rejecting a
  quoted continuation at column 0.
- CHANGELOG unreleased entries from both lines are preserved in two
  groups with a provenance note.

Closes #1, closes #3
2026-07-05 00:23:48 +02:00

37 lines
1.6 KiB
Swift

@testable import PureYAML
import Testing
/// An explicit key (`? foo`) may span lines: its plain scalar folds across the break, and a `:` on
/// the last key line is the value indicator, not a new entry. Under an implicit key a continuation
/// line ending at `:` is instead a new mapping key, so the scalar stops before it, unchanged.
@Suite("Explicit key multiline fold")
struct ExplicitKeyMultilineFoldTests {
@Test("An explicit key continuation ending at a value colon is rejected")
func test_continuationEndingAtColon() {
// libyaml rejects a `: value` on a key continuation line ("mapping values are not
// allowed here"): the value indicator must sit at the key's own level, on a later
// line, as the next test proves. The ported engine agrees with the reference.
#expect(throws: PureYAML.Parsing.ParseError.self) {
try PureYAML.parse("? foo\n bar : baz\n")
}
}
@Test("An explicit key with the colon on its own line still folds")
func test_colonOnOwnLine() throws {
#expect(try PureYAML.parse("? foo\n bar\n: baz\n") == .mapping(.init([
.init(key: "foo bar", value: .string("baz")),
])))
}
@Test("An implicit key is unaffected: a continuation ending at a colon stays a new key")
func test_implicitKeyUnchanged() throws {
#expect(try PureYAML.parse("foo: bar\n") == .mapping(.init([
.init(key: "foo", value: .string("bar")),
])))
#expect(try PureYAML.parse("a: 1\nb: 2\n") == .mapping(.init([
.init(key: "a", value: .int(1)),
.init(key: "b", value: .int(2)),
])))
}
}