-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcatalog_test.go
71 lines (59 loc) · 1.92 KB
/
catalog_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
package ffcss
import (
"path/filepath"
"sort"
"testing"
"github.com/stretchr/testify/assert"
)
func makeTheme(name string) Theme {
t := NewTheme()
t.ExplicitName = name
return t
}
func TestCatalogLookup(t *testing.T) {
catalog := Catalog{
"lorem": makeTheme("lorem"),
"ipsum": makeTheme("ipsum"),
"dolor": makeTheme("a_completely_different_name"),
"bacon": makeTheme("bacon"),
}
actual, err := catalog.Lookup("lorem")
assert.NoError(t, err)
assert.Equal(t, makeTheme("lorem"), actual)
actual, err = catalog.Lookup("a.completely different-name")
assert.NoError(t, err)
assert.Equal(t, makeTheme("a_completely_different_name"), actual)
actual, err = catalog.Lookup("dolor")
assert.Error(t, err, `theme "dolor" not found`)
assert.Equal(t, Theme{}, actual)
actual, err = catalog.Lookup("baaaa con")
assert.Error(t, err, `theme "baaaa con" not found. did you mean [blue][bold]bacon[reset]?`)
assert.Equal(t, Theme{}, actual)
}
func TestLookupPreprocess(t *testing.T) {
cases := []struct{ in, out string }{
{"same", "same"},
{"B O N K", "bonk"},
{"you. shall. not. pass.", "youshallnotpass"},
{"wHaTevER", "whatever"},
{"all-thE.puncT_uAtio n", "allthepunctuation"},
{"with great power\u037e comes great responsibility.", "withgreatpower;comesgreatresponsibility"},
{"𝔽𝔸ℕℂ𝕐", "fancy"},
}
for _, caze := range cases {
assert.Equal(t, caze.out, lookupPreprocess(caze.in))
}
}
func TestLoadCatalog(t *testing.T) {
actual, err := LoadCatalog(filepath.Join(testarea, "catalogs/empty"))
assert.NoError(t, err)
assert.Equal(t, make(Catalog), actual)
actual, err = LoadCatalog(filepath.Join(testarea, "catalogs/various"))
assert.NoError(t, err)
actualNames := make([]string, 0, len(actual))
for name := range actual {
actualNames = append(actualNames, name)
}
sort.Strings(actualNames)
assert.Equal(t, []string{"alpenblue", "flyingfox", "montereyfox", "sometheme"}, actualNames)
}