PureYAML/docs/YAML_TEST_SUITE_CONFORMANCE.md
Mihaela Mihaljevic 88b67ff0b2 fix(parsing): apply flow folding to quoted scalars
Single (') and double (") quoted multi-line scalars now apply YAML 1.2 flow folding (sections 6.5, 7.3.1, 7.3.2): trailing whitespace before a break is stripped, leading whitespace on continuation lines is stripped, a single break between non-empty lines folds to one space, and N consecutive breaks yield N-1 literal line feeds (first and last lines keep their own leading/trailing spaces as content). A double-quoted backslash at end of line suppresses the break entirely.

Complete the double-quoted escape set: add \xXX and \UXXXXXXXX hex escapes plus the previously missing \0 \a \v \e, literal backslash-space, and named breaks \N \_ \L \P (existing \uXXXX surrogate-pair handling kept). The folding state machine mirrors scanner.c yaml_parser_scan_flow_scalar; implemented in Sources/Parsing/Scalar.swift.

Flips 30 official YAML test suite cases to passing (250/402). Updates the gap manifest, fixtures, count assertions, and roadmap.
2026-06-23 20:17:56 +02:00

7.3 KiB

YAML Test Suite Conformance

This document tracks PureYAML against the official YAML test suite and lays out the ordered plan for closing the gaps. It is a living document: bucket 1 (block scalars) and bucket 2 (quoted-scalar folding) have landed; buckets 3-6 remain.

How conformance is measured

The suite's data branch (commit 6ad3d2c62885d82fc349026c136ef560838fdf3d) was run against PureYAML.parseStream + PureYAML.validate, with each case judged by its own oracle:

  • error cases (an error marker): a conformant parser must reject the input.
  • data cases (an in.json): the parsed value must match the expected JSON projection (core-schema resolved), compared structurally.
  • plain valid cases (neither): the input must at least parse without error.

Result at the pinned commit

402 cases (including numbered sub-cases). First measurement was 196 pass / 206 fail; after bucket 1 (block scalars, +24) and bucket 2 (quoted-scalar folding, +30) it is now 250 pass, 152 fail. The 152 remaining failing cases are vendored under Tests/Fixtures/yaml-test-suite/ and recorded in Tests/Fixtures/yaml-test-suite-gaps.yaml. Run the opt-in sweep with:

bash scripts/check-yaml-test-suite.sh

The default swift test only checks that the manifest still matches the vendored files; the behavioral sweep is gated behind PUREYAML_RUN_YAML_TEST_SUITE=1, the same way the full real-world corpus is gated. The sweep asserts that each recorded gap still reproduces, so fixing a case fails the sweep until the manifest is updated, the deliberate forcing function for keeping this document honest.

Failure categories (remaining)

Category Count Meaning
false-reject 84 Well-formed YAML that PureYAML wrongly rejects at parse time.
json-mismatch 16 Parses, but produces a value that disagrees with the expected JSON.
accepted-invalid 52 Malformed YAML that PureYAML wrongly accepts.

Root-cause buckets and fix order

Per AGENTS.md, every fix below must start from the matching behavior in the private PureYAMLResearch repository (the libyaml-derived Sources/CYaml/src/ and the Yams Swift layer), not from re-derived intuition. The order is chosen so that structural prerequisites land before the correctness work that depends on them.

1. Block scalar folding and chomping (DONE)

Literal (|) and folded (>) scalar content now follows YAML 1.2 §8.1: interior blank lines are preserved, §8.1.3 folding is applied (single break between equally indented non-empty lines folds to a space; blank lines and more-indented lines keep their breaks), tabs in content are preserved, and the + keep chomping indicator is supported alongside clip and strip. The block scalar is scanned as a single unit with indentation auto-detection, mirroring scanner.c yaml_parser_scan_block_scalar. Implemented in Sources/Parsing/Scanner.BlockScalar.swift.

Flipped 24 cases to passing: 4QFQ, 5LLU, 6VJK, 7T8X, 96NN/00, 96NN/01, DWX9, F6MC, F8F9, H2RW, JEF9/00, JEF9/01, K527, K858, L24T/00, L24T/01, M29M, M9B4, MJS9, P2AD, R4YG, TS54, W9L4, Y79Y/001. (T5N4 looks like a block-scalar case but is blocked by document-start handling, bucket 5.)

2. Quoted-scalar line breaks and empty-line folding (DONE)

Single (') and double (") quoted multi-line scalars now apply YAML 1.2 flow folding (§6.5, §7.3.1, §7.3.2): trailing whitespace before a break is stripped, leading whitespace on a continuation line is stripped, a single break between non-empty lines folds to one space, and N consecutive breaks yield N-1 literal line feeds (the first and last lines keep their own leading and trailing spaces as content). A double quoted backslash at end of line suppresses the break entirely. The double quoted escape set is completed with \xXX and \UXXXXXXXX, plus the previously missing \0 \a \v \e, literal \<space>, and named breaks \N \_ \L \P (the existing \uXXXX surrogate-pair handling is kept). The folding state machine mirrors scanner.c yaml_parser_scan_flow_scalar; implemented in Sources/Parsing/Scalar.swift (foldFlowScalar and the escape decoder).

Flipped 30 cases to passing: 3RLN/00, 3RLN/01, 3RLN/02, 3RLN/03, 3RLN/04, 3RLN/05, 4ZYM, 565N, 5GBF, 6WPF, 7A4E, 8UDB, 9SA2, 9TFX, DE56/00, DE56/01, DE56/02, DE56/03, DE56/04, DE56/05, DK95/02, DK95/08, G4RS, NAT4, NP9H, PRH3, Q8AD, T4YY, TL85, XV9V. (DK95/01 looks similar but is blocked by tab-as-indentation handling, bucket 6.)

3. Empty nodes and empty keys (≈15 cases, false-reject)

Legal empty scalars, empty mapping values, anchors on empty scalars, and empty keys raise "expected a YAML node". Examples: PW8X, NKF9, WZ62, 8XDJ.

  • Reference: parser.c empty-node production (yaml_parser_parse_node with the empty-scalar fallback) and Yams' node composition.
  • Why third: unblocks several block-mapping spec examples that currently false-reject only because an empty node is unrepresentable mid-parse.

4. Anchors and aliases as mapping keys (≈8 cases, false-reject)

*alias : value and &anchor key : value are rejected with "expected document boundary" / "expected mapping key". Examples: 26DV, and the alias-keyed cases in X38W, LX3P.

  • Reference: the alias/anchor resolution path in parser.c plus Yams' Constructor anchor table.

5. Directives and multi-document streams (≈33 cases, false-reject)

%YAML/%TAG/unknown directives and ---/... document boundaries are explicitly unsupported (unsupportedDirective, unsupportedMultiDocumentStream). This is a feature, not a bug fix, and the largest structural change. Examples: the %YAML/%TAG/%FOO cases, UT92, W4TN, M7A3.

  • Reference: scanner.c directive scanning + parser.c document-stream state machine.
  • Why last: it is the most invasive (parser state machine + emitter round-trip) and the existing UnsupportedYAMLGapsFixtures deliberately pins the current rejection behavior, so this bucket must update those fixtures in lockstep.

6. Stricter rejection of invalid input (54 cases, accepted-invalid)

Inputs that must be rejected are silently accepted: tabs used as indentation, duplicate %YAML directives, bad document-end markers inside quoted scalars, malformed flow collections. Examples: SF5V, QB6E, RXY3, ZVH3, the Y79Y tab cases.

  • Reference: the corresponding error productions in scanner.c/parser.c.
  • Why last among the parse work: several of these only become reachable once buckets 1-5 stop short-circuiting; tightening errors earlier would mask the positive-case work.

Updating this document

When a bucket lands:

  1. Re-run bash scripts/check-yaml-test-suite.sh; it will fail on the now-fixed cases.
  2. For each newly-passing case, assert the round-trip law (parse → dump → parse is stable) in addition to the value/JSON match, per core/round-trip-transformation.md; the parser fix is only proven once the emitter agrees on the same input.
  3. Remove those cases from Tests/Fixtures/yaml-test-suite-gaps.yaml and delete their vendored fixtures (or, for json-mismatch cases that now parse but are still being verified, update current).
  4. Update the counts in this document and in CHANGELOG.md.