-
Notifications
You must be signed in to change notification settings - Fork 255
/
themes_test.go
84 lines (80 loc) · 1.75 KB
/
themes_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
package main
import (
"errors"
"reflect"
"sort"
"testing"
)
func TestFindAllThemes(t *testing.T) {
themes, err := sortedThemeNames()
if err != nil {
t.Fatal(err)
}
expect := 348
if l := len(themes); l != expect {
t.Errorf("expected to load %d themes, got %d", expect, l)
}
}
func TestFindTheme(t *testing.T) {
tests := []struct {
tname string
theme string
err error
}{
{
tname: "exact match",
theme: "Catppuccin Latte",
err: nil,
},
{
tname: "match found",
theme: "caTppuccin ltt",
err: ThemeNotFoundError{"caTppuccin ltt", []string{"Catppuccin Latte"}},
},
{
tname: "no match found",
theme: "stArf1sh",
err: ThemeNotFoundError{"stArf1sh", []string{}},
},
{
tname: "single char",
theme: "s",
err: ThemeNotFoundError{"s", []string{}},
},
{
tname: "empty string",
theme: "",
err: ThemeNotFoundError{"", []string{}},
},
}
for _, tc := range tests {
t.Run(tc.tname, func(t *testing.T) {
_, err := findTheme(tc.theme)
if tc.err != nil {
if err == nil {
t.Fatal("expected an error:", tc.err)
}
// check we got the right error
var perr ThemeNotFoundError
if !errors.As(err, &perr) {
t.Fatal(err)
}
gotErr := err.(ThemeNotFoundError)
wantErr := tc.err.(ThemeNotFoundError)
// check suggestions
sort.Strings(gotErr.Suggestions)
sort.Strings(wantErr.Suggestions)
if !reflect.DeepEqual(gotErr.Suggestions, wantErr.Suggestions) {
t.Fatalf("got != want. got: %v, want: %v", err, tc.err)
}
// check names
if !reflect.DeepEqual(gotErr.Theme, wantErr.Theme) {
t.Fatalf("got != want. got: %v, want: %v", err, tc.err)
}
}
if err != nil && tc.err == nil {
t.Fatal("unexpected error:", err)
}
})
}
}