-
Notifications
You must be signed in to change notification settings - Fork 151
/
addenda12_test.go
304 lines (265 loc) · 10.2 KB
/
addenda12_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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
// Licensed to The Moov Authors under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. The Moov Authors licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package ach
import (
"testing"
"github.com/moov-io/base"
)
// mockAddenda12 creates a mock Addenda12 record
func mockAddenda12() *Addenda12 {
addenda12 := NewAddenda12()
addenda12.OriginatorCityStateProvince = "JacobsTown*PA\\"
addenda12.OriginatorCountryPostalCode = "US*19305\\"
addenda12.EntryDetailSequenceNumber = 00000001
return addenda12
}
// TestMockAddenda12 validates mockAddenda12
func TestMockAddenda12(t *testing.T) {
addenda12 := mockAddenda12()
if err := addenda12.Validate(); err != nil {
t.Error("mockAddenda12 does not validate and will break other tests")
}
}
// testAddenda12Parse parses Addenda12 record
func testAddenda12Parse(t testing.TB) {
Addenda12 := NewAddenda12()
line := "712" + "JacobsTown*PA\\ " + "US*19305\\ " + "0000001"
Addenda12.Parse(line)
// walk the Addenda12 struct
if Addenda12.TypeCode != "12" {
t.Errorf("expected %v got %v", "12", Addenda12.TypeCode)
}
if Addenda12.OriginatorCityStateProvince != "JacobsTown*PA\\" {
t.Errorf("expected %v got %v", "JacobsTown*PA\\", Addenda12.OriginatorCityStateProvince)
}
if Addenda12.OriginatorCountryPostalCode != "US*19305\\" {
t.Errorf("expected: %v got: %v", "US*19305\\", Addenda12.OriginatorCountryPostalCode)
}
if Addenda12.EntryDetailSequenceNumber != 0000001 {
t.Errorf("expected: %v got: %v", 0000001, Addenda12.EntryDetailSequenceNumber)
}
}
// TestAddenda12Parse tests parsing Addenda12 record
func TestAddenda12Parse(t *testing.T) {
testAddenda12Parse(t)
}
// BenchmarkAddenda12Parse benchmarks parsing Addenda12 record
func BenchmarkAddenda12Parse(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda12Parse(b)
}
}
// testAddenda12ValidTypeCode validates Addenda12 TypeCode
func testAddenda12ValidTypeCode(t testing.TB) {
addenda12 := mockAddenda12()
addenda12.TypeCode = "65"
err := addenda12.Validate()
if !base.Match(err, ErrAddendaTypeCode) {
t.Errorf("%T: %s", err, err)
}
}
// TestAddenda12ValidTypeCode tests validating Addenda12 TypeCode
func TestAddenda12ValidTypeCode(t *testing.T) {
testAddenda12ValidTypeCode(t)
}
// BenchmarkAddenda12ValidTypeCode benchmarks validating Addenda12 TypeCode
func BenchmarkAddenda12ValidTypeCode(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda12ValidTypeCode(b)
}
}
// testAddenda12TypeCode12 TypeCode is 12 if TypeCode is a valid TypeCode
func testAddenda12TypeCode12(t testing.TB) {
addenda12 := mockAddenda12()
addenda12.TypeCode = "05"
err := addenda12.Validate()
if !base.Match(err, ErrAddendaTypeCode) {
t.Errorf("%T: %s", err, err)
}
}
// TestAddenda12TypeCode12 tests TypeCode is 12 if TypeCode is a valid TypeCode
func TestAddenda12TypeCode12(t *testing.T) {
testAddenda12TypeCode12(t)
}
// BenchmarkAddenda12TypeCode12 benchmarks TypeCode is 12 if TypeCode is a valid TypeCode
func BenchmarkAddenda12TypeCode12(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda12TypeCode12(b)
}
}
// testOriginatorCityStateProvinceAlphaNumeric validates OriginatorCityStateProvince is alphanumeric
func testOriginatorCityStateProvinceAlphaNumeric(t testing.TB) {
addenda12 := mockAddenda12()
addenda12.OriginatorCityStateProvince = "Jacobs®Town*PA"
err := addenda12.Validate()
if !base.Match(err, ErrNonAlphanumeric) {
t.Errorf("%T: %s", err, err)
}
}
// TestOriginatorCityStateProvinceAlphaNumeric tests validating OriginatorCityStateProvince is alphanumeric
func TestOriginatorCityStateProvinceAlphaNumeric(t *testing.T) {
testOriginatorCityStateProvinceAlphaNumeric(t)
}
// BenchmarkOriginatorCityStateProvinceAlphaNumeric benchmarks validating OriginatorCityStateProvince is alphanumeric
func BenchmarkOriginatorCityStateProvinceAlphaNumeric(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testOriginatorCityStateProvinceAlphaNumeric(b)
}
}
// testOriginatorCountryPostalCodeAlphaNumeric validates OriginatorCountryPostalCode is alphanumeric
func testOriginatorCountryPostalCodeAlphaNumeric(t testing.TB) {
addenda12 := mockAddenda12()
addenda12.OriginatorCountryPostalCode = "US19®305"
err := addenda12.Validate()
if !base.Match(err, ErrNonAlphanumeric) {
t.Errorf("%T: %s", err, err)
}
}
// TestOriginatorCountryPostalCodeAlphaNumeric tests validating OriginatorCountryPostalCode is alphanumeric
func TestOriginatorCountryPostalCodeAlphaNumeric(t *testing.T) {
testOriginatorCountryPostalCodeAlphaNumeric(t)
}
// BenchmarkOriginatorCountryPostalCodeAlphaNumeric benchmarks validating OriginatorCountryPostalCode is alphanumeric
func BenchmarkOriginatorCountryPostalCodeAlphaNumeric(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testOriginatorCountryPostalCodeAlphaNumeric(b)
}
}
// testAddenda12FieldInclusionTypeCode validates TypeCode fieldInclusion
func testAddenda12FieldInclusionTypeCode(t testing.TB) {
addenda12 := mockAddenda12()
addenda12.TypeCode = ""
err := addenda12.Validate()
if !base.Match(err, ErrConstructor) {
t.Errorf("%T: %s", err, err)
}
}
// TestAddenda12FieldInclusionTypeCode tests validating TypeCode fieldInclusion
func TestAddenda12FieldInclusionTypeCode(t *testing.T) {
testAddenda12FieldInclusionTypeCode(t)
}
// BenchmarkAddenda12FieldInclusionTypeCode benchmarks validating TypeCode fieldInclusion
func BenchmarkAddenda12FieldInclusionTypeCode(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda12FieldInclusionTypeCode(b)
}
}
// testAddenda12FieldInclusionOriginatorCityStateProvince validates OriginatorCityStateProvince fieldInclusion
func testAddenda12FieldInclusionOriginatorCityStateProvince(t testing.TB) {
addenda12 := mockAddenda12()
addenda12.OriginatorCityStateProvince = ""
err := addenda12.Validate()
if !base.Match(err, ErrConstructor) {
t.Errorf("%T: %s", err, err)
}
}
// TestAddenda12FieldInclusionOriginatorCityStateProvince tests validating OriginatorCityStateProvince fieldInclusion
func TestAddenda12FieldInclusionOriginatorCityStateProvince(t *testing.T) {
testAddenda12FieldInclusionOriginatorCityStateProvince(t)
}
// BenchmarkAddenda12FieldInclusionOriginatorCityStateProvince benchmarks validating OriginatorCityStateProvince fieldInclusion
func BenchmarkAddenda12FieldInclusionOriginatorCityStateProvince(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda12FieldInclusionOriginatorCityStateProvince(b)
}
}
// testAddenda12FieldInclusionOriginatorCountryPostalCode validates OriginatorCountryPostalCode fieldInclusion
func testAddenda12FieldInclusionOriginatorCountryPostalCode(t testing.TB) {
addenda12 := mockAddenda12()
addenda12.OriginatorCountryPostalCode = ""
err := addenda12.Validate()
if !base.Match(err, ErrConstructor) {
t.Errorf("%T: %s", err, err)
}
}
// TestAddenda12FieldInclusionOriginatorCountryPostalCode tests validating OriginatorCountryPostalCode fieldInclusion
func TestAddenda12FieldInclusionOriginatorCountryPostalCode(t *testing.T) {
testAddenda12FieldInclusionOriginatorCountryPostalCode(t)
}
// BenchmarkAddenda12FieldInclusionOriginatorCountryPostalCode benchmarks validating OriginatorCountryPostalCode fieldInclusion
func BenchmarkAddenda12FieldInclusionOriginatorCountryPostalCode(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda12FieldInclusionOriginatorCountryPostalCode(b)
}
}
// testAddenda12FieldInclusionEntryDetailSequenceNumber validates EntryDetailSequenceNumber fieldInclusion
func testAddenda12FieldInclusionEntryDetailSequenceNumber(t testing.TB) {
addenda12 := mockAddenda12()
addenda12.EntryDetailSequenceNumber = 0
err := addenda12.Validate()
if !base.Match(err, ErrConstructor) {
t.Errorf("%T: %s", err, err)
}
}
// TestAddenda12FieldInclusionEntryDetailSequenceNumber tests validating
// EntryDetailSequenceNumber fieldInclusion
func TestAddenda12FieldInclusionEntryDetailSequenceNumber(t *testing.T) {
testAddenda12FieldInclusionEntryDetailSequenceNumber(t)
}
// BenchmarkAddenda12FieldInclusionEntryDetailSequenceNumber benchmarks validating
// EntryDetailSequenceNumber fieldInclusion
func BenchmarkAddenda12FieldInclusionEntryDetailSequenceNumber(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda12FieldInclusionEntryDetailSequenceNumber(b)
}
}
// TestAddenda12String validates that a known parsed Addenda12 record can be return to a string of the same value
func testAddenda12String(t testing.TB) {
addenda12 := NewAddenda12()
// Backslash logic
var line = "712" +
"JacobsTown*PA\\ " +
"US*19305\\ " +
" " +
"0000001"
addenda12.Parse(line)
if addenda12.String() != line {
t.Errorf("Strings do not match")
}
if addenda12.TypeCode != "12" {
t.Errorf("TypeCode Expected 12 got: %v", addenda12.TypeCode)
}
}
// TestAddenda12String tests validating that a known parsed Addenda12 record can be return to a string of the same value
func TestAddenda12String(t *testing.T) {
testAddenda12String(t)
}
// BenchmarkAddenda12String benchmarks validating that a known parsed Addenda12 record can be return to a string of the same value
func BenchmarkAddenda12String(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testAddenda12String(b)
}
}
// TestAddenda12RuneCountInString validates RuneCountInString
func TestAddenda12RuneCountInString(t *testing.T) {
addenda12 := NewAddenda12()
var line = "712" + "JacobsTown*PA\\ " + "US*19305\\ "
addenda12.Parse(line)
if addenda12.OriginatorCountryPostalCode != "" {
t.Error("Parsed with an invalid RuneCountInString not equal to 94")
}
}