aboutsummaryrefslogtreecommitdiff
path: root/cmd/lectio-ui/main_test.go
blob: 284fc67805917696b88548f1e2318818505591f5 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package main

import (
	"bytes"
	"strings"
	"testing"
)

func TestHelpFlag(t *testing.T) {
	var out, errb bytes.Buffer
	if code := run([]string{"-h"}, &out, &errb); code != 0 {
		t.Errorf("-h code=%d (stderr=%q)", code, errb.String())
	}
	if !strings.Contains(out.String(), "lectio-ui") {
		t.Errorf("-h output missing lectio-ui: %q", out.String())
	}
}

func TestHelpLongFlag(t *testing.T) {
	var out, errb bytes.Buffer
	if code := run([]string{"--help"}, &out, &errb); code != 0 {
		t.Errorf("--help code=%d (stderr=%q)", code, errb.String())
	}
	if !strings.Contains(out.String(), "lectio-ui") {
		t.Errorf("--help output missing lectio-ui: %q", out.String())
	}
}

func TestVersionFlag(t *testing.T) {
	var out, errb bytes.Buffer
	if code := run([]string{"-v"}, &out, &errb); code != 0 {
		t.Errorf("-v code=%d (stderr=%q)", code, errb.String())
	}
	if !strings.Contains(out.String(), "lectio-ui") {
		t.Errorf("-v output missing lectio-ui: %q", out.String())
	}
}

func TestVersionLongFlag(t *testing.T) {
	var out, errb bytes.Buffer
	if code := run([]string{"--version"}, &out, &errb); code != 0 {
		t.Errorf("--version code=%d (stderr=%q)", code, errb.String())
	}
	if !strings.Contains(out.String(), "lectio-ui") {
		t.Errorf("--version output missing lectio-ui: %q", out.String())
	}
}

func TestUnknownFlag(t *testing.T) {
	t.Setenv("XDG_CONFIG_HOME", t.TempDir())
	var out, errb bytes.Buffer
	if code := run([]string{"-x"}, &out, &errb); code != 2 {
		t.Errorf("-x code=%d want 2 (stderr=%q)", code, errb.String())
	}
}

func TestUnknownLongFlag(t *testing.T) {
	t.Setenv("XDG_CONFIG_HOME", t.TempDir())
	var out, errb bytes.Buffer
	if code := run([]string{"--bogus"}, &out, &errb); code != 2 {
		t.Errorf("--bogus code=%d want 2 (stderr=%q)", code, errb.String())
	}
}

func TestUnexpectedPositional(t *testing.T) {
	t.Setenv("XDG_CONFIG_HOME", t.TempDir())
	var out, errb bytes.Buffer
	if code := run([]string{"bogus"}, &out, &errb); code != 2 {
		t.Errorf("unexpected positional code=%d want 2 (stderr=%q)", code, errb.String())
	}
}

func TestTwoDatesIsAmbiguous(t *testing.T) {
	t.Setenv("XDG_CONFIG_HOME", t.TempDir())
	var out, errb bytes.Buffer
	if code := run([]string{"2026-07-22", "2026-07-23"}, &out, &errb); code != 2 {
		t.Errorf("two dates code=%d want 2 (stderr=%q)", code, errb.String())
	}
}

func TestLectionaryBogus(t *testing.T) {
	t.Setenv("XDG_CONFIG_HOME", t.TempDir())
	var out, errb bytes.Buffer
	if code := run([]string{"-l", "bogus"}, &out, &errb); code != 2 {
		t.Errorf("bogus lectionary code=%d want 2 (stderr=%q)", code, errb.String())
	}
}

func TestLangBogus(t *testing.T) {
	t.Setenv("XDG_CONFIG_HOME", t.TempDir())
	var out, errb bytes.Buffer
	if code := run([]string{"-g", "xx"}, &out, &errb); code != 2 {
		t.Errorf("bogus lang code=%d want 2 (stderr=%q)", code, errb.String())
	}
}

func TestBibleVersionBogus(t *testing.T) {
	t.Setenv("XDG_CONFIG_HOME", t.TempDir())
	var out, errb bytes.Buffer
	if code := run([]string{"-b", "zzz"}, &out, &errb); code != 2 {
		t.Errorf("bogus bible version code=%d want 2 (stderr=%q)", code, errb.String())
	}
}