-
Notifications
You must be signed in to change notification settings - Fork 5
/
codec_test.go
94 lines (88 loc) · 1.58 KB
/
codec_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
package freedb
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestBasicCodecEncode(t *testing.T) {
tc := []struct {
name string
input string
expected string
}{
{
name: "empty_string",
input: "",
expected: "!",
},
{
name: "non_empty_string",
input: "test",
expected: "!test",
},
{
name: "emoji",
input: "😀",
expected: "!😀",
},
{
name: "NA_value",
input: naValue,
expected: "!" + naValue,
},
}
codec := &basicCodec{}
for _, c := range tc {
t.Run(c.name, func(t *testing.T) {
result, err := codec.Encode([]byte(c.input))
assert.Nil(t, err)
assert.Equal(t, c.expected, result)
})
}
}
func TestBasicCodecDecode(t *testing.T) {
tc := []struct {
name string
input string
expected []byte
hasErr bool
}{
{
name: "empty_string",
input: "",
expected: []byte(nil),
hasErr: true,
},
{
name: "non_empty_string_no_whitespace",
input: "test",
expected: []byte(nil),
hasErr: true,
},
{
name: "non_empty_string",
input: "!test",
expected: []byte("test"),
hasErr: false,
},
{
name: "emoji",
input: "!😀",
expected: []byte("😀"),
hasErr: false,
},
{
name: "NA_value",
input: "!" + naValue,
expected: []byte(naValue),
hasErr: false,
},
}
codec := &basicCodec{}
for _, c := range tc {
t.Run(c.name, func(t *testing.T) {
result, err := codec.Decode(c.input)
assert.Equal(t, c.hasErr, err != nil)
assert.Equal(t, c.expected, result)
})
}
}