aboutsummaryrefslogtreecommitdiff
path: root/main_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 /main_test.go
downloadpdfstamp-master.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 'main_test.go')
-rw-r--r--main_test.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/main_test.go b/main_test.go
new file mode 100644
index 0000000..680e821
--- /dev/null
+++ b/main_test.go
@@ -0,0 +1,46 @@
+package main
+
+import "testing"
+
+func TestParsePickArgs(t *testing.T) {
+ ok := map[string]struct {
+ args []string
+ input string
+ plan string
+ }{
+ "input only": {[]string{"in.pdf"}, "in.pdf", ""},
+ "input with -o": {[]string{"in.pdf", "-o", "p.json"}, "in.pdf", "p.json"},
+ "-o before input": {[]string{"-o", "p.json", "in.pdf"}, "in.pdf", "p.json"},
+ }
+ for name, c := range ok {
+ input, plan, err := parsePickArgs(c.args)
+ if err != nil {
+ t.Errorf("%s: unexpected error: %v", name, err)
+ continue
+ }
+ if input != c.input || plan != c.plan {
+ t.Errorf("%s: got input=%q plan=%q, want %q %q", name, input, plan, c.input, c.plan)
+ }
+ }
+
+ bad := map[string][]string{
+ "no args": {},
+ "missing -o value": {"in.pdf", "-o"},
+ "unknown option": {"in.pdf", "-x"},
+ "extra positional": {"in.pdf", "extra.json"},
+ }
+ for name, args := range bad {
+ if _, _, err := parsePickArgs(args); err == nil {
+ t.Errorf("%s: expected error, got nil", name)
+ }
+ }
+}
+
+func TestTerminalText(t *testing.T) {
+ if got, want := terminalText("safe café"), "safe café"; got != want {
+ t.Errorf("terminalText safe text = %q, want %q", got, want)
+ }
+ if got, want := terminalText("a\nb\x1b\u0085"), "a?b??"; got != want {
+ t.Errorf("terminalText controls = %q, want %q", got, want)
+ }
+}