-
Notifications
You must be signed in to change notification settings - Fork 43
/
cstr_test.go
103 lines (96 loc) · 1.88 KB
/
cstr_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
package bbs
import (
"reflect"
"testing"
)
func TestCstrToBytes(t *testing.T) {
str1 := [13]byte{}
str2 := [13]byte{}
copy(str2[:], []byte("123"))
str3 := [10]byte{}
copy(str3[:], []byte("0123456789"))
str4 := [10]byte{}
copy(str4[:], []byte("01234\x006789"))
type args struct {
cstr Cstr
}
tests := []struct {
name string
args args
expected []byte
}{
{
name: "init",
args: args{str1[:]},
expected: []byte{},
},
{
name: "with only 3 letters",
args: args{str2[:]},
expected: []byte("123"),
},
{
name: "with no 0",
args: args{str3[:]},
expected: []byte("0123456789"),
},
{
name: "cutoff at str4[5]",
args: args{str4[:]},
expected: []byte("01234"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := CstrToBytes(tt.args.cstr); !reflect.DeepEqual(got, tt.expected) {
t.Errorf("CstrToBytes() = %v, expected %v", got, tt.expected)
}
})
}
}
func TestCstrToString(t *testing.T) {
str1 := [13]byte{}
str2 := [13]byte{}
copy(str2[:], []byte("123"))
str3 := [10]byte{}
copy(str3[:], []byte("0123456789"))
str4 := [10]byte{}
copy(str4[:], []byte("01234\x006789"))
type args struct {
cstr Cstr
}
tests := []struct {
name string
args args
expected string
}{
// TODO: Add test cases.
{
name: "init",
args: args{str1[:]},
expected: "",
},
{
name: "with only 3 letters",
args: args{str2[:]},
expected: "123",
},
{
name: "with no 0",
args: args{str3[:]},
expected: "0123456789",
},
{
name: "cutoff at str4[5]",
args: args{str4[:]},
expected: "01234",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := CstrToString(tt.args.cstr); got != tt.expected {
t.Errorf("CstrToString() = %v, expected %v", got, tt.expected)
}
})
}
}