-
Notifications
You must be signed in to change notification settings - Fork 265
/
command_test.go
94 lines (84 loc) · 2.4 KB
/
command_test.go
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
package main
import (
"reflect"
"testing"
"github.com/charmbracelet/vhs/parser"
)
func TestCommand(t *testing.T) {
const numberOfCommands = 29
if len(parser.CommandTypes) != numberOfCommands {
t.Errorf("Expected %d commands, got %d", numberOfCommands, len(parser.CommandTypes))
}
const numberOfCommandFuncs = 29
if len(CommandFuncs) != numberOfCommandFuncs {
t.Errorf("Expected %d commands, got %d", numberOfCommandFuncs, len(CommandFuncs))
}
}
func TestExecuteSetTheme(t *testing.T) {
t.Run("empty", func(t *testing.T) {
theme, err := getTheme(" ")
requireNoErr(t, err)
requireDefaultTheme(t, theme)
})
t.Run("named", func(t *testing.T) {
theme, err := getTheme("Andromeda")
requireNoErr(t, err)
requireNotDefaultTheme(t, theme)
})
t.Run("json", func(t *testing.T) {
theme, err := getTheme(`{"background": "#29283b"}`)
requireNoErr(t, err)
requireNotDefaultTheme(t, theme)
if "#29283b" != theme.Background {
t.Errorf("wrong background, expected %q, got %q", "#29283b", theme.Background)
}
})
t.Run("suggestion", func(t *testing.T) {
theme, err := getTheme("cattppuccin latt")
requireEqualErr(t, err, "invalid `Set Theme \"cattppuccin latt\"`: did you mean \"Catppuccin Latte\"")
requireDefaultTheme(t, theme)
})
t.Run("invalid json", func(t *testing.T) {
theme, err := getTheme(`{"background`)
requireErr(t, err)
requireDefaultTheme(t, theme)
})
t.Run("unknown theme", func(t *testing.T) {
theme, err := getTheme("foobar")
requireErr(t, err)
requireDefaultTheme(t, theme)
})
}
func requireErr(tb testing.TB, err error) {
tb.Helper()
if err == nil {
tb.Fatalf("expected an error, got nil")
}
}
func requireEqualErr(tb testing.TB, err1 error, err2 string) {
tb.Helper()
if err1 == nil {
tb.Fatalf("expected an error, got nil")
}
if err1.Error() != err2 {
tb.Fatalf("errors do not match: %q != %q", err1.Error(), err2)
}
}
func requireNoErr(tb testing.TB, err error) {
tb.Helper()
if err != nil {
tb.Fatalf("expected no error, got: %v", err)
}
}
func requireDefaultTheme(tb testing.TB, theme Theme) {
tb.Helper()
if !reflect.DeepEqual(DefaultTheme, theme) {
tb.Fatalf("expected theme to be the default theme, got something else: %+v", theme)
}
}
func requireNotDefaultTheme(tb testing.TB, theme Theme) {
tb.Helper()
if reflect.DeepEqual(DefaultTheme, theme) {
tb.Fatalf("expected theme to be different from the default theme, got the default instead")
}
}