Skip to content

test(layout): pin the boundaries the documentation states - #553

Merged
Tim81 merged 7 commits into
mainfrom
test/layout-boundary-kats
Nov 19, 2026
Merged

Tim81 merged 7 commits into
mainfrom
test/layout-boundary-kats

Conversation

@Tim81

@Tim81 Tim81 commented Sep 20, 2026 •

Copy link
Copy Markdown
Owner

Follow-up to #542.

#542 documented Layout's public surface by measuring it over 21 review rounds. Nothing held the
figures afterwards, and later rounds re-derived partitions an earlier round had already settled.
Documentation goes stale in silence. A boundary a test asserts does not.

What is pinned

67 cases (5 facts and 62 theory rows) in tests/VellumPdf.Layout.Tests/BoundaryContractTests.cs.
Every assertion that pins a sentence is taken from the probe that produced that sentence; the
controls under "How they are written" pin none.

  • Which null decides, when two are null. DrawContext.UseEmbeddedFont answers a null handle
    with NullReferenceException when its RendererContext has a document, unless the context was
    built without a page: the kernel looks the page up first and raises ArgumentNullException with
    ParamName key instead. RegisterImageXObject reads its own argument first. The two truth
    tables diverge when the document is null: UseEmbeddedFont raises NullReferenceException for
    a null handle (read from source; no row nulls the document), while RegisterImageXObject
    raises ArgumentNullException for a null image.
  • AddOutlineEntry's save refuses the Y it writes, not the layoutY passed. It flips the Y
    through PageBounds, so a finite layoutY is refused when that height is NaN, positive or
    negative infinity, or when the subtraction overflows. The tags blamed the caller's argument until
    round 21.
  • A page from another document drops a link annotation entirely, with its coordinates never
    checked, while the outline entry is still written and points at a null destination.
  • The five Document.Add overloads that carry a TextStyle (string, Paragraph, Heading,
    ListElement, TableElement) defer a non-finite font size to the save, at NaN, positive infinity and
    negative infinity separately (15 rows), and defer an unnamed Standard14 value to the save too.
    Round 7 gave Add(string, TextStyle) these tags, round 9's sweep of the style-taking members did
    not reach the four sibling Add overloads, and round 21 found them still tagging only the null
    case.
  • ListElement.Indent: a nested list is refused at its own area width, inclusively (451.2799
    saves, 451.28 throws), and the boundary moves with the list's margins. A flat list with unlinked
    text is never refused, at any indent, including positive and negative infinity and NaN (a linked run at
    NaN throws ArgumentException). At positive infinity the marker is drawn and the item text is
    discarded.
  • Heading.Level: level 0 is always a top-level entry. Any other level hangs under the most
    recent earlier entry at exactly Level - 1, or at the top level when there is none, so
    consecutive levels nest and a jump does not. A [-1, 0] row pins that level 0 stays at the top
    even after a level -1 entry.
  • Kernel: Symbol and ZapfDingbats have no advance-width tables, so every string in them measures zero #470: Symbol and ZapfDingbats measure every one of the 63,488 non-surrogate BMP characters as
    zero at each size probed. A wholly-Symbol paragraph of 660 characters draws one line where
    Helvetica wraps to nine. A centred Symbol line sits at the exact centre of the content area. In a
    wrapped paragraph the mixed Symbol and Helvetica line is centred on its Helvetica text alone.

The figures 451.28, 451.2799, 297.64 and 523.28 are what the probes measured for the rules the
members state. The documentation does not quote them.

How they are written

A refusal is asserted by exception type, ParamName or a message fragment, an acceptance by the
save completing or the call returning, and a placement by the bytes written. Non-finite inputs are listed value by value,
since NaN, positive infinity and negative infinity can take three different branches, and during
#542's review a measurement of one of them was twice promoted to a claim about all three.

The placement cases carry controls: a Helvetica line beside the Symbol one (x 257.296 centred and
442.592 right-aligned, against 297.64 and 523.28 for Symbol), and a default indent beside the
infinite one. They catch a change that always places the line at the Symbol position or always
drops the item text.

Scope

Tests only; no src/ file changes. Main is merged in (75b0c70: #577, #578, #579), so the tests
build for net10.0 and net11.0. Layout tests, Release, with REQUIRE_ORACLES=1, veraPDF 1.30.4
and qpdf 12.4.2: 479 per target framework, 0 failed, 0 skipped.

Some cases pin behaviour that later issues intend to change. #484 (validating at the property
instead of at the save) is expected to fail the non-finite font-size cases, #470 (v2.3.6) will fail every case that
depends on Symbol or ZapfDingbats measuring zero (the measurement theory, the Symbol rows of the
placement theory, both mixed-line facts and the Symbol paragraph fact), and #476 (v2.3.8) will fail the positive-infinity flat-list
row. That is the point: each of those cases pins a documented sentence, and the fix has to change that
sentence too.

#571 merges after this PR and updates, in its own diff, every pin here that it changes, so its
behaviour changes show up as test changes.

the figures afterwards. Rounds re-derived partitions an earlier round had
already settled, and three of the defects they found were sentences that had
been true when written. A boundary a test asserts fails loudly instead.

45 cases, each from the probe that produced the sentence it pins: which null
decides when two are null on DrawContext and RendererContext, and that the two
methods of one type read them in opposite orders; that a save refuses the value
it writes rather than the one passed, so a finite layoutY is refused when the
page height is not finite; that a page from another document drops a link
annotation while still writing the outline entry; that every Document.Add
overload defers its refusals to the save; where a nested list's indent is
refused and that a flat one never is; how a heading's level places its
bookmark; and that Symbol and ZapfDingbats measure every BMP character as zero.

Assertions are on exception type, ParamName or written bytes, never on a
document coming back. The placement cases carry a control - a Helvetica line
beside the Symbol one, a default indent beside the infinite one - so a change
that stops drawing cannot pass them. The suite failed eight times while it was
being written and every fix was to the test, not the library.

Layout tests: 457 run, 0 failed, 31 skipped without the oracles on PATH.
Review rounds on PR #542 measured Layout's public surface, and nothing
held the figures afterwards: rounds re-derived partitions an earlier
round had already settled. A boundary a test asserts fails loudly
instead.

BoundaryContractTests holds 55 cases (4 facts and 51 theory rows), each
from the probe that produced the sentence it pins: which null decides
when two are null on DrawContext.UseEmbeddedFont and
RendererContext.RegisterImageXObject, which read their arguments in
opposite orders; that a save refuses the value it writes rather than
the one passed; that a page from another document drops a link
annotation while the outline entry is still written; that the five
Document.Add overloads that carry a TextStyle defer that style's
refusals to the save; where a nested list's indent is refused and that
a flat list with unlinked text is never refused; how a heading's level
places its bookmark; and that Symbol and ZapfDingbats measure every
non-surrogate BMP character as zero.

A refusal is asserted by exception type, ParamName or a message
fragment, an acceptance by the save completing, and a placement by the
bytes written. The placement cases carry a control, a Helvetica line
beside the Symbol one and a default indent beside the infinite one, so
a change that stops drawing cannot pass them.

Layout tests, Release: 467 run, 0 failed, 31 skipped (oracle cases, no
oracles on PATH).
Round 2 review of the boundary tests found two assertions a mutation
survived and several sentences that overreached.

Tests: Document.Add is now run at each non-finite font size (NaN,
positive and negative infinity) for all five overloads, 15 rows, since a
NaN-only row let an eager refusal of positive infinity in Add(Paragraph)
pass. A wrapped paragraph now carries the mixed Symbol and Helvetica
line, which is what backs the claim that the line, not the paragraph, is
the unit: x 96.196, 235.282, 293.314, 293.314.

Prose: 451.28, 451.2799, 297.64 and 523.28 are the values the probes
measured for a stated rule, not figures the documentation quotes. The
mixed-line comment is scoped to a Symbol run followed by a Helvetica run
and says what round 20 changed. The test names that said more than they
pinned are renamed, and the flat-list case is scoped to unlinked text.

BoundaryContractTests: 66 cases (5 facts, 61 theory rows). Layout suite,
Release: 478 total: 447 passed, 31 skipped (veraPDF not installed),
0 failed.
Round 3 review found sentences in the boundary tests that said more than
the measurements support.

Heading.Level: level 0 is always a top-level entry, so a level -1 entry
before it does not become its parent. A [-1, 0] row pins that; it
measures one distinct parent. Any other level hangs under the most
recent earlier entry at exactly one level below it, or at the top level
when there is none.

Prose: the nested-list rows are the measured values either side of the
edge, not figures the documentation quotes. Add(string, TextStyle) got
its tags in round 7, not round 9. UseEmbeddedFont raises
NullReferenceException for a null handle only when the context has a
document. An acceptance is asserted by the save completing or the call
returning. The controls pin no sentence, so only the other assertions
are said to come from a probe. Run order changes the mixed-line result
because the space between runs is measured in the earlier run's font.
Em dashes in the test file's comments are replaced.

BoundaryContractTests: 67 cases (5 facts, 62 theory rows). Layout suite,
Release: 479 total: 448 passed, 31 skipped (veraPDF not installed),
0 failed.
Round 4 review found sentences in the boundary tests and their notes
that generalised past the rows.

The save-refusal rule is stated for AddOutlineEntry, the member the
rows exercise. The Symbol, ZapfDingbats and mixed-line summaries now
point at TextStyle.FontRef, which holds the sentences they pin. The
mixed-line summary gives the mechanism for the run-order result: each
run is placed after the measured width of the runs before it, a Symbol
run measures zero, and the space between runs is measured in the
earlier run's font. The UseEmbeddedFont null-document behaviour is
marked as read from source, since no row nulls the document. The
CHANGELOG entry carries the full Heading.Level rule.

Documentation and comments only; no assertion changed.
BoundaryContractTests still runs 67 cases, 0 failed.
Comments only, no wording change. Doc-comment paragraphs that ran past
100 columns are rewrapped, and two trailing comments that pushed a code
line past it now sit on the line above. Code lines over 100 columns are
left as they are, since dotnet format does not wrap them.
@Tim81
Tim81 merged commit 540cfc8 into main Nov 19, 2026
5 checks passed
@Tim81
Tim81 deleted the test/layout-boundary-kats branch November 21, 2026 06:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant