Skip to content

Commit a3212b2

Browse files
implemted new field parser functions, updated record parse, format functions
1 parent dd7dc70 commit a3212b2

File tree

114 files changed

+848
-721
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+848
-721
lines changed

Diff for: accountCreditedDrawdown.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (creditDD *AccountCreditedDrawdown) Parse(record string) error {
4343
creditDD.tag = record[:6]
4444
length := 6
4545

46-
value, read, err := creditDD.parseVariableStringField(record[length:], 9)
46+
value, read, err := creditDD.parseFixedStringField(record[length:], 9)
4747
if err != nil {
4848
return fieldError("DrawdownCreditAccountNumber", err)
4949
}
@@ -83,7 +83,7 @@ func (creditDD *AccountCreditedDrawdown) Format(options FormatOptions) string {
8383
var buf strings.Builder
8484
buf.Grow(15)
8585
buf.WriteString(creditDD.tag)
86-
buf.WriteString(creditDD.FormatCreditAccountNumber(options))
86+
buf.WriteString(creditDD.DrawdownCreditAccountNumberField())
8787
return buf.String()
8888
}
8989

Diff for: accountCreditedDrawdown_test.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,28 @@ func TestStringAccountCreditedDrawdownVariableLength(t *testing.T) {
102102
r.line = line
103103

104104
err = r.parseAccountCreditedDrawdown()
105-
expected = r.parseError(fieldError("DrawdownCreditAccountNumber", ErrFieldRequired)).Error()
105+
expected = r.parseError(fieldError("DrawdownCreditAccountNumber", ErrValidLength)).Error()
106106
require.EqualError(t, err, expected)
107107

108108
line = "{5400}1*"
109109
r = NewReader(strings.NewReader(line))
110110
r.line = line
111111

112112
err = r.parseAccountCreditedDrawdown()
113-
require.Equal(t, err, nil)
113+
expected = r.parseError(fieldError("DrawdownCreditAccountNumber", ErrValidLength)).Error()
114+
require.EqualError(t, err, expected)
115+
116+
line = "{5400}1 *"
117+
r = NewReader(strings.NewReader(line))
118+
r.line = line
119+
120+
err = r.parseAccountCreditedDrawdown()
121+
require.NoError(t, err)
114122
}
115123

116124
// TestStringAccountCreditedDrawdownOptions validates Format() formatted according to the FormatOptions
117125
func TestStringAccountCreditedDrawdownOptions(t *testing.T) {
118-
var line = "{5400}1*"
126+
var line = "{5400}1 "
119127
r := NewReader(strings.NewReader(line))
120128
r.line = line
121129

@@ -124,6 +132,6 @@ func TestStringAccountCreditedDrawdownOptions(t *testing.T) {
124132

125133
acd := r.currentFEDWireMessage.AccountCreditedDrawdown
126134
require.Equal(t, acd.String(), "{5400}1 ")
127-
require.Equal(t, acd.Format(FormatOptions{VariableLengthFields: true}), "{5400}1*")
135+
require.Equal(t, acd.Format(FormatOptions{VariableLengthFields: true}), "{5400}1 ")
128136
require.Equal(t, acd.String(), acd.Format(FormatOptions{VariableLengthFields: false}))
129137
}

Diff for: accountDebitedDrawdown.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ func (debitDD *AccountDebitedDrawdown) Format(options FormatOptions) string {
119119

120120
buf.WriteString(debitDD.tag)
121121
buf.WriteString(debitDD.IdentificationCodeField())
122-
buf.WriteString(debitDD.FormatIdentifier(options))
123-
buf.WriteString(debitDD.FormatName(options))
124-
buf.WriteString(debitDD.FormatAddressLineOne(options))
125-
buf.WriteString(debitDD.FormatAddressLineTwo(options))
126-
buf.WriteString(debitDD.FormatAddressLineThree(options))
122+
buf.WriteString(debitDD.FormatIdentifier(options) + Delimiter)
123+
buf.WriteString(debitDD.FormatName(options) + Delimiter)
124+
buf.WriteString(debitDD.FormatAddressLineOne(options) + Delimiter)
125+
buf.WriteString(debitDD.FormatAddressLineTwo(options) + Delimiter)
126+
buf.WriteString(debitDD.FormatAddressLineThree(options) + Delimiter)
127127

128128
if options.VariableLengthFields {
129129
return debitDD.stripDelimiters(buf.String())

Diff for: accountDebitedDrawdown_test.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package wire
22

33
import (
4-
"errors"
54
"strings"
65
"testing"
76

@@ -129,18 +128,18 @@ func TestIdentificationCodeBogus(t *testing.T) {
129128

130129
// TestParseAccountDebitedDrawdownWrongLength parses a wrong AccountDebitedDrawdown record length
131130
func TestParseAccountDebitedDrawdownWrongLength(t *testing.T) {
132-
var line = "{4400}D123456789 debitDD Name Address One Address Two Address Three "
131+
var line = "{4400}D123456789 *debitDD Name *Address One *Address Two *Address Three "
133132
r := NewReader(strings.NewReader(line))
134133
r.line = line
135134

136135
err := r.parseAccountDebitedDrawdown()
137136

138-
require.EqualError(t, err, r.parseError(fieldError("AddressLineThree", ErrValidLength)).Error())
137+
require.EqualError(t, err, r.parseError(fieldError("AddressLineThree", ErrRequireDelimiter)).Error())
139138
}
140139

141140
// TestParseAccountDebitedDrawdownReaderParseError parses a wrong AccountDebitedDrawdown reader parse error
142141
func TestParseAccountDebitedDrawdownReaderParseError(t *testing.T) {
143-
var line = "{4400}D123456789 debitDD ®ame Address One Address Two Address Three "
142+
var line = "{4400}D123456789 *debitDD ®ame *Address One *Address Two *Address Three *"
144143
r := NewReader(strings.NewReader(line))
145144
r.line = line
146145

@@ -175,12 +174,12 @@ func TestStringAccountDebitedDrawdownVariableLength(t *testing.T) {
175174
expected := r.parseError(NewTagMinLengthErr(9, len(r.line))).Error()
176175
require.EqualError(t, err, expected)
177176

178-
line = "{4400}D123456789 debitDD Name Address One Address Two Address Three NNNN"
177+
line = "{4400}D123456789 *debitDD Name *Address One *Address Two *Address Three NNNNNNNN*"
179178
r = NewReader(strings.NewReader(line))
180179
r.line = line
181180

182181
err = r.parseAccountDebitedDrawdown()
183-
require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error())
182+
require.NoError(t, err)
184183

185184
line = "{4400}***"
186185
r = NewReader(strings.NewReader(line))
@@ -208,7 +207,7 @@ func TestStringAccountDebitedDrawdownOptions(t *testing.T) {
208207
require.Equal(t, err, nil)
209208

210209
add := r.currentFEDWireMessage.AccountDebitedDrawdown
211-
require.Equal(t, add.String(), "{4400}D2 3 ")
210+
require.Equal(t, add.String(), "{4400}D2 *3 * * * *")
212211
require.Equal(t, add.Format(FormatOptions{VariableLengthFields: true}), "{4400}D2*3*")
213212
require.Equal(t, add.String(), add.Format(FormatOptions{VariableLengthFields: false}))
214213
}

Diff for: actualAmountPaid.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (aap *ActualAmountPaid) Parse(record string) error {
4343
aap.tag = record[:6]
4444
length := 6
4545

46-
value, read, err := aap.parseVariableStringField(record[length:], 3)
46+
value, read, err := aap.parseFixedStringField(record[length:], 3)
4747
if err != nil {
4848
return fieldError("CurrencyCode", err)
4949
}
@@ -91,8 +91,8 @@ func (aap *ActualAmountPaid) Format(options FormatOptions) string {
9191
buf.Grow(28)
9292

9393
buf.WriteString(aap.tag)
94-
buf.WriteString(aap.FormatCurrencyCode(options))
95-
buf.WriteString(aap.FormatAmount(options))
94+
buf.WriteString(aap.CurrencyCodeField())
95+
buf.WriteString(aap.FormatAmount(options) + Delimiter)
9696

9797
return buf.String()
9898
}

Diff for: actualAmountPaid_test.go

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package wire
22

33
import (
4-
"errors"
54
"strings"
65
"testing"
76

@@ -65,18 +64,17 @@ func TestActualAmountPaidCurrencyCodeValid(t *testing.T) {
6564

6665
// TestParseActualAmountPaidWrongLength parses a wrong ActualAmountPaid record length
6766
func TestParseActualAmountPaidWrongLength(t *testing.T) {
68-
var line = "{8450}USD1234.56 "
67+
var line = "{8450}USD1234.56 *"
6968
r := NewReader(strings.NewReader(line))
7069
r.line = line
7170

7271
err := r.parseActualAmountPaid()
73-
74-
require.EqualError(t, err, r.parseError(fieldError("Amount", ErrValidLength)).Error())
72+
require.NoError(t, err)
7573
}
7674

7775
// TestParseActualAmountPaidReaderParseError parses a wrong ActualAmountPaid reader parse error
7876
func TestParseActualAmountPaidReaderParseError(t *testing.T) {
79-
var line = "{8450}USD1234.56Z "
77+
var line = "{8450}USD1234.56Z *"
8078
r := NewReader(strings.NewReader(line))
8179
r.line = line
8280

@@ -111,21 +109,21 @@ func TestStringActualAmountPaidVariableLength(t *testing.T) {
111109
expected := r.parseError(NewTagMinLengthErr(8, len(r.line))).Error()
112110
require.EqualError(t, err, expected)
113111

114-
line = "{8450}USD1234.56 NNN"
112+
line = "{8450}USD1234.56 NNN*"
115113
r = NewReader(strings.NewReader(line))
116114
r.line = line
117115

118116
err = r.parseActualAmountPaid()
119-
require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error())
117+
require.ErrorContains(t, err, ErrNonAmount.Error())
120118

121119
line = "{8450}****"
122120
r = NewReader(strings.NewReader(line))
123121
r.line = line
124122

125123
err = r.parseActualAmountPaid()
126-
require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error())
124+
require.ErrorContains(t, err, ErrValidLength.Error())
127125

128-
line = "{8450}**"
126+
line = "{8450}USD*"
129127
r = NewReader(strings.NewReader(line))
130128
r.line = line
131129

@@ -151,7 +149,7 @@ func TestStringActualAmountPaidOptions(t *testing.T) {
151149
require.Equal(t, err, nil)
152150

153151
aap := r.currentFEDWireMessage.ActualAmountPaid
154-
require.Equal(t, aap.String(), "{8450}USD1234.56 ")
152+
require.Equal(t, aap.String(), "{8450}USD1234.56 *")
155153
require.Equal(t, aap.Format(FormatOptions{VariableLengthFields: true}), "{8450}USD1234.56*")
156154
require.Equal(t, aap.String(), aap.Format(FormatOptions{VariableLengthFields: false}))
157155
}

Diff for: adjustment.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,21 @@ func (adj *Adjustment) Parse(record string) error {
4949
adj.tag = record[:6]
5050
length := 6
5151

52-
value, read, err := adj.parseVariableStringField(record[length:], 2)
52+
value, read, err := adj.parseFixedStringField(record[length:], 2)
5353
if err != nil {
5454
return fieldError("AdjustmentReasonCode", err)
5555
}
5656
adj.AdjustmentReasonCode = value
5757
length += read
5858

59-
value, read, err = adj.parseVariableStringField(record[length:], 4)
59+
value, read, err = adj.parseFixedStringField(record[length:], 4)
6060
if err != nil {
6161
return fieldError("CreditDebitIndicator", err)
6262
}
6363
adj.CreditDebitIndicator = value
6464
length += read
6565

66-
value, read, err = adj.parseVariableStringField(record[length:], 3)
66+
value, read, err = adj.parseFixedStringField(record[length:], 3)
6767
if err != nil {
6868
return fieldError("CurrencyCode", err)
6969
}
@@ -72,7 +72,7 @@ func (adj *Adjustment) Parse(record string) error {
7272

7373
value, read, err = adj.parseVariableStringField(record[length:], 19)
7474
if err != nil {
75-
return fieldError("CurrencyCode", err)
75+
return fieldError("Amount", err)
7676
}
7777
adj.RemittanceAmount.Amount = value
7878
length += read
@@ -118,11 +118,11 @@ func (adj *Adjustment) Format(options FormatOptions) string {
118118
buf.Grow(168)
119119

120120
buf.WriteString(adj.tag)
121-
buf.WriteString(adj.FormatAdjustmentReasonCode(options))
122-
buf.WriteString(adj.FormatCreditDebitIndicator(options))
123-
buf.WriteString(adj.FormatCurrencyCode(options))
124-
buf.WriteString(adj.FormatAmount(options))
125-
buf.WriteString(adj.FormatAdditionalInfo(options))
121+
buf.WriteString(adj.AdjustmentReasonCodeField())
122+
buf.WriteString(adj.CreditDebitIndicatorField())
123+
buf.WriteString(adj.CurrencyCodeField())
124+
buf.WriteString(adj.FormatAmount(options) + Delimiter)
125+
buf.WriteString(adj.FormatAdditionalInfo(options) + Delimiter)
126126

127127
if options.VariableLengthFields {
128128
return adj.stripDelimiters(buf.String())

Diff for: adjustment_test.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,17 @@ func TestAdjustmentCurrencyCodeRequired(t *testing.T) {
108108

109109
// TestParseAdjustmentWrongLength parses a wrong Adjustment record length
110110
func TestParseAdjustmentWrongLength(t *testing.T) {
111-
var line = "{8600}01CRDTUSD1234.56Z Adjustment Additional Information "
111+
var line = "{8600}01CRDTUSD1234.56 *Additional Information *"
112112
r := NewReader(strings.NewReader(line))
113113
r.line = line
114114

115115
err := r.parseAdjustment()
116-
117-
require.EqualError(t, err, r.parseError(fieldError("AdditionalInfo", ErrValidLength)).Error())
116+
require.NoError(t, err)
118117
}
119118

120119
// TestParseAdjustmentReaderParseError parses a wrong Adjustment reader parse error
121120
func TestParseAdjustmentReaderParseError(t *testing.T) {
122-
var line = "{8600}01CRDTUSD1234.56Z Adjustment Additional Information "
121+
var line = "{8600}01CRDTUSD1234.56Z *Additional Information *"
123122
r := NewReader(strings.NewReader(line))
124123
r.line = line
125124

@@ -159,7 +158,7 @@ func TestStringAdjustmentVariableLength(t *testing.T) {
159158
r.line = line
160159

161160
err = r.parseAdjustment()
162-
require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error())
161+
require.ErrorContains(t, err, ErrRequireDelimiter.Error())
163162

164163
line = "{8600}01CRDTUSD1234.56****"
165164
r = NewReader(strings.NewReader(line))
@@ -186,7 +185,7 @@ func TestStringAdjustmentOptions(t *testing.T) {
186185
require.Equal(t, err, nil)
187186

188187
adj := r.currentFEDWireMessage.Adjustment
189-
require.Equal(t, adj.String(), "{8600}01CRDTUSD1234.56 ")
188+
require.Equal(t, adj.String(), "{8600}01CRDTUSD1234.56 * *")
190189
require.Equal(t, adj.Format(FormatOptions{VariableLengthFields: true}), "{8600}01CRDTUSD1234.56*")
191190
require.Equal(t, adj.String(), adj.Format(FormatOptions{VariableLengthFields: false}))
192191
}

Diff for: amountNegotiatedDiscount.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (nd *AmountNegotiatedDiscount) Parse(record string) error {
4343
nd.tag = record[:6]
4444
length := 6
4545

46-
value, read, err := nd.parseVariableStringField(record[length:], 3)
46+
value, read, err := nd.parseFixedStringField(record[length:], 3)
4747
if err != nil {
4848
return fieldError("CurrencyCode", err)
4949
}
@@ -91,8 +91,8 @@ func (nd *AmountNegotiatedDiscount) Format(options FormatOptions) string {
9191
buf.Grow(28)
9292

9393
buf.WriteString(nd.tag)
94-
buf.WriteString(nd.FormatCurrencyCode(options))
95-
buf.WriteString(nd.FormatAmount(options))
94+
buf.WriteString(nd.CurrencyCodeField())
95+
buf.WriteString(nd.FormatAmount(options) + Delimiter)
9696

9797
return buf.String()
9898
}

Diff for: amountNegotiatedDiscount_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ func TestParseAmountNegotiatedDiscountWrongLength(t *testing.T) {
7171

7272
err := r.parseAmountNegotiatedDiscount()
7373

74-
require.EqualError(t, err, r.parseError(fieldError("Amount", ErrValidLength)).Error())
74+
require.EqualError(t, err, r.parseError(fieldError("Amount", ErrRequireDelimiter)).Error())
7575
}
7676

7777
// TestParseAmountNegotiatedDiscountReaderParseError parses a wrong AmountNegotiatedDiscount reader parse error
7878
func TestParseAmountNegotiatedDiscountReaderParseError(t *testing.T) {
79-
var line = "{8550}USD1234.56Z "
79+
var line = "{8550}USD1234.56Z *"
8080
r := NewReader(strings.NewReader(line))
8181
r.line = line
8282

@@ -116,7 +116,7 @@ func TestStringAmountNegotiatedDiscountVariableLength(t *testing.T) {
116116
r.line = line
117117

118118
err = r.parseAmountNegotiatedDiscount()
119-
require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error())
119+
require.ErrorContains(t, err, ErrRequireDelimiter.Error())
120120

121121
line = "{8550}USD1234.56***"
122122
r = NewReader(strings.NewReader(line))
@@ -143,7 +143,7 @@ func TestStringAmountNegotiatedDiscountOptions(t *testing.T) {
143143
require.Equal(t, err, nil)
144144

145145
and := r.currentFEDWireMessage.AmountNegotiatedDiscount
146-
require.Equal(t, and.String(), "{8550}USD1234.56 ")
146+
require.Equal(t, and.String(), "{8550}USD1234.56 *")
147147
require.Equal(t, and.Format(FormatOptions{VariableLengthFields: true}), "{8550}USD1234.56*")
148148
require.Equal(t, and.String(), and.Format(FormatOptions{VariableLengthFields: false}))
149149
}

Diff for: beneficiary.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@ func (ben *Beneficiary) Format(options FormatOptions) string {
114114

115115
buf.WriteString(ben.tag)
116116
buf.WriteString(ben.IdentificationCodeField())
117-
buf.WriteString(ben.FormatIdentifier(options))
118-
buf.WriteString(ben.FormatName(options))
119-
buf.WriteString(ben.FormatAddressLineOne(options))
120-
buf.WriteString(ben.FormatAddressLineTwo(options))
121-
buf.WriteString(ben.FormatAddressLineThree(options))
117+
buf.WriteString(ben.FormatIdentifier(options) + Delimiter)
118+
buf.WriteString(ben.FormatName(options) + Delimiter)
119+
buf.WriteString(ben.FormatAddressLineOne(options) + Delimiter)
120+
buf.WriteString(ben.FormatAddressLineTwo(options) + Delimiter)
121+
buf.WriteString(ben.FormatAddressLineThree(options) + Delimiter)
122122

123123
if options.VariableLengthFields {
124124
return ben.stripDelimiters(buf.String())

Diff for: beneficiaryCustomer.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,12 @@ func (bc *BeneficiaryCustomer) Format(options FormatOptions) string {
119119
buf.Grow(186)
120120

121121
buf.WriteString(bc.tag)
122-
buf.WriteString(bc.FormatSwiftFieldTag(options))
123-
buf.WriteString(bc.FormatSwiftLineOne(options))
124-
buf.WriteString(bc.FormatSwiftLineTwo(options))
125-
buf.WriteString(bc.FormatSwiftLineThree(options))
126-
buf.WriteString(bc.FormatSwiftLineFour(options))
127-
buf.WriteString(bc.FormatSwiftLineFive(options))
122+
buf.WriteString(bc.FormatSwiftFieldTag(options) + Delimiter)
123+
buf.WriteString(bc.FormatSwiftLineOne(options) + Delimiter)
124+
buf.WriteString(bc.FormatSwiftLineTwo(options) + Delimiter)
125+
buf.WriteString(bc.FormatSwiftLineThree(options) + Delimiter)
126+
buf.WriteString(bc.FormatSwiftLineFour(options) + Delimiter)
127+
buf.WriteString(bc.FormatSwiftLineFive(options) + Delimiter)
128128

129129
if options.VariableLengthFields {
130130
return bc.stripDelimiters(buf.String())

0 commit comments

Comments
 (0)