-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmessage_test.go
68 lines (66 loc) · 1.73 KB
/
message_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
package lcm
import (
"fmt"
"testing"
)
func TestSetDisplay(t *testing.T) {
type args struct {
line DisplayLine
indent int
text string
}
tests := []struct {
name string
args args
wantRaw string
wantErr bool
}{
{
name: "Test spaces",
args: args{line: DisplayTop, indent: 0, text: " "},
wantRaw: "0xf01227000020202020202020202020202020202020",
},
{
name: "Test spaces (padding)",
args: args{line: DisplayTop, indent: 0, text: ""},
wantRaw: "0xf01227000020202020202020202020202020202020",
},
{
name: "Test text",
args: args{line: DisplayTop, indent: 0, text: "PRESS ANY KEY TO"},
wantRaw: "0xf012270000505245535320414e59204b455920544f",
},
{
name: "Test text indent",
args: args{line: DisplayTop, indent: 2, text: "PRESS ANY KEY TO"},
wantRaw: "0xf012270002505245535320414e59204b455920544f",
},
{
name: "Test text too long",
args: args{line: DisplayTop, indent: 0, text: "PRESS ANY KEY TO EXPLODE"},
wantErr: true,
},
{
name: "Test indent out of bounds",
args: args{line: DisplayTop, indent: 0xFF, text: "PRESS ANY KEY TO "},
wantErr: true,
},
{
name: "Test display bottom",
args: args{line: DisplayBottom, indent: 0, text: ">"},
wantRaw: "0xf0122701003e202020202020202020202020202020",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotRaw, err := SetDisplay(tt.args.line, tt.args.indent, tt.args.text)
if (err != nil) != tt.wantErr {
t.Errorf("SetDisplay() error = %v, wantErr %v", err, tt.wantErr)
return
}
if err == nil && fmt.Sprintf("%#x", gotRaw) != tt.wantRaw {
t.Errorf("SetDisplay() = %#x, want %s", gotRaw, tt.wantRaw)
}
})
}
}