forked from ktr0731/go-fuzzyfinder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mock_test.go
130 lines (125 loc) · 3.01 KB
/
mock_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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package fuzzyfinder
import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/nsf/termbox-go"
)
func Test_parseAttr(t *testing.T) {
cases := map[string]struct {
attr termbox.Attribute
isFg bool
expected string
willPanic bool
}{
"ColorDefault": {
attr: termbox.ColorDefault,
isFg: true,
expected: "\x1b[39m",
},
"ColorDefault bg": {
attr: termbox.ColorDefault,
expected: "\x1b[49m",
},
"ColorGreen": {
attr: termbox.ColorGreen,
expected: "\x1b[48;5;2m",
},
"ColorGreen with bold": {
attr: termbox.ColorGreen | termbox.AttrBold,
expected: "\x1b[1;48;5;2m",
},
"ColorGreen with bold and underline": {
attr: termbox.ColorGreen | termbox.AttrBold | termbox.AttrUnderline,
expected: "\x1b[4;1;48;5;2m",
},
"ColorGreen with reverse": {
attr: termbox.ColorGreen | termbox.AttrReverse,
expected: "\x1b[7;48;5;2m",
},
"invalid color": {
attr: termbox.ColorWhite + 1,
willPanic: true,
},
}
for name, c := range cases {
c := c
t.Run(name, func(t *testing.T) {
if c.willPanic {
defer func() {
if err := recover(); err == nil {
t.Errorf("must panic")
}
}()
}
actual := parseAttr(c.attr, c.isFg)
if diff := cmp.Diff(c.expected, actual); diff != "" {
t.Errorf("diff found: \n%s\nexpected = %x, actual = %x", diff, c.expected, actual)
}
})
}
}
// func Test_parseAttrV2(t *testing.T) {
// cases := map[string]struct {
// attr tcell.AttrMask
// fg tcell.Color
// bg tcell.Color
// isBg bool
// expected string
// willPanic bool
// }{
// "ColorDefault": {
// fg: tcell.ColorDefault,
// expected: "\x1b[39m",
// },
// "ColorDefault bg": {
// bg: tcell.ColorDefault,
// isBg: true,
// expected: "\x1b[49m",
// },
// "ColorGreen": {
// fg: tcell.ColorGreen,
// expected: "\x1b[38;5;2m",
// },
// "ColorGreen with bold": {
// attr: tcell.AttrBold,
// fg: tcell.ColorGreen,
// expected: "\x1b[1;38;5;2m",
// },
// "ColorGreen with bold and underline": {
// attr: tcell.AttrBold | tcell.AttrUnderline,
// fg: tcell.ColorGreen,
// expected: "\x1b[1;4;38;5;2m",
// },
// "ColorGreen with reverse": {
// attr: tcell.AttrReverse,
// fg: tcell.ColorGreen,
// expected: "\x1b[7;38;5;2m",
// },
// "invalid color": {
// attr: tcell.AttrInvalid,
// willPanic: true,
// },
// }
//
// for name, c := range cases {
// c := c
// t.Run(name, func(t *testing.T) {
// if c.willPanic {
// defer func() {
// if err := recover(); err == nil {
// t.Errorf("must panic")
// }
// }()
// }
// var actual string
// if c.isBg {
// actual = parseAttrV2(nil, &c.bg, c.attr)
// } else {
// actual = parseAttrV2(&c.fg, nil, c.attr)
// }
// if diff := cmp.Diff(c.expected, actual); diff != "" {
// t.Errorf("diff found: \n%s\nexpected = %x, actual = %x", diff, c.expected, actual)
// }
// })
// }
// }