-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser_test.go
116 lines (103 loc) · 4.88 KB
/
parser_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
package fedach
import (
"reflect"
"testing"
)
func TestUnmarshalToStruct(t *testing.T) {
cases := []struct {
input []byte
ExpectedOutput []RoutingDirectoryRecord
ExpectedErr error
}{
{[]byte(`011000015O0110000150122415000000000FEDERAL RESERVE BANK 1000 PEACHTREE ST N.E. ATLANTA GA303094470877372245711 `), []RoutingDirectoryRecord{{"011000015", "O", "011000015", "0", "122415", "000000000", "FEDERAL RESERVE BANK ", "1000 PEACHTREE ST N.E. ", "ATLANTA ", "GA", "30309", "4470", "877", "372", "2457", "1", "1", " "}}, nil},
{[]byte(`011000015O0110000150122415000000000FEDERAL RESERVE BANK 1000 PEACHTREE ST N.E. ATLANTA GA303094470877372245711
`), []RoutingDirectoryRecord{{"011000015", "O", "011000015", "0", "122415", "000000000", "FEDERAL RESERVE BANK ", "1000 PEACHTREE ST N.E. ", "ATLANTA ", "GA", "30309", "4470", "877", "372", "2457", "1", "1", " "}}, nil},
}
for _, tc := range cases {
var output []RoutingDirectoryRecord
err := Unmarshal(tc.input, &output)
if err != tc.ExpectedErr {
t.Errorf("Unmarshal func returned wrong error: got %#v want %#v",
err, tc.ExpectedErr)
}
if !reflect.DeepEqual(tc.ExpectedOutput, output) {
t.Errorf("Unmarshal func returned wrong output: got %#v want %#v",
output, tc.ExpectedOutput)
}
}
}
func TestUnmarshalToSlice(t *testing.T) {
cases := []struct {
input []byte
ExpectedOutput [][]string
ExpectedErr error
}{
{[]byte(`011000015O0110000150122415000000000FEDERAL RESERVE BANK 1000 PEACHTREE ST N.E. ATLANTA GA303094470877372245711 `), [][]string{{"011000015", "O", "011000015", "0", "122415", "000000000", "FEDERAL RESERVE BANK ", "1000 PEACHTREE ST N.E. ", "ATLANTA ", "GA", "30309", "4470", "877", "372", "2457", "1", "1", " "}}, nil},
{[]byte(`011000015O0110000150122415000000000FEDERAL RESERVE BANK 1000 PEACHTREE ST N.E. ATLANTA GA303094470877372245711
`), [][]string{{"011000015", "O", "011000015", "0", "122415", "000000000", "FEDERAL RESERVE BANK ", "1000 PEACHTREE ST N.E. ", "ATLANTA ", "GA", "30309", "4470", "877", "372", "2457", "1", "1", " "}}, nil},
}
for _, tc := range cases {
var output [][]string
err := Unmarshal(tc.input, &output)
if err != tc.ExpectedErr {
t.Errorf("Unmarshal func returned wrong error: got %#v want %#v",
err, tc.ExpectedErr)
}
if !reflect.DeepEqual(tc.ExpectedOutput, output) {
t.Errorf("Unmarshal func returned wrong output: got %#v want %#v",
output, tc.ExpectedOutput)
}
}
}
func TestMarshal(t *testing.T) {
cases := []struct {
input []RoutingDirectoryRecord
ExpectedOutput []byte
ExpectedErr error
}{
{[]RoutingDirectoryRecord{{"011000015", "O", "011000015", "0", "122415", "000000000", "FEDERAL RESERVE BANK ", "1000 PEACHTREE ST N.E. ", "ATLANTA ", "GA", "30309", "4470", "877", "372", "2457", "1", "1", " "}}, []byte(`011000015O0110000150122415000000000FEDERAL RESERVE BANK 1000 PEACHTREE ST N.E. ATLANTA GA303094470877372245711 `), nil},
}
for _, tc := range cases {
output, err := Marshal(tc.input)
if err != tc.ExpectedErr {
t.Errorf("Marshal func returned wrong error: got %#v want %#v",
err, tc.ExpectedErr)
}
if !reflect.DeepEqual(tc.ExpectedOutput, output) {
t.Errorf("Unmarshal func returned wrong output: got %s want %s\n, output length: %d ExpectedOutput length: %d",
output, tc.ExpectedOutput, len(output), len(tc.ExpectedOutput))
}
}
}
func TestSymmetryStruct(t *testing.T) {
cases := []struct {
input []byte
}{
{[]byte(`011000015O0110000150122415000000000FEDERAL RESERVE BANK 1000 PEACHTREE ST N.E. ATLANTA GA303094470877372245711 `)},
}
for _, tc := range cases {
var um []RoutingDirectoryRecord
Unmarshal(tc.input, &um)
output, _ := Marshal(um)
if !reflect.DeepEqual(tc.input, output) {
t.Errorf("Unmarshal func returned wrong output: got %s want %s\n, output length: %d input length: %d",
output, tc.input, len(output), len(tc.input))
}
}
}
func TestSymmetryStringSlice(t *testing.T) {
cases := []struct {
input []byte
}{
{[]byte(`011000015O0110000150122415000000000FEDERAL RESERVE BANK 1000 PEACHTREE ST N.E. ATLANTA GA303094470877372245711 `)},
}
for _, tc := range cases {
var um [][]string
Unmarshal(tc.input, &um)
output, _ := Marshal(um)
if !reflect.DeepEqual(tc.input, output) {
t.Errorf("Unmarshal func returned wrong output: got %s want %s\n, output length: %d input length: %d",
output, tc.input, len(output), len(tc.input))
}
}
}