-
Notifications
You must be signed in to change notification settings - Fork 30
/
keymaps_test.go
52 lines (38 loc) · 1.59 KB
/
keymaps_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
package keymaps_test
import (
ansi "clx/utils/strip-ansi"
"testing"
"clx/keymaps"
"github.com/stretchr/testify/assert"
)
func TestKeymaps(t *testing.T) {
t.Parallel()
keys := new(keymaps.List)
keys.Init()
keys.AddHeader("Header")
keys.AddSeparator()
keys.AddKeymap("Very long description", "x")
keys.AddKeymap("Separate item", "xyz")
keys.AddSeparator()
keys.AddKeymap("Add item", "x")
keys.AddKeymap("Delete item", "x")
keys.AddSeparator()
keys.AddHeader("Header")
keys.AddSeparator()
keys.AddKeymap("Delete item", "x")
keys.AddKeymap("Item", "a + b")
actual := keys.Print(80)
expected := ` Header
[1mx[0m[2m ........................................................ [0mVery long description
[1mxyz[0m[2m .............................................................. [0mSeparate item
[1mx[0m[2m ..................................................................... [0mAdd item
[1mx[0m[2m .................................................................. [0mDelete item
Header
[1mx[0m[2m .................................................................. [0mDelete item
[1ma + b[0m[2m ..................................................................... [0mItem
`
// Workaround for a bug where lipgloss does not render ansi formatting during testing
// Possibly related to https://github.com/charmbracelet/lipgloss/issues/176
expectedWithoutAnsi := ansi.Strip(expected)
assert.Equal(t, expectedWithoutAnsi, actual)
}