diff options
| author | Lena <lena@omega> | 2026-04-01 00:00:00 +0000 |
|---|---|---|
| committer | Lena <lena@omega> | 2026-04-01 00:00:00 +0000 |
| commit | 459f5935aab505cdb8174e5f9f04a9a3c426f37e (patch) | |
| tree | 525a5b39b05ef2c799b953ad3969e869ab484745 /render_test.go | |
| download | pdfstamp-459f5935aab505cdb8174e5f9f04a9a3c426f37e.tar.gz | |
Terminal-only PDF stamp picker. Renders a coarse page preview in the
terminal, places text and image stamps with the keyboard, saves the
layout as a JSON plan, and burns it into an output PDF.
MuPDF (via go-fitz) renders the preview; pdfcpu overlays the generated
stamp PDF onto the source 1:1 and validates the result.
Diffstat (limited to 'render_test.go')
| -rw-r--r-- | render_test.go | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/render_test.go b/render_test.go new file mode 100644 index 0000000..263c2da --- /dev/null +++ b/render_test.go @@ -0,0 +1,60 @@ +package main + +import "testing" + +// TestAxisMap checks centering when content fits and clamped scrolling when it +// does not. +func TestAxisMap(t *testing.T) { + cases := []struct { + name string + pane, content, focus int + wantBlank, wantScroll int + }{ + {"fits centered", 100, 40, 0, 30, 0}, + {"exact fit", 40, 40, 0, 0, 0}, + {"scroll centered on focus", 40, 100, 50, 0, 30}, + {"scroll clamped low", 40, 100, 0, 0, 0}, + {"scroll clamped high", 40, 100, 999, 0, 60}, + } + for _, c := range cases { + blank, scroll := axisMap(c.pane, c.content, c.focus) + if blank != c.wantBlank || scroll != c.wantScroll { + t.Errorf("%s: axisMap(%d,%d,%d) = (%d,%d), want (%d,%d)", + c.name, c.pane, c.content, c.focus, blank, scroll, c.wantBlank, c.wantScroll) + } + } +} + +// TestPtToCell checks the point->cell mapping and that moving a point by one +// stepPt lands exactly one cell away (the property the cursor/stamp nudges +// rely on). +func TestPtToCell(t *testing.T) { + // Page 600x800 pt rendered to a 120x80 px image (scaleX=0.2, scaleY=0.1), + // fitting within the pane (no scroll), centered with a 4-cell/2-px margin. + v := &view{ + cols: 128, rows: 41, + scaleX: 0.2, scaleY: 0.1, + blankX: 4, blankY: 2, + scrollX: 0, scrollY: 0, + pageH: 800, + } + + // Bottom-left of the page maps to the bottom-left of the image area. + col, row := v.ptToCell(0, 0) + if col != 4 || row != 41 { + t.Errorf("ptToCell(0,0) = (%d,%d), want (4,41)", col, row) + } + + // One horizontal step moves exactly one column; one vertical step one row. + sx, sy := v.stepPt() + x, y := 300.0, 400.0 + c0, r0 := v.ptToCell(x, y) + c1, _ := v.ptToCell(x+sx, y) + if c1-c0 != 1 { + t.Errorf("one stepPt in x moved %d cols, want 1", c1-c0) + } + _, r1 := v.ptToCell(x, y+sy) + if r0-r1 != 1 { // +y is up, which is a smaller row number + t.Errorf("one stepPt in y moved %d rows, want 1", r0-r1) + } +} |