aboutsummaryrefslogtreecommitdiff
path: root/pick_test.go
diff options
context:
space:
mode:
authorLena <lena@omega>2026-04-01 00:00:00 +0000
committerLena <lena@omega>2026-04-01 00:00:00 +0000
commit459f5935aab505cdb8174e5f9f04a9a3c426f37e (patch)
tree525a5b39b05ef2c799b953ad3969e869ab484745 /pick_test.go
downloadpdfstamp-459f5935aab505cdb8174e5f9f04a9a3c426f37e.tar.gz
Enter pdfstampHEADmaster
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 'pick_test.go')
-rw-r--r--pick_test.go71
1 files changed, 71 insertions, 0 deletions
diff --git a/pick_test.go b/pick_test.go
new file mode 100644
index 0000000..c7ab985
--- /dev/null
+++ b/pick_test.go
@@ -0,0 +1,71 @@
+package main
+
+import (
+ "reflect"
+ "testing"
+)
+
+func TestParsePages(t *testing.T) {
+ ok := map[string]struct {
+ in string
+ n int
+ want []int
+ }{
+ "single": {"2", 5, []int{2}},
+ "list": {"1,3", 5, []int{1, 3}},
+ "range": {"2-4", 5, []int{2, 3, 4}},
+ "mixed": {"1,3-5", 5, []int{1, 3, 4, 5}},
+ "overlap": {"1-3,2-4", 5, []int{1, 2, 3, 4}},
+ "all": {"all", 3, []int{1, 2, 3}},
+ "spaces": {" 1 , 3 - 4 ", 5, []int{1, 3, 4}},
+ "unordered": {"4,1", 5, []int{1, 4}},
+ "full bounds": {"1-5", 5, []int{1, 2, 3, 4, 5}},
+ }
+ for name, c := range ok {
+ got, err := parsePages(c.in, c.n)
+ if err != nil {
+ t.Errorf("%s: unexpected error: %v", name, err)
+ continue
+ }
+ if !reflect.DeepEqual(got, c.want) {
+ t.Errorf("%s: parsePages(%q,%d) = %v, want %v", name, c.in, c.n, got, c.want)
+ }
+ }
+
+ bad := map[string]struct {
+ in string
+ n int
+ }{
+ "empty": {"", 5},
+ "zero": {"0", 5},
+ "beyond doc": {"6", 5},
+ "range beyond": {"4-6", 5},
+ "reversed": {"4-2", 5},
+ "junk": {"x", 5},
+ "trailing junk": {"1,", 5},
+ "open range": {"3-", 5},
+ }
+ for name, c := range bad {
+ if got, err := parsePages(c.in, c.n); err == nil {
+ t.Errorf("%s: parsePages(%q,%d) = %v, expected error", name, c.in, c.n, got)
+ }
+ }
+}
+
+func TestFormatPages(t *testing.T) {
+ cases := map[string]struct {
+ in []int
+ want string
+ }{
+ "single": {[]int{2}, "2"},
+ "run": {[]int{1, 2, 3}, "1-3"},
+ "mixed": {[]int{1, 3, 4, 5, 9}, "1,3-5,9"},
+ "unsorted": {[]int{4, 1, 2}, "1-2,4"},
+ "two apart": {[]int{1, 3}, "1,3"},
+ }
+ for name, c := range cases {
+ if got := formatPages(c.in); got != c.want {
+ t.Errorf("%s: formatPages(%v) = %q, want %q", name, c.in, got, c.want)
+ }
+ }
+}