-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencode_test.go
63 lines (52 loc) · 939 Bytes
/
encode_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
package text_test
import (
"bytes"
"testing"
"github.com/Gophercraft/text"
)
type record1 struct {
ID uint64
Key string
Strings []string
}
type test_case1 struct {
Record1 []record1
EncodedTable string
}
var cases1 = []test_case1{
{
Record1: []record1{
{
ID: 1,
Key: "ABCDEFGHIJKLMNOP",
Strings: []string{
"00",
"01",
"02",
"03",
},
},
},
EncodedTable: `[ ID Key Strings ]
{ 1 ABCDEFGHIJKLMNOP { 00 01 02 03 } }
`,
},
}
func TestEncodeTable(t *testing.T) {
for _, case1 := range cases1 {
var buf bytes.Buffer
encoder := text.NewEncoder(&buf)
encoder.Indent = " "
encoder.Tabular = true
for _, record := range case1.Record1 {
if err := encoder.Encode(&record); err != nil {
t.Fatal(err)
}
}
str := buf.String()
expected := case1.EncodedTable
if str != expected {
t.Fatal(str, "should have been equal to", expected)
}
}
}