aboutsummaryrefslogtreecommitdiff
path: root/main_test.go
blob: 680e821474853f613941ead0b2000298c4a7217d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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)
	}
}