From a3212b2212f8a12e781b8b1ea6efd8fbc950e0be Mon Sep 17 00:00:00 2001 From: Jose Date: Mon, 26 Jun 2023 11:06:59 -0500 Subject: [PATCH] implemted new field parser functions, updated record parse, format functions --- accountCreditedDrawdown.go | 4 +- accountCreditedDrawdown_test.go | 16 ++- accountDebitedDrawdown.go | 10 +- accountDebitedDrawdown_test.go | 13 +- actualAmountPaid.go | 6 +- actualAmountPaid_test.go | 18 ++- adjustment.go | 18 +-- adjustment_test.go | 11 +- amountNegotiatedDiscount.go | 6 +- amountNegotiatedDiscount_test.go | 8 +- beneficiary.go | 10 +- beneficiaryCustomer.go | 12 +- beneficiaryCustomer_test.go | 10 +- beneficiaryFI.go | 10 +- beneficiaryFI_test.go | 10 +- beneficiaryIntermediaryFI.go | 10 +- beneficiaryIntermediaryFI_test.go | 10 +- beneficiaryReference.go | 2 +- beneficiaryReference_test.go | 8 +- beneficiary_test.go | 12 +- businessFunctionCode.go | 2 +- businessFunctionCode_test.go | 8 +- charges.go | 8 +- charges_test.go | 4 +- converters.go | 82 +++++++---- converters_test.go | 175 +++++++++++++++++++----- currencyInstructedAmount.go | 19 ++- currencyInstructedAmount_test.go | 19 ++- errorWire.go | 10 +- errorWire_test.go | 8 +- exchangeRate.go | 2 +- exchangeRate_test.go | 10 +- fIBeneficiaryFIAdvice.go | 12 +- fIBeneficiaryFIAdvice_test.go | 8 +- fiAdditionalFIToFI.go | 12 +- fiAdditionalFIToFI_test.go | 8 +- fiBeneficiary.go | 12 +- fiBeneficiaryAdvice.go | 12 +- fiBeneficiaryAdvice_test.go | 8 +- fiBeneficiaryFI.go | 12 +- fiBeneficiaryFI_test.go | 8 +- fiBeneficiary_test.go | 8 +- fiDrawdownDebitAccountAdvice.go | 12 +- fiDrawdownDebitAccountAdvice_test.go | 8 +- fiIntermediaryFI.go | 12 +- fiIntermediaryFIAdvice.go | 12 +- fiIntermediaryFIAdvice_test.go | 8 +- fiIntermediaryFI_test.go | 8 +- fiPaymentMethodToBeneficiary.go | 2 +- fiPaymentMethodToBeneficiary_test.go | 8 +- fiReceiverFI.go | 12 +- fiReceiverFI_test.go | 8 +- fieldErrors.go | 3 + grossAmountRemittanceDocument.go | 6 +- grossAmountRemittanceDocument_test.go | 8 +- institutionAccount.go | 12 +- institutionAccount_test.go | 8 +- instructedAmount.go | 6 +- instructedAmount_test.go | 8 +- instructingFI.go | 22 +-- instructingFI_test.go | 8 +- intermediaryInstitution.go | 12 +- intermediaryInstitution_test.go | 8 +- localInstrument.go | 8 +- localInstrument_test.go | 11 +- messageDisposition.go | 16 +-- messageDisposition_test.go | 6 +- orderingCustomer.go | 12 +- orderingCustomer_test.go | 8 +- orderingInstitution.go | 12 +- orderingInstitution_test.go | 8 +- originator.go | 10 +- originatorFI.go | 14 +- originatorFI_test.go | 8 +- originatorOptionF.go | 10 +- originatorOptionF_test.go | 8 +- originatorToBeneficiary.go | 17 +-- originatorToBeneficiary_test.go | 8 +- originator_test.go | 8 +- outputMessageAccountabilityData.go | 48 +++++-- outputMessageAccountabilityData_test.go | 10 +- paymentNotification.go | 21 +-- paymentNotification_test.go | 20 +-- previousMessageIdentifier.go | 4 +- previousMessageIdentifier_test.go | 6 +- primaryRemittanceDocument.go | 6 +- primaryRemittanceDocument_test.go | 8 +- reader_test.go | 3 +- receiptTimeStamp.go | 12 +- receiptTimeStamp_test.go | 6 +- receiverDepositoryInstitution.go | 6 +- receiverDepositoryInstitution_test.go | 29 ++-- relatedRemittance.go | 40 +++--- relatedRemittance_test.go | 12 +- remittance.go | 10 +- remittanceBeneficiary.go | 44 +++--- remittanceBeneficiary_test.go | 20 +-- remittanceFreeText.go | 6 +- remittanceFreeText_test.go | 8 +- remittanceOriginator.go | 62 ++++----- remittanceOriginator_test.go | 25 +--- remittance_test.go | 10 +- secondaryRemittanceDocument.go | 15 +- secondaryRemittanceDocument_test.go | 14 +- senderDepositoryInstitution.go | 6 +- senderDepositoryInstitution_test.go | 27 ++-- senderReference.go | 2 +- senderReference_test.go | 8 +- senderSupplied.go | 6 +- senderSupplied_test.go | 15 +- senderToReceiver.go | 14 +- senderToReceiver_test.go | 8 +- serviceMessage.go | 24 ++-- serviceMessage_test.go | 8 +- 114 files changed, 848 insertions(+), 721 deletions(-) diff --git a/accountCreditedDrawdown.go b/accountCreditedDrawdown.go index f1c80fdc..979e19ba 100644 --- a/accountCreditedDrawdown.go +++ b/accountCreditedDrawdown.go @@ -43,7 +43,7 @@ func (creditDD *AccountCreditedDrawdown) Parse(record string) error { creditDD.tag = record[:6] length := 6 - value, read, err := creditDD.parseVariableStringField(record[length:], 9) + value, read, err := creditDD.parseFixedStringField(record[length:], 9) if err != nil { return fieldError("DrawdownCreditAccountNumber", err) } @@ -83,7 +83,7 @@ func (creditDD *AccountCreditedDrawdown) Format(options FormatOptions) string { var buf strings.Builder buf.Grow(15) buf.WriteString(creditDD.tag) - buf.WriteString(creditDD.FormatCreditAccountNumber(options)) + buf.WriteString(creditDD.DrawdownCreditAccountNumberField()) return buf.String() } diff --git a/accountCreditedDrawdown_test.go b/accountCreditedDrawdown_test.go index 5ed64ca5..f1550fb8 100644 --- a/accountCreditedDrawdown_test.go +++ b/accountCreditedDrawdown_test.go @@ -102,7 +102,7 @@ func TestStringAccountCreditedDrawdownVariableLength(t *testing.T) { r.line = line err = r.parseAccountCreditedDrawdown() - expected = r.parseError(fieldError("DrawdownCreditAccountNumber", ErrFieldRequired)).Error() + expected = r.parseError(fieldError("DrawdownCreditAccountNumber", ErrValidLength)).Error() require.EqualError(t, err, expected) line = "{5400}1*" @@ -110,12 +110,20 @@ func TestStringAccountCreditedDrawdownVariableLength(t *testing.T) { r.line = line err = r.parseAccountCreditedDrawdown() - require.Equal(t, err, nil) + expected = r.parseError(fieldError("DrawdownCreditAccountNumber", ErrValidLength)).Error() + require.EqualError(t, err, expected) + + line = "{5400}1 *" + r = NewReader(strings.NewReader(line)) + r.line = line + + err = r.parseAccountCreditedDrawdown() + require.NoError(t, err) } // TestStringAccountCreditedDrawdownOptions validates Format() formatted according to the FormatOptions func TestStringAccountCreditedDrawdownOptions(t *testing.T) { - var line = "{5400}1*" + var line = "{5400}1 " r := NewReader(strings.NewReader(line)) r.line = line @@ -124,6 +132,6 @@ func TestStringAccountCreditedDrawdownOptions(t *testing.T) { acd := r.currentFEDWireMessage.AccountCreditedDrawdown require.Equal(t, acd.String(), "{5400}1 ") - require.Equal(t, acd.Format(FormatOptions{VariableLengthFields: true}), "{5400}1*") + require.Equal(t, acd.Format(FormatOptions{VariableLengthFields: true}), "{5400}1 ") require.Equal(t, acd.String(), acd.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/accountDebitedDrawdown.go b/accountDebitedDrawdown.go index efdd448c..c24de21b 100644 --- a/accountDebitedDrawdown.go +++ b/accountDebitedDrawdown.go @@ -119,11 +119,11 @@ func (debitDD *AccountDebitedDrawdown) Format(options FormatOptions) string { buf.WriteString(debitDD.tag) buf.WriteString(debitDD.IdentificationCodeField()) - buf.WriteString(debitDD.FormatIdentifier(options)) - buf.WriteString(debitDD.FormatName(options)) - buf.WriteString(debitDD.FormatAddressLineOne(options)) - buf.WriteString(debitDD.FormatAddressLineTwo(options)) - buf.WriteString(debitDD.FormatAddressLineThree(options)) + buf.WriteString(debitDD.FormatIdentifier(options) + Delimiter) + buf.WriteString(debitDD.FormatName(options) + Delimiter) + buf.WriteString(debitDD.FormatAddressLineOne(options) + Delimiter) + buf.WriteString(debitDD.FormatAddressLineTwo(options) + Delimiter) + buf.WriteString(debitDD.FormatAddressLineThree(options) + Delimiter) if options.VariableLengthFields { return debitDD.stripDelimiters(buf.String()) diff --git a/accountDebitedDrawdown_test.go b/accountDebitedDrawdown_test.go index fc3eb7fb..d8cfa5d6 100644 --- a/accountDebitedDrawdown_test.go +++ b/accountDebitedDrawdown_test.go @@ -1,7 +1,6 @@ package wire import ( - "errors" "strings" "testing" @@ -129,18 +128,18 @@ func TestIdentificationCodeBogus(t *testing.T) { // TestParseAccountDebitedDrawdownWrongLength parses a wrong AccountDebitedDrawdown record length func TestParseAccountDebitedDrawdownWrongLength(t *testing.T) { - var line = "{4400}D123456789 debitDD Name Address One Address Two Address Three " + var line = "{4400}D123456789 *debitDD Name *Address One *Address Two *Address Three " r := NewReader(strings.NewReader(line)) r.line = line err := r.parseAccountDebitedDrawdown() - require.EqualError(t, err, r.parseError(fieldError("AddressLineThree", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("AddressLineThree", ErrRequireDelimiter)).Error()) } // TestParseAccountDebitedDrawdownReaderParseError parses a wrong AccountDebitedDrawdown reader parse error func TestParseAccountDebitedDrawdownReaderParseError(t *testing.T) { - var line = "{4400}D123456789 debitDD ®ame Address One Address Two Address Three " + var line = "{4400}D123456789 *debitDD ®ame *Address One *Address Two *Address Three *" r := NewReader(strings.NewReader(line)) r.line = line @@ -175,12 +174,12 @@ func TestStringAccountDebitedDrawdownVariableLength(t *testing.T) { expected := r.parseError(NewTagMinLengthErr(9, len(r.line))).Error() require.EqualError(t, err, expected) - line = "{4400}D123456789 debitDD Name Address One Address Two Address Three NNNN" + line = "{4400}D123456789 *debitDD Name *Address One *Address Two *Address Three NNNNNNNN*" r = NewReader(strings.NewReader(line)) r.line = line err = r.parseAccountDebitedDrawdown() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.NoError(t, err) line = "{4400}***" r = NewReader(strings.NewReader(line)) @@ -208,7 +207,7 @@ func TestStringAccountDebitedDrawdownOptions(t *testing.T) { require.Equal(t, err, nil) add := r.currentFEDWireMessage.AccountDebitedDrawdown - require.Equal(t, add.String(), "{4400}D2 3 ") + require.Equal(t, add.String(), "{4400}D2 *3 * * * *") require.Equal(t, add.Format(FormatOptions{VariableLengthFields: true}), "{4400}D2*3*") require.Equal(t, add.String(), add.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/actualAmountPaid.go b/actualAmountPaid.go index 6ac10b53..6fd098a8 100644 --- a/actualAmountPaid.go +++ b/actualAmountPaid.go @@ -43,7 +43,7 @@ func (aap *ActualAmountPaid) Parse(record string) error { aap.tag = record[:6] length := 6 - value, read, err := aap.parseVariableStringField(record[length:], 3) + value, read, err := aap.parseFixedStringField(record[length:], 3) if err != nil { return fieldError("CurrencyCode", err) } @@ -91,8 +91,8 @@ func (aap *ActualAmountPaid) Format(options FormatOptions) string { buf.Grow(28) buf.WriteString(aap.tag) - buf.WriteString(aap.FormatCurrencyCode(options)) - buf.WriteString(aap.FormatAmount(options)) + buf.WriteString(aap.CurrencyCodeField()) + buf.WriteString(aap.FormatAmount(options) + Delimiter) return buf.String() } diff --git a/actualAmountPaid_test.go b/actualAmountPaid_test.go index de77ed05..f5079dfd 100644 --- a/actualAmountPaid_test.go +++ b/actualAmountPaid_test.go @@ -1,7 +1,6 @@ package wire import ( - "errors" "strings" "testing" @@ -65,18 +64,17 @@ func TestActualAmountPaidCurrencyCodeValid(t *testing.T) { // TestParseActualAmountPaidWrongLength parses a wrong ActualAmountPaid record length func TestParseActualAmountPaidWrongLength(t *testing.T) { - var line = "{8450}USD1234.56 " + var line = "{8450}USD1234.56 *" r := NewReader(strings.NewReader(line)) r.line = line err := r.parseActualAmountPaid() - - require.EqualError(t, err, r.parseError(fieldError("Amount", ErrValidLength)).Error()) + require.NoError(t, err) } // TestParseActualAmountPaidReaderParseError parses a wrong ActualAmountPaid reader parse error func TestParseActualAmountPaidReaderParseError(t *testing.T) { - var line = "{8450}USD1234.56Z " + var line = "{8450}USD1234.56Z *" r := NewReader(strings.NewReader(line)) r.line = line @@ -111,21 +109,21 @@ func TestStringActualAmountPaidVariableLength(t *testing.T) { expected := r.parseError(NewTagMinLengthErr(8, len(r.line))).Error() require.EqualError(t, err, expected) - line = "{8450}USD1234.56 NNN" + line = "{8450}USD1234.56 NNN*" r = NewReader(strings.NewReader(line)) r.line = line err = r.parseActualAmountPaid() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrNonAmount.Error()) line = "{8450}****" r = NewReader(strings.NewReader(line)) r.line = line err = r.parseActualAmountPaid() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrValidLength.Error()) - line = "{8450}**" + line = "{8450}USD*" r = NewReader(strings.NewReader(line)) r.line = line @@ -151,7 +149,7 @@ func TestStringActualAmountPaidOptions(t *testing.T) { require.Equal(t, err, nil) aap := r.currentFEDWireMessage.ActualAmountPaid - require.Equal(t, aap.String(), "{8450}USD1234.56 ") + require.Equal(t, aap.String(), "{8450}USD1234.56 *") require.Equal(t, aap.Format(FormatOptions{VariableLengthFields: true}), "{8450}USD1234.56*") require.Equal(t, aap.String(), aap.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/adjustment.go b/adjustment.go index 3f25bc05..bd7a9a15 100644 --- a/adjustment.go +++ b/adjustment.go @@ -49,21 +49,21 @@ func (adj *Adjustment) Parse(record string) error { adj.tag = record[:6] length := 6 - value, read, err := adj.parseVariableStringField(record[length:], 2) + value, read, err := adj.parseFixedStringField(record[length:], 2) if err != nil { return fieldError("AdjustmentReasonCode", err) } adj.AdjustmentReasonCode = value length += read - value, read, err = adj.parseVariableStringField(record[length:], 4) + value, read, err = adj.parseFixedStringField(record[length:], 4) if err != nil { return fieldError("CreditDebitIndicator", err) } adj.CreditDebitIndicator = value length += read - value, read, err = adj.parseVariableStringField(record[length:], 3) + value, read, err = adj.parseFixedStringField(record[length:], 3) if err != nil { return fieldError("CurrencyCode", err) } @@ -72,7 +72,7 @@ func (adj *Adjustment) Parse(record string) error { value, read, err = adj.parseVariableStringField(record[length:], 19) if err != nil { - return fieldError("CurrencyCode", err) + return fieldError("Amount", err) } adj.RemittanceAmount.Amount = value length += read @@ -118,11 +118,11 @@ func (adj *Adjustment) Format(options FormatOptions) string { buf.Grow(168) buf.WriteString(adj.tag) - buf.WriteString(adj.FormatAdjustmentReasonCode(options)) - buf.WriteString(adj.FormatCreditDebitIndicator(options)) - buf.WriteString(adj.FormatCurrencyCode(options)) - buf.WriteString(adj.FormatAmount(options)) - buf.WriteString(adj.FormatAdditionalInfo(options)) + buf.WriteString(adj.AdjustmentReasonCodeField()) + buf.WriteString(adj.CreditDebitIndicatorField()) + buf.WriteString(adj.CurrencyCodeField()) + buf.WriteString(adj.FormatAmount(options) + Delimiter) + buf.WriteString(adj.FormatAdditionalInfo(options) + Delimiter) if options.VariableLengthFields { return adj.stripDelimiters(buf.String()) diff --git a/adjustment_test.go b/adjustment_test.go index 0c3cfe73..52d6d7c7 100644 --- a/adjustment_test.go +++ b/adjustment_test.go @@ -108,18 +108,17 @@ func TestAdjustmentCurrencyCodeRequired(t *testing.T) { // TestParseAdjustmentWrongLength parses a wrong Adjustment record length func TestParseAdjustmentWrongLength(t *testing.T) { - var line = "{8600}01CRDTUSD1234.56Z Adjustment Additional Information " + var line = "{8600}01CRDTUSD1234.56 *Additional Information *" r := NewReader(strings.NewReader(line)) r.line = line err := r.parseAdjustment() - - require.EqualError(t, err, r.parseError(fieldError("AdditionalInfo", ErrValidLength)).Error()) + require.NoError(t, err) } // TestParseAdjustmentReaderParseError parses a wrong Adjustment reader parse error func TestParseAdjustmentReaderParseError(t *testing.T) { - var line = "{8600}01CRDTUSD1234.56Z Adjustment Additional Information " + var line = "{8600}01CRDTUSD1234.56Z *Additional Information *" r := NewReader(strings.NewReader(line)) r.line = line @@ -159,7 +158,7 @@ func TestStringAdjustmentVariableLength(t *testing.T) { r.line = line err = r.parseAdjustment() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{8600}01CRDTUSD1234.56****" r = NewReader(strings.NewReader(line)) @@ -186,7 +185,7 @@ func TestStringAdjustmentOptions(t *testing.T) { require.Equal(t, err, nil) adj := r.currentFEDWireMessage.Adjustment - require.Equal(t, adj.String(), "{8600}01CRDTUSD1234.56 ") + require.Equal(t, adj.String(), "{8600}01CRDTUSD1234.56 * *") require.Equal(t, adj.Format(FormatOptions{VariableLengthFields: true}), "{8600}01CRDTUSD1234.56*") require.Equal(t, adj.String(), adj.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/amountNegotiatedDiscount.go b/amountNegotiatedDiscount.go index 3685c84b..d87566aa 100644 --- a/amountNegotiatedDiscount.go +++ b/amountNegotiatedDiscount.go @@ -43,7 +43,7 @@ func (nd *AmountNegotiatedDiscount) Parse(record string) error { nd.tag = record[:6] length := 6 - value, read, err := nd.parseVariableStringField(record[length:], 3) + value, read, err := nd.parseFixedStringField(record[length:], 3) if err != nil { return fieldError("CurrencyCode", err) } @@ -91,8 +91,8 @@ func (nd *AmountNegotiatedDiscount) Format(options FormatOptions) string { buf.Grow(28) buf.WriteString(nd.tag) - buf.WriteString(nd.FormatCurrencyCode(options)) - buf.WriteString(nd.FormatAmount(options)) + buf.WriteString(nd.CurrencyCodeField()) + buf.WriteString(nd.FormatAmount(options) + Delimiter) return buf.String() } diff --git a/amountNegotiatedDiscount_test.go b/amountNegotiatedDiscount_test.go index 744745d2..c185fcd7 100644 --- a/amountNegotiatedDiscount_test.go +++ b/amountNegotiatedDiscount_test.go @@ -71,12 +71,12 @@ func TestParseAmountNegotiatedDiscountWrongLength(t *testing.T) { err := r.parseAmountNegotiatedDiscount() - require.EqualError(t, err, r.parseError(fieldError("Amount", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("Amount", ErrRequireDelimiter)).Error()) } // TestParseAmountNegotiatedDiscountReaderParseError parses a wrong AmountNegotiatedDiscount reader parse error func TestParseAmountNegotiatedDiscountReaderParseError(t *testing.T) { - var line = "{8550}USD1234.56Z " + var line = "{8550}USD1234.56Z *" r := NewReader(strings.NewReader(line)) r.line = line @@ -116,7 +116,7 @@ func TestStringAmountNegotiatedDiscountVariableLength(t *testing.T) { r.line = line err = r.parseAmountNegotiatedDiscount() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{8550}USD1234.56***" r = NewReader(strings.NewReader(line)) @@ -143,7 +143,7 @@ func TestStringAmountNegotiatedDiscountOptions(t *testing.T) { require.Equal(t, err, nil) and := r.currentFEDWireMessage.AmountNegotiatedDiscount - require.Equal(t, and.String(), "{8550}USD1234.56 ") + require.Equal(t, and.String(), "{8550}USD1234.56 *") require.Equal(t, and.Format(FormatOptions{VariableLengthFields: true}), "{8550}USD1234.56*") require.Equal(t, and.String(), and.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/beneficiary.go b/beneficiary.go index 323b2bbe..2db6d197 100644 --- a/beneficiary.go +++ b/beneficiary.go @@ -114,11 +114,11 @@ func (ben *Beneficiary) Format(options FormatOptions) string { buf.WriteString(ben.tag) buf.WriteString(ben.IdentificationCodeField()) - buf.WriteString(ben.FormatIdentifier(options)) - buf.WriteString(ben.FormatName(options)) - buf.WriteString(ben.FormatAddressLineOne(options)) - buf.WriteString(ben.FormatAddressLineTwo(options)) - buf.WriteString(ben.FormatAddressLineThree(options)) + buf.WriteString(ben.FormatIdentifier(options) + Delimiter) + buf.WriteString(ben.FormatName(options) + Delimiter) + buf.WriteString(ben.FormatAddressLineOne(options) + Delimiter) + buf.WriteString(ben.FormatAddressLineTwo(options) + Delimiter) + buf.WriteString(ben.FormatAddressLineThree(options) + Delimiter) if options.VariableLengthFields { return ben.stripDelimiters(buf.String()) diff --git a/beneficiaryCustomer.go b/beneficiaryCustomer.go index f440209e..0adfa431 100644 --- a/beneficiaryCustomer.go +++ b/beneficiaryCustomer.go @@ -119,12 +119,12 @@ func (bc *BeneficiaryCustomer) Format(options FormatOptions) string { buf.Grow(186) buf.WriteString(bc.tag) - buf.WriteString(bc.FormatSwiftFieldTag(options)) - buf.WriteString(bc.FormatSwiftLineOne(options)) - buf.WriteString(bc.FormatSwiftLineTwo(options)) - buf.WriteString(bc.FormatSwiftLineThree(options)) - buf.WriteString(bc.FormatSwiftLineFour(options)) - buf.WriteString(bc.FormatSwiftLineFive(options)) + buf.WriteString(bc.FormatSwiftFieldTag(options) + Delimiter) + buf.WriteString(bc.FormatSwiftLineOne(options) + Delimiter) + buf.WriteString(bc.FormatSwiftLineTwo(options) + Delimiter) + buf.WriteString(bc.FormatSwiftLineThree(options) + Delimiter) + buf.WriteString(bc.FormatSwiftLineFour(options) + Delimiter) + buf.WriteString(bc.FormatSwiftLineFive(options) + Delimiter) if options.VariableLengthFields { return bc.stripDelimiters(buf.String()) diff --git a/beneficiaryCustomer_test.go b/beneficiaryCustomer_test.go index ade5f0d6..d28d2e62 100644 --- a/beneficiaryCustomer_test.go +++ b/beneficiaryCustomer_test.go @@ -105,12 +105,12 @@ func TestParseBeneficiaryCustomerWrongLength(t *testing.T) { err := r.parseBeneficiaryCustomer() - require.EqualError(t, err, r.parseError(fieldError("SwiftLineFive", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("SwiftFieldTag", ErrRequireDelimiter)).Error()) } // TestParseBeneficiaryCustomerReaderParseError parses a wrong BeneficiaryCustomer reader parse error func TestParseBeneficiaryCustomerReaderParseError(t *testing.T) { - var line = "{7059}SwiftSwift ®ine One Swift Line Two Swift Line Three Swift Line Four Swift Line Five " + var line = "{7059}Swift*Swift ®ine One *Swift Line Two *Swift Line Three *Swift Line Four *Swift Line Five *" r := NewReader(strings.NewReader(line)) r.line = line @@ -144,12 +144,12 @@ func TestStringBeneficiaryCustomerVariableLength(t *testing.T) { err := r.parseBeneficiaryCustomer() require.Nil(t, err) - line = "{7059}SwiftSwift ®ine One Swift Line Two Swift Line Three Swift Line Four Swift Line Five NN" + line = "{7059}SwiftSwift ®ine One *Swift Line Two *Swift Line Three *Swift Line Four *Swift Line Five NN" r = NewReader(strings.NewReader(line)) r.line = line err = r.parseBeneficiaryCustomer() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{7059}********" r = NewReader(strings.NewReader(line)) @@ -176,7 +176,7 @@ func TestStringBeneficiaryCustomerOptions(t *testing.T) { require.Equal(t, err, nil) bc := r.currentFEDWireMessage.BeneficiaryCustomer - require.Equal(t, bc.String(), "{7059} ") + require.Equal(t, bc.String(), "{7059} * * * * * *") require.Equal(t, bc.Format(FormatOptions{VariableLengthFields: true}), "{7059}*") require.Equal(t, bc.String(), bc.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/beneficiaryFI.go b/beneficiaryFI.go index 9ec782a4..1fbec630 100644 --- a/beneficiaryFI.go +++ b/beneficiaryFI.go @@ -114,11 +114,11 @@ func (bfi *BeneficiaryFI) Format(options FormatOptions) string { buf.WriteString(bfi.tag) buf.WriteString(bfi.IdentificationCodeField()) - buf.WriteString(bfi.FormatIdentifier(options)) - buf.WriteString(bfi.FormatName(options)) - buf.WriteString(bfi.FormatAddressLineOne(options)) - buf.WriteString(bfi.FormatAddressLineTwo(options)) - buf.WriteString(bfi.FormatAddressLineThree(options)) + buf.WriteString(bfi.FormatIdentifier(options) + Delimiter) + buf.WriteString(bfi.FormatName(options) + Delimiter) + buf.WriteString(bfi.FormatAddressLineOne(options) + Delimiter) + buf.WriteString(bfi.FormatAddressLineTwo(options) + Delimiter) + buf.WriteString(bfi.FormatAddressLineThree(options) + Delimiter) if options.VariableLengthFields { return bfi.stripDelimiters(buf.String()) diff --git a/beneficiaryFI_test.go b/beneficiaryFI_test.go index 63a4ddb0..5a148248 100644 --- a/beneficiaryFI_test.go +++ b/beneficiaryFI_test.go @@ -125,12 +125,12 @@ func TestParseBeneficiaryFIWrongLength(t *testing.T) { err := r.parseBeneficiaryFI() - require.EqualError(t, err, r.parseError(fieldError("AddressLineThree", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("Identifier", ErrRequireDelimiter)).Error()) } // TestParseBeneficiaryFIReaderParseError parses a wrong BeneficiaryFI reader parse error func TestParseBeneficiaryFIReaderParseError(t *testing.T) { - var line = "{4100}D123456789 F® Name Address One Address Two Address Three " + var line = "{4100}D123456789 *F® Name *Address One *Address Two *Address Three *" r := NewReader(strings.NewReader(line)) r.line = line @@ -165,12 +165,12 @@ func TestStringBeneficiaryFIVariableLength(t *testing.T) { expected := r.parseError(NewTagMinLengthErr(7, len(r.line))).Error() require.EqualError(t, err, expected) - line = "{4100}D123456789 FI Name Address One Address Two Address Three NNN" + line = "{4100}D123456789 *FI Name *Address One *Address Two *Address Three NNN" r = NewReader(strings.NewReader(line)) r.line = line err = r.parseBeneficiaryFI() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{4100}D123456789*******" r = NewReader(strings.NewReader(line)) @@ -197,7 +197,7 @@ func TestStringBeneficiaryFIOptions(t *testing.T) { require.Equal(t, err, nil) bfi := r.currentFEDWireMessage.BeneficiaryFI - require.Equal(t, bfi.String(), "{4100}D123456789 ") + require.Equal(t, bfi.String(), "{4100}D123456789 * * * * *") require.Equal(t, bfi.Format(FormatOptions{VariableLengthFields: true}), "{4100}D123456789*") require.Equal(t, bfi.String(), bfi.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/beneficiaryIntermediaryFI.go b/beneficiaryIntermediaryFI.go index 836ac743..2f145df5 100644 --- a/beneficiaryIntermediaryFI.go +++ b/beneficiaryIntermediaryFI.go @@ -114,11 +114,11 @@ func (bifi *BeneficiaryIntermediaryFI) Format(options FormatOptions) string { buf.WriteString(bifi.tag) buf.WriteString(bifi.IdentificationCodeField()) - buf.WriteString(bifi.FormatIdentifier(options)) - buf.WriteString(bifi.FormatName(options)) - buf.WriteString(bifi.FormatAddressLineOne(options)) - buf.WriteString(bifi.FormatAddressLineTwo(options)) - buf.WriteString(bifi.FormatAddressLineThree(options)) + buf.WriteString(bifi.FormatIdentifier(options) + Delimiter) + buf.WriteString(bifi.FormatName(options) + Delimiter) + buf.WriteString(bifi.FormatAddressLineOne(options) + Delimiter) + buf.WriteString(bifi.FormatAddressLineTwo(options) + Delimiter) + buf.WriteString(bifi.FormatAddressLineThree(options) + Delimiter) if options.VariableLengthFields { return bifi.stripDelimiters(buf.String()) diff --git a/beneficiaryIntermediaryFI_test.go b/beneficiaryIntermediaryFI_test.go index ce7003c5..b22f46d0 100644 --- a/beneficiaryIntermediaryFI_test.go +++ b/beneficiaryIntermediaryFI_test.go @@ -125,12 +125,12 @@ func TestParseBeneficiaryIntermediaryFIWrongLength(t *testing.T) { err := r.parseBeneficiaryIntermediaryFI() - require.EqualError(t, err, r.parseError(fieldError("AddressLineThree", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("Identifier", ErrRequireDelimiter)).Error()) } // TestParseBeneficiaryIntermediaryFIReaderParseError parses a wrong BeneficiaryIntermediaryFI reader parse error func TestParseBeneficiaryIntermediaryFIReaderParseError(t *testing.T) { - var line = "{4000}D123456789 F® Name Address One Address Two Address Three " + var line = "{4000}D123456789 *F® Name *Address One *Address Two *Address Three *" r := NewReader(strings.NewReader(line)) r.line = line fwm := new(FEDWireMessage) @@ -168,12 +168,12 @@ func TestStringBeneficiaryIntermediaryFIVariableLength(t *testing.T) { expected := r.parseError(NewTagMinLengthErr(7, len(r.line))).Error() require.EqualError(t, err, expected) - line = "{4000}D123456789 FI Name Address One Address Two Address Three NNN" + line = "{4000}D123456789 *FI Name *Address One *Address Two *Address Three NNN" r = NewReader(strings.NewReader(line)) r.line = line err = r.parseBeneficiaryIntermediaryFI() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{4000}D123456789*******" r = NewReader(strings.NewReader(line)) @@ -200,7 +200,7 @@ func TestStringBeneficiaryIntermediaryFIOptions(t *testing.T) { require.Equal(t, err, nil) bifi := r.currentFEDWireMessage.BeneficiaryIntermediaryFI - require.Equal(t, bifi.String(), "{4000}D123456789 ") + require.Equal(t, bifi.String(), "{4000}D123456789 * * * * *") require.Equal(t, bifi.Format(FormatOptions{VariableLengthFields: true}), "{4000}D123456789*") require.Equal(t, bifi.String(), bifi.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/beneficiaryReference.go b/beneficiaryReference.go index 56ee9cbf..0ae060da 100644 --- a/beneficiaryReference.go +++ b/beneficiaryReference.go @@ -84,7 +84,7 @@ func (br *BeneficiaryReference) Format(options FormatOptions) string { buf.Grow(22) buf.WriteString(br.tag) - buf.WriteString(br.FormatBeneficiaryReference(options)) + buf.WriteString(br.FormatBeneficiaryReference(options) + Delimiter) return buf.String() } diff --git a/beneficiaryReference_test.go b/beneficiaryReference_test.go index 8ba5c0e2..79c6ddf4 100644 --- a/beneficiaryReference_test.go +++ b/beneficiaryReference_test.go @@ -40,12 +40,12 @@ func TestParseBeneficiaryReferenceWrongLength(t *testing.T) { err := r.parseBeneficiaryReference() - require.EqualError(t, err, r.parseError(fieldError("BeneficiaryReference", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("BeneficiaryReference", ErrRequireDelimiter)).Error()) } // TestParseBeneficiaryReferenceReaderParseError parses a wrong BeneficiaryReference reader parse error func TestParseBeneficiaryReferenceReaderParseError(t *testing.T) { - var line = "{4320}Reference® " + var line = "{4320}Reference® *" r := NewReader(strings.NewReader(line)) r.line = line @@ -84,7 +84,7 @@ func TestStringBeneficiaryReferenceVariableLength(t *testing.T) { r.line = line err = r.parseBeneficiaryReference() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{4320}***" r = NewReader(strings.NewReader(line)) @@ -111,7 +111,7 @@ func TestStringBeneficiaryReferenceOptions(t *testing.T) { require.Equal(t, err, nil) br := r.currentFEDWireMessage.BeneficiaryReference - require.Equal(t, br.String(), "{4320}Reference ") + require.Equal(t, br.String(), "{4320}Reference *") require.Equal(t, br.Format(FormatOptions{VariableLengthFields: true}), "{4320}Reference*") require.Equal(t, br.String(), br.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/beneficiary_test.go b/beneficiary_test.go index 1e71793a..0e9128b6 100644 --- a/beneficiary_test.go +++ b/beneficiary_test.go @@ -109,18 +109,18 @@ func TestBeneficiaryIdentifierRequired(t *testing.T) { // TestParseBeneficiaryWrongLength parses a wrong Beneficiary record length func TestParseBeneficiaryWrongLength(t *testing.T) { - var line = "{4200}31234 Name Address One Address Two Address Three " + var line = "{4200}31234 *Name *Address One *Address Two *Address Three " r := NewReader(strings.NewReader(line)) r.line = line err := r.parseBeneficiary() - require.EqualError(t, err, r.parseError(fieldError("AddressLineThree", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("AddressLineThree", ErrRequireDelimiter)).Error()) } // TestParseBeneficiaryReaderParseError parses a wrong Beneficiary reader parse error func TestParseBeneficiaryReaderParseError(t *testing.T) { - var line = "{4200}31234 Na®e Address One Address Two Address Three " + var line = "{4200}31234 *Na®e *Address One *Address Two *Address Three *" r := NewReader(strings.NewReader(line)) r.line = line @@ -155,12 +155,12 @@ func TestStringBeneficiaryVariableLength(t *testing.T) { expected := r.parseError(NewTagMinLengthErr(7, len(r.line))).Error() require.EqualError(t, err, expected) - line = "{4200}31234 Na®e Address One Address Two Address Three NNN" + line = "{4200}31234 *Na®e *Address One *Address Two *Address Three NNN" r = NewReader(strings.NewReader(line)) r.line = line err = r.parseBeneficiary() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{4200}31234*******" r = NewReader(strings.NewReader(line)) @@ -187,7 +187,7 @@ func TestStringBeneficiaryOptions(t *testing.T) { require.Equal(t, err, nil) ben := r.currentFEDWireMessage.Beneficiary - require.Equal(t, ben.String(), "{4200}31234 ") + require.Equal(t, ben.String(), "{4200}31234 * * * * *") require.Equal(t, ben.Format(FormatOptions{VariableLengthFields: true}), "{4200}31234*") require.Equal(t, ben.String(), ben.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/businessFunctionCode.go b/businessFunctionCode.go index 990bdb90..e13048f1 100644 --- a/businessFunctionCode.go +++ b/businessFunctionCode.go @@ -88,7 +88,7 @@ func (bfc *BusinessFunctionCode) Format(options FormatOptions) string { buf.WriteString(bfc.tag) buf.WriteString(bfc.BusinessFunctionCodeField()) - buf.WriteString(bfc.FormatTransactionTypeCode(options)) + buf.WriteString(bfc.FormatTransactionTypeCode(options) + Delimiter) return buf.String() } diff --git a/businessFunctionCode_test.go b/businessFunctionCode_test.go index 1c85d0e1..a0193a4b 100644 --- a/businessFunctionCode_test.go +++ b/businessFunctionCode_test.go @@ -56,7 +56,7 @@ func TestParseBusinessFunctionCodeWrongLength(t *testing.T) { // TestParseBusinessFunctionCodeReaderParseError parses a wrong BusinessFunctionCode reader parse error func TestParseBusinessFunctionCodeReaderParseError(t *testing.T) { - var line = "{3600}CTAXXY" + var line = "{3600}CTAXXY*" r := NewReader(strings.NewReader(line)) r.line = line @@ -96,7 +96,7 @@ func TestStringBusinessFunctionCodeVariableLength(t *testing.T) { r.line = line err = r.parseBusinessFunctionCode() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{3600}BTR***" r = NewReader(strings.NewReader(line)) @@ -123,8 +123,8 @@ func TestStringBusinessFunctionCodeOptions(t *testing.T) { require.Equal(t, err, nil) bfc := r.currentFEDWireMessage.BusinessFunctionCode - require.Equal(t, bfc.String(), "{3600}BTR ") - require.Equal(t, bfc.Format(FormatOptions{VariableLengthFields: true}), "{3600}BTR") + require.Equal(t, bfc.String(), "{3600}BTR *") + require.Equal(t, bfc.Format(FormatOptions{VariableLengthFields: true}), "{3600}BTR*") require.Equal(t, bfc.String(), bfc.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/charges.go b/charges.go index f407aaac..b5abb62d 100644 --- a/charges.go +++ b/charges.go @@ -123,10 +123,10 @@ func (c *Charges) Format(options FormatOptions) string { buf.WriteString(c.tag) buf.WriteString(c.ChargeDetailsField()) - buf.WriteString(c.FormatSendersChargesOne(options)) - buf.WriteString(c.FormatSendersChargesTwo(options)) - buf.WriteString(c.FormatSendersChargesThree(options)) - buf.WriteString(c.FormatSendersChargesFour(options)) + buf.WriteString(c.FormatSendersChargesOne(options) + Delimiter) + buf.WriteString(c.FormatSendersChargesTwo(options) + Delimiter) + buf.WriteString(c.FormatSendersChargesThree(options) + Delimiter) + buf.WriteString(c.FormatSendersChargesFour(options) + Delimiter) if options.VariableLengthFields { return c.stripDelimiters(buf.String()) diff --git a/charges_test.go b/charges_test.go index 4f3e7248..82819d7f 100644 --- a/charges_test.go +++ b/charges_test.go @@ -59,7 +59,7 @@ func TestStringChargesVariableLength(t *testing.T) { r.line = line err = r.parseCharges() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{3700}B******" r = NewReader(strings.NewReader(line)) @@ -86,7 +86,7 @@ func TestStringChargesOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.Charges - require.Equal(t, record.String(), "{3700}B ") + require.Equal(t, record.String(), "{3700}B * * * *") require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{3700}B*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/converters.go b/converters.go index 9e58f1cb..ef86d95b 100644 --- a/converters.go +++ b/converters.go @@ -10,6 +10,10 @@ import ( "strings" ) +const ( + Delimiter = "*" +) + // converters handles golang to WIRE type Converters type converters struct{} @@ -50,30 +54,30 @@ func (c *converters) alphaField(s string, max uint) string { // formatAlphaField returns the input formatted according to the FormatOptions. // If the length of s exceeds max, s will be truncated to max. If options.VariableLengthFields -// is set, any trailing whitespace is replaced with a single asterisk (*) character. +// is set, any trailing whitespace is stripped func (c *converters) formatAlphaField(s string, max uint, options FormatOptions) string { ln := uint(len(s)) if ln > max { return s[:max] } - if options.VariableLengthFields { - if max-ln > 0 { - s += "*" - } - } else { + if !options.VariableLengthFields { s += strings.Repeat(" ", int(max-ln)) } return s } -func (c *converters) parseVariableStringField(r string, maxLen int) (got string, size int, err error) { - min := func(x, y int) int { +// parseFixedStringField will use to parse for mandatory fixed length elements +// - Has fixed length +// - Not permitted Delimiter +func (c *converters) parseFixedStringField(r string, maxLen int) (got string, size int, err error) { + max := func(x, y int) int { if x > y { - return y + return x } - return x + + return y } // Omit field? @@ -81,44 +85,62 @@ func (c *converters) parseVariableStringField(r string, maxLen int) (got string, return } - endIndex := maxLen - delimiterIndex := maxLen + endIndex := -1 + delimiterIndex := -1 - if index := strings.Index(r, "*"); index > -1 { + if index := strings.Index(r, Delimiter); index > -1 { delimiterIndex = index } if index := strings.Index(r, "{"); index > -1 { endIndex = index } - hasDelimiter := false - size = min(endIndex, delimiterIndex) - if size >= maxLen { + size = max(endIndex, delimiterIndex) + if size == -1 { + size = len(r) + } + + if size > maxLen { size = maxLen - // checking delimiter if max's next position is not last post - if len(r) > maxLen+1 && r[maxLen:maxLen+1] == "*" { - hasDelimiter = true - } } else if size < maxLen { - if delimiterIndex == size { - hasDelimiter = true - } + size = 0 + err = ErrValidLength + return } - if size > len(r) { + got = strings.TrimSpace(r[:size]) + + return +} + +// parseVariableStringField will use to parse for mandatory variable length/optional fixed length/optional variable length elements +// - Has variable length +// - Always required delimiter +func (c *converters) parseVariableStringField(r string, maxLen int) (got string, size int, err error) { + // Omit field? + if len(r) == 0 { + return + } + + if index := strings.Index(r, Delimiter); index > -1 { + size = index + } else { size = 0 - err = ErrValidLength + err = ErrRequireDelimiter return } - if got = strings.TrimSpace(r[:size]); got == "*" { + if got = strings.TrimSpace(r[:size]); got == Delimiter { got = "" } - if hasDelimiter { - size++ + if len(got) > maxLen { + got = got[:maxLen] } + // skip delimiter + size++ + return } @@ -144,7 +166,7 @@ func (c *converters) stripDelimiters(data string) string { inspectLetter1 := string(data[i]) inspectLetter2 := string(data[i-1]) - if inspectLetter1 != "*" || inspectLetter2 != "*" || i == 6 { + if inspectLetter1 != Delimiter || inspectLetter2 != Delimiter || i == 6 { index = i + 1 break } @@ -160,7 +182,7 @@ func (c *converters) verifyDataWithReadLength(data string, expected int) error { if n == expected { return nil } - if n > expected && data[expected:] == "*" { + if n > expected && data[expected:] == Delimiter { return nil } return fmt.Errorf("found data of %d length but expected %d", n, expected) diff --git a/converters_test.go b/converters_test.go index 3c255485..7e14352a 100644 --- a/converters_test.go +++ b/converters_test.go @@ -5,6 +5,7 @@ package wire import ( + "fmt" "testing" "github.com/stretchr/testify/require" @@ -33,42 +34,152 @@ func TestConverters__parseFirstOption(t *testing.T) { } func TestConverters__parseVariableStringField(t *testing.T) { - c := &converters{} - - got, size, err := c.parseVariableStringField("1234{0000}56789", 3) - require.Equal(t, "123", got) - require.Equal(t, 3, size) - require.Nil(t, err) - - got, size, err = c.parseVariableStringField("1234{0000}56789", 4) - require.Equal(t, "1234", got) - require.Equal(t, 4, size) - require.Nil(t, err) - got, size, err = c.parseVariableStringField("1234{0000}56789", 5) - require.Equal(t, "1234", got) - require.Equal(t, 4, size) - require.Nil(t, err) + tests := []struct { + input string + maxLength int + want string + gotSize int + err error + }{ + { + input: "1234{0000}56789", + maxLength: 3, + want: "", + gotSize: 0, + err: ErrRequireDelimiter, + }, + { + input: "1234{0000}56789", + maxLength: 4, + want: "", + gotSize: 0, + err: ErrRequireDelimiter, + }, + { + input: "1234{0000}56789", + maxLength: 5, + want: "", + gotSize: 0, + err: ErrRequireDelimiter, + }, + { + input: "123456789", + maxLength: 5, + want: "", + gotSize: 0, + err: ErrRequireDelimiter, + }, + { + input: "1234*56789", + maxLength: 5, + want: "1234", + gotSize: 5, + err: nil, + }, + { + input: "1234*56789", + maxLength: 4, + want: "1234", + gotSize: 5, + err: nil, + }, + { + input: "1234*56789", + maxLength: 3, + want: "123", + gotSize: 5, + err: nil, + }, + { + input: "*123456789", + maxLength: 3, + want: "", + gotSize: 1, + err: nil, + }, + } + c := &converters{} - got, size, err = c.parseVariableStringField("1234*56789", 7) - require.Equal(t, "1234", got) - require.Equal(t, 5, size) - require.Nil(t, err) + for index, tt := range tests { + t.Run(fmt.Sprintf("sub_%d", index), func(t *testing.T) { + got, size, err := c.parseVariableStringField(tt.input, tt.maxLength) + require.Equal(t, tt.want, got) + require.Equal(t, tt.gotSize, size) + require.Equal(t, tt.err, err) + }) + } +} - got, size, err = c.parseVariableStringField("1234*56789", 3) - require.Equal(t, "123", got) - require.Equal(t, 3, size) - require.Nil(t, err) +func TestConverters__parseFixedStringField(t *testing.T) { - got, size, err = c.parseVariableStringField("123*567", 3) - require.Equal(t, "123", got) - require.Equal(t, 4, size) - require.Nil(t, err) + tests := []struct { + input string + maxLength int + want string + gotSize int + err error + }{ + { + input: "1234{0000}56789", + maxLength: 3, + want: "123", + gotSize: 3, + err: nil, + }, + { + input: "1234{0000}56789", + maxLength: 4, + want: "1234", + gotSize: 4, + err: nil, + }, + { + input: "1234{0000}56789", + maxLength: 5, + want: "", + gotSize: 0, + err: ErrValidLength, + }, + { + input: "1234*56789", + maxLength: 5, + want: "", + gotSize: 0, + err: ErrValidLength, + }, + { + input: "1234*56789", + maxLength: 4, + want: "1234", + gotSize: 4, + err: nil, + }, + { + input: "1234*56789", + maxLength: 3, + want: "123", + gotSize: 3, + err: nil, + }, + { + input: "*123456789", + maxLength: 3, + want: "", + gotSize: 0, + err: ErrValidLength, + }, + } + c := &converters{} - got, size, err = c.parseVariableStringField("123*", 3) - require.Equal(t, "123", got) - require.Equal(t, 3, size) - require.Nil(t, err) + for index, tt := range tests { + t.Run(fmt.Sprintf("sub_%d", index), func(t *testing.T) { + got, size, err := c.parseFixedStringField(tt.input, tt.maxLength) + require.Equal(t, tt.want, got) + require.Equal(t, tt.gotSize, size) + require.Equal(t, tt.err, err) + }) + } } func TestConverters_alphaVariableField(t *testing.T) { @@ -100,7 +211,7 @@ func TestConverters_alphaVariableField(t *testing.T) { input: "{0000}12", variableLength: true, maxLength: 10, - want: "{0000}12*", + want: "{0000}12", }, } c := &converters{} diff --git a/currencyInstructedAmount.go b/currencyInstructedAmount.go index 5d47a641..93fa5569 100644 --- a/currencyInstructedAmount.go +++ b/currencyInstructedAmount.go @@ -53,12 +53,12 @@ func (cia *CurrencyInstructedAmount) Parse(record string) error { cia.SwiftFieldTag = value length += read - if len(record) < length+18 { - return fieldError("Amount", ErrValidLength) + value, read, err = cia.parseVariableStringField(record[length:], 18) + if err != nil { + return fieldError("Amount", err) } - - cia.Amount = cia.parseStringField(record[length : length+18]) - length += 18 + cia.Amount = value + length += read if err := cia.verifyDataWithReadLength(record, length); err != nil { return NewTagMaxLengthErr(err) @@ -94,8 +94,8 @@ func (cia *CurrencyInstructedAmount) Format(options FormatOptions) string { buf.Grow(29) buf.WriteString(cia.tag) - buf.WriteString(cia.FormatSwiftFieldTag(options)) - buf.WriteString(cia.AmountField()) + buf.WriteString(cia.FormatSwiftFieldTag(options) + Delimiter) + buf.WriteString(cia.FormatAmount(options) + Delimiter) return buf.String() } @@ -127,6 +127,11 @@ func (cia *CurrencyInstructedAmount) AmountField() string { return cia.numericStringField(cia.Amount, 18) } +// FormatAmount gets a string of the AmountTag formatted according to the FormatOptions +func (cia *CurrencyInstructedAmount) FormatAmount(options FormatOptions) string { + return cia.formatAlphaField(cia.Amount, 18, options) +} + // FormatSwiftFieldTag returns SwiftFieldTag formatted according to the FormatOptions func (cia *CurrencyInstructedAmount) FormatSwiftFieldTag(options FormatOptions) string { return cia.formatAlphaField(cia.SwiftFieldTag, 5, options) diff --git a/currencyInstructedAmount_test.go b/currencyInstructedAmount_test.go index 5f2815e0..82712f50 100644 --- a/currencyInstructedAmount_test.go +++ b/currencyInstructedAmount_test.go @@ -1,7 +1,6 @@ package wire import ( - "errors" "strings" "testing" @@ -45,22 +44,22 @@ func TestCurrencyInstructedAmountValid(t *testing.T) { // TestParseCurrencyInstructedAmountWrongLength parses a wrong CurrencyInstructedAmount record length func TestParseCurrencyInstructedAmountWrongLength(t *testing.T) { - var line = "{7033}Swift000000000001500,4" + var line = "{7033}Swift*000000000001500,4" r := NewReader(strings.NewReader(line)) r.line = line err := r.parseCurrencyInstructedAmount() - require.EqualError(t, err, r.parseError(fieldError("Amount", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("Amount", ErrRequireDelimiter)).Error()) _, err = r.Read() - require.EqualError(t, err, r.parseError(fieldError("Amount", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("Amount", ErrRequireDelimiter)).Error()) } // TestParseCurrencyInstructedAmountReaderParseError parses a wrong CurrencyInstructedAmount reader parse error func TestParseCurrencyInstructedAmountReaderParseError(t *testing.T) { - var line = "{7033}Swift00000000Z001500,49" + var line = "{7033}Swift*00000000Z001500,49*" r := NewReader(strings.NewReader(line)) r.line = line @@ -85,7 +84,7 @@ func TestCurrencyInstructedAmountTagError(t *testing.T) { // TestStringCurrencyInstructedAmountVariableLength parses using variable length func TestStringCurrencyInstructedAmountVariableLength(t *testing.T) { - var line = "{7033}*000000000001500,49" + var line = "{7033}*000000000001500,49*" r := NewReader(strings.NewReader(line)) r.line = line @@ -97,12 +96,12 @@ func TestStringCurrencyInstructedAmountVariableLength(t *testing.T) { r.line = line err = r.parseCurrencyInstructedAmount() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) } // TestStringCurrencyInstructedAmountOptions validates Format() formatted according to the FormatOptions func TestStringCurrencyInstructedAmountOptions(t *testing.T) { - var line = "{7033}*000000000001500,49" + var line = "{7033}*000000000001500,49*" r := NewReader(strings.NewReader(line)) r.line = line @@ -110,7 +109,7 @@ func TestStringCurrencyInstructedAmountOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.CurrencyInstructedAmount - require.Equal(t, record.String(), "{7033} 000000000001500,49") - require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{7033}*000000000001500,49") + require.Equal(t, record.String(), "{7033} *000000000001500,49*") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{7033}*000000000001500,49*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/errorWire.go b/errorWire.go index b542ee22..bcdda83b 100644 --- a/errorWire.go +++ b/errorWire.go @@ -47,14 +47,14 @@ func (ew *ErrorWire) Parse(record string) error { ew.tag = record[:6] length := 6 - value, read, err := ew.parseVariableStringField(record[length:], 1) + value, read, err := ew.parseFixedStringField(record[length:], 1) if err != nil { return fieldError("ErrorCategory", err) } ew.ErrorCategory = value length += read - value, read, err = ew.parseVariableStringField(record[length:], 3) + value, read, err = ew.parseFixedStringField(record[length:], 3) if err != nil { return fieldError("ErrorCode", err) } @@ -102,9 +102,9 @@ func (ew *ErrorWire) Format(options FormatOptions) string { buf.Grow(45) buf.WriteString(ew.tag) - buf.WriteString(ew.FormatErrorCategory(options)) - buf.WriteString(ew.FormatErrorCode(options)) - buf.WriteString(ew.FormatErrorDescription(options)) + buf.WriteString(ew.ErrorCategoryField()) + buf.WriteString(ew.ErrorCodeField()) + buf.WriteString(ew.FormatErrorDescription(options) + Delimiter) if options.VariableLengthFields { return ew.stripDelimiters(buf.String()) diff --git a/errorWire_test.go b/errorWire_test.go index d9d5f244..c3d864ee 100644 --- a/errorWire_test.go +++ b/errorWire_test.go @@ -27,7 +27,7 @@ func TestMockErrorWire(t *testing.T) { // TestParseErrorWire parses a known ErrorWire record string func TestParseErrorWire(t *testing.T) { - var line = "{1130}1XYZData Error " + var line = "{1130}1XYZData Error *" r := NewReader(strings.NewReader(line)) r.line = line @@ -41,7 +41,7 @@ func TestParseErrorWire(t *testing.T) { // TestWriteErrorWire writes a ErrorWire record string func TestWriteErrorWire(t *testing.T) { - var line = "{1130}1XYZData Error " + var line = "{1130}1XYZData Error *" r := NewReader(strings.NewReader(line)) r.line = line require.NoError(t, r.parseErrorWire()) @@ -64,7 +64,7 @@ func TestStringErrorWireAmountVariableLength(t *testing.T) { r.line = line err = r.parseErrorWire() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{1130}1XYZData Error***" r = NewReader(strings.NewReader(line)) @@ -91,7 +91,7 @@ func TestStringErrorWireOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.ErrorWire - require.Equal(t, record.String(), "{1130}1XYZData Error ") + require.Equal(t, record.String(), "{1130}1XYZData Error *") require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{1130}1XYZData Error*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/exchangeRate.go b/exchangeRate.go index f6e07faa..ba2cd9e2 100644 --- a/exchangeRate.go +++ b/exchangeRate.go @@ -85,7 +85,7 @@ func (eRate *ExchangeRate) Format(options FormatOptions) string { buf.Grow(18) buf.WriteString(eRate.tag) - buf.WriteString(eRate.FormatExchangeRate(options)) + buf.WriteString(eRate.FormatExchangeRate(options) + Delimiter) if options.VariableLengthFields { return eRate.stripDelimiters(buf.String()) diff --git a/exchangeRate_test.go b/exchangeRate_test.go index 30e83c1e..c2cd2656 100644 --- a/exchangeRate_test.go +++ b/exchangeRate_test.go @@ -40,16 +40,16 @@ func TestParseExchangeRateWrongLength(t *testing.T) { err := r.parseExchangeRate() - require.EqualError(t, err, r.parseError(fieldError("ExchangeRate", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("ExchangeRate", ErrRequireDelimiter)).Error()) _, err = r.Read() - require.EqualError(t, err, r.parseError(fieldError("ExchangeRate", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("ExchangeRate", ErrRequireDelimiter)).Error()) } // TestParseExchangeRateReaderParseError parses a wrong ExchangeRate reader parse error func TestParseExchangeRateReaderParseError(t *testing.T) { - var line = "{3720}1,2345Z " + var line = "{3720}1,2345Z *" r := NewReader(strings.NewReader(line)) r.line = line @@ -86,7 +86,7 @@ func TestStringErrorExchangeRateVariableLength(t *testing.T) { r.line = line err = r.parseExchangeRate() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{3720}123***" r = NewReader(strings.NewReader(line)) @@ -113,7 +113,7 @@ func TestStringExchangeRateOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.ExchangeRate - require.Equal(t, record.String(), "{3720}123 ") + require.Equal(t, record.String(), "{3720}123 *") require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{3720}123*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/fIBeneficiaryFIAdvice.go b/fIBeneficiaryFIAdvice.go index bfbecbce..66711e63 100644 --- a/fIBeneficiaryFIAdvice.go +++ b/fIBeneficiaryFIAdvice.go @@ -121,12 +121,12 @@ func (fibfia *FIBeneficiaryFIAdvice) Format(options FormatOptions) string { buf.WriteString(fibfia.tag) buf.WriteString(fibfia.AdviceCodeField()) - buf.WriteString(fibfia.FormatLineOne(options)) - buf.WriteString(fibfia.FormatLineTwo(options)) - buf.WriteString(fibfia.FormatLineThree(options)) - buf.WriteString(fibfia.FormatLineFour(options)) - buf.WriteString(fibfia.FormatLineFive(options)) - buf.WriteString(fibfia.FormatLineSix(options)) + buf.WriteString(fibfia.FormatLineOne(options) + Delimiter) + buf.WriteString(fibfia.FormatLineTwo(options) + Delimiter) + buf.WriteString(fibfia.FormatLineThree(options) + Delimiter) + buf.WriteString(fibfia.FormatLineFour(options) + Delimiter) + buf.WriteString(fibfia.FormatLineFive(options) + Delimiter) + buf.WriteString(fibfia.FormatLineSix(options) + Delimiter) if options.VariableLengthFields { return fibfia.stripDelimiters(buf.String()) diff --git a/fIBeneficiaryFIAdvice_test.go b/fIBeneficiaryFIAdvice_test.go index 2c098564..ea9c8499 100644 --- a/fIBeneficiaryFIAdvice_test.go +++ b/fIBeneficiaryFIAdvice_test.go @@ -106,12 +106,12 @@ func TestParseFIBeneficiaryFIAdviceWrongLength(t *testing.T) { err := r.parseFIBeneficiaryFIAdvice() - require.EqualError(t, err, r.parseError(fieldError("LineSix", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("LineOne", ErrRequireDelimiter)).Error()) } // TestParseFIBeneficiaryFIAdviceReaderParseError parses a wrong FIBeneficiaryFIAdvice reader parse error func TestParseFIBeneficiaryFIAdviceReaderParseError(t *testing.T) { - var line = "{6310}TLXLine ®ne Line Two Line Three Line Four Line Five Line Six " + var line = "{6310}TLXLine ®ne *Line Two *Line Three *Line Four *Line Five *Line Six *" r := NewReader(strings.NewReader(line)) r.line = line @@ -150,7 +150,7 @@ func TestStringFIBeneficiaryFIAdviceVariableLength(t *testing.T) { r.line = line err = r.parseFIBeneficiaryFIAdvice() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{6310}HLD********" r = NewReader(strings.NewReader(line)) @@ -177,7 +177,7 @@ func TestStringFIBeneficiaryFIAdviceOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.FIBeneficiaryFIAdvice - require.Equal(t, record.String(), "{6310}HLD ") + require.Equal(t, record.String(), "{6310}HLD * * * * * *") require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{6310}HLD*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/fiAdditionalFIToFI.go b/fiAdditionalFIToFI.go index 98f149da..96c20900 100644 --- a/fiAdditionalFIToFI.go +++ b/fiAdditionalFIToFI.go @@ -119,12 +119,12 @@ func (fifi *FIAdditionalFIToFI) Format(options FormatOptions) string { buf.Grow(216) buf.WriteString(fifi.tag) - buf.WriteString(fifi.FormatLineOne(options)) - buf.WriteString(fifi.FormatLineTwo(options)) - buf.WriteString(fifi.FormatLineThree(options)) - buf.WriteString(fifi.FormatLineFour(options)) - buf.WriteString(fifi.FormatLineFive(options)) - buf.WriteString(fifi.FormatLineSix(options)) + buf.WriteString(fifi.FormatLineOne(options) + Delimiter) + buf.WriteString(fifi.FormatLineTwo(options) + Delimiter) + buf.WriteString(fifi.FormatLineThree(options) + Delimiter) + buf.WriteString(fifi.FormatLineFour(options) + Delimiter) + buf.WriteString(fifi.FormatLineFive(options) + Delimiter) + buf.WriteString(fifi.FormatLineSix(options) + Delimiter) if options.VariableLengthFields { return fifi.stripDelimiters(buf.String()) diff --git a/fiAdditionalFIToFI_test.go b/fiAdditionalFIToFI_test.go index ecc1c829..1683296a 100644 --- a/fiAdditionalFIToFI_test.go +++ b/fiAdditionalFIToFI_test.go @@ -94,12 +94,12 @@ func TestParseFIAdditionalFIToFIWrongLength(t *testing.T) { r.line = line err := r.parseFIAdditionalFIToFI() - require.EqualError(t, err, r.parseError(fieldError("LineSix", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("LineOne", ErrRequireDelimiter)).Error()) } // TestParseFIAdditionalFIToFIReaderParseError parses a wrong FIAdditionalFIToFI reader parse error func TestParseFIAdditionalFIToFIReaderParseError(t *testing.T) { - var line = "{6500}®ine One Line Two Line Three Line Four Line Five Line Six " + var line = "{6500}®ine One *Line Two *Line Three *Line Four *Line Five *Line Six *" r := NewReader(strings.NewReader(line)) r.line = line @@ -138,7 +138,7 @@ func TestStringFIAdditionalFIToFIVariableLength(t *testing.T) { r.line = line err = r.parseFIAdditionalFIToFI() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{6500}********" r = NewReader(strings.NewReader(line)) @@ -165,7 +165,7 @@ func TestStringFIAdditionalFIToFIOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.FIAdditionalFIToFI - require.Equal(t, record.String(), "{6500} ") + require.Equal(t, record.String(), "{6500} * * * * * *") require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{6500}*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/fiBeneficiary.go b/fiBeneficiary.go index 6ad0e66c..33c8e1d3 100644 --- a/fiBeneficiary.go +++ b/fiBeneficiary.go @@ -119,12 +119,12 @@ func (fib *FIBeneficiary) Format(options FormatOptions) string { buf.Grow(201) buf.WriteString(fib.tag) - buf.WriteString(fib.FormatLineOne(options)) - buf.WriteString(fib.FormatLineTwo(options)) - buf.WriteString(fib.FormatLineThree(options)) - buf.WriteString(fib.FormatLineFour(options)) - buf.WriteString(fib.FormatLineFive(options)) - buf.WriteString(fib.FormatLineSix(options)) + buf.WriteString(fib.FormatLineOne(options) + Delimiter) + buf.WriteString(fib.FormatLineTwo(options) + Delimiter) + buf.WriteString(fib.FormatLineThree(options) + Delimiter) + buf.WriteString(fib.FormatLineFour(options) + Delimiter) + buf.WriteString(fib.FormatLineFive(options) + Delimiter) + buf.WriteString(fib.FormatLineSix(options) + Delimiter) if options.VariableLengthFields { return fib.stripDelimiters(buf.String()) diff --git a/fiBeneficiaryAdvice.go b/fiBeneficiaryAdvice.go index 505b73a7..3bec6710 100644 --- a/fiBeneficiaryAdvice.go +++ b/fiBeneficiaryAdvice.go @@ -121,12 +121,12 @@ func (fiba *FIBeneficiaryAdvice) Format(options FormatOptions) string { buf.WriteString(fiba.tag) buf.WriteString(fiba.AdviceCodeField()) - buf.WriteString(fiba.FormatLineOne(options)) - buf.WriteString(fiba.FormatLineTwo(options)) - buf.WriteString(fiba.FormatLineThree(options)) - buf.WriteString(fiba.FormatLineFour(options)) - buf.WriteString(fiba.FormatLineFive(options)) - buf.WriteString(fiba.FormatLineSix(options)) + buf.WriteString(fiba.FormatLineOne(options) + Delimiter) + buf.WriteString(fiba.FormatLineTwo(options) + Delimiter) + buf.WriteString(fiba.FormatLineThree(options) + Delimiter) + buf.WriteString(fiba.FormatLineFour(options) + Delimiter) + buf.WriteString(fiba.FormatLineFive(options) + Delimiter) + buf.WriteString(fiba.FormatLineSix(options) + Delimiter) if options.VariableLengthFields { return fiba.stripDelimiters(buf.String()) diff --git a/fiBeneficiaryAdvice_test.go b/fiBeneficiaryAdvice_test.go index 201e9e0f..ded25ba1 100644 --- a/fiBeneficiaryAdvice_test.go +++ b/fiBeneficiaryAdvice_test.go @@ -99,12 +99,12 @@ func TestParseFIBeneficiaryAdviceWrongLength(t *testing.T) { err := r.parseFIBeneficiaryAdvice() - require.EqualError(t, err, r.parseError(fieldError("LineSix", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("LineOne", ErrRequireDelimiter)).Error()) } // TestParseFIBeneficiaryAdviceReaderParseError parses a wrong FIBeneficiaryAdvice reader parse error func TestParseFIBeneficiaryAdviceReaderParseError(t *testing.T) { - var line = "{6410}LTRLine ®ne Line Two Line Three Line Four Line Five Line Six " + var line = "{6410}LTRLine ®ne *Line Two *Line Three *Line Four *Line Five *Line Six *" r := NewReader(strings.NewReader(line)) r.line = line @@ -141,7 +141,7 @@ func TestStringFIBeneficiaryAdviceVariableLength(t *testing.T) { r.line = line err = r.parseFIBeneficiaryAdvice() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{6410}HLD********" r = NewReader(strings.NewReader(line)) @@ -168,7 +168,7 @@ func TestStringFIBeneficiaryAdviceOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.FIBeneficiaryAdvice - require.Equal(t, record.String(), "{6410}HLD ") + require.Equal(t, record.String(), "{6410}HLD * * * * * *") require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{6410}HLD*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/fiBeneficiaryFI.go b/fiBeneficiaryFI.go index 3906e8ef..289a72f3 100644 --- a/fiBeneficiaryFI.go +++ b/fiBeneficiaryFI.go @@ -119,12 +119,12 @@ func (fibfi *FIBeneficiaryFI) Format(options FormatOptions) string { buf.Grow(201) buf.WriteString(fibfi.tag) - buf.WriteString(fibfi.FormatLineOne(options)) - buf.WriteString(fibfi.FormatLineTwo(options)) - buf.WriteString(fibfi.FormatLineThree(options)) - buf.WriteString(fibfi.FormatLineFour(options)) - buf.WriteString(fibfi.FormatLineFive(options)) - buf.WriteString(fibfi.FormatLineSix(options)) + buf.WriteString(fibfi.FormatLineOne(options) + Delimiter) + buf.WriteString(fibfi.FormatLineTwo(options) + Delimiter) + buf.WriteString(fibfi.FormatLineThree(options) + Delimiter) + buf.WriteString(fibfi.FormatLineFour(options) + Delimiter) + buf.WriteString(fibfi.FormatLineFive(options) + Delimiter) + buf.WriteString(fibfi.FormatLineSix(options) + Delimiter) if options.VariableLengthFields { return fibfi.stripDelimiters(buf.String()) diff --git a/fiBeneficiaryFI_test.go b/fiBeneficiaryFI_test.go index cc0db3ae..31443063 100644 --- a/fiBeneficiaryFI_test.go +++ b/fiBeneficiaryFI_test.go @@ -95,12 +95,12 @@ func TestParseFIBeneficiaryFIWrongLength(t *testing.T) { err := r.parseFIBeneficiaryFI() - require.EqualError(t, err, r.parseError(fieldError("LineSix", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("LineOne", ErrRequireDelimiter)).Error()) } // TestParseFIBeneficiaryFIReaderParseError parses a wrong FIBeneficiaryFI reader parse error func TestParseFIBeneficiaryFIReaderParseError(t *testing.T) { - var line = "{6300}Line ®ne Line Two Line Three Line Four Line Five Line Six " + var line = "{6300}Line ®ne *Line Two *Line Three *Line Four *Line Five *Line Six *" r := NewReader(strings.NewReader(line)) r.line = line @@ -139,7 +139,7 @@ func TestStringFIBeneficiaryFIVariableLength(t *testing.T) { r.line = line err = r.parseFIBeneficiaryFI() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{6300}********" r = NewReader(strings.NewReader(line)) @@ -166,7 +166,7 @@ func TestStringFIBeneficiaryFIToFIOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.FIBeneficiaryFI - require.Equal(t, record.String(), "{6300} ") + require.Equal(t, record.String(), "{6300} * * * * * *") require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{6300}*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/fiBeneficiary_test.go b/fiBeneficiary_test.go index 81bfb504..ff60d1e2 100644 --- a/fiBeneficiary_test.go +++ b/fiBeneficiary_test.go @@ -94,12 +94,12 @@ func TestParseFIBeneficiaryWrongLength(t *testing.T) { r.line = line err := r.parseFIBeneficiary() - require.EqualError(t, err, r.parseError(fieldError("LineSix", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("LineOne", ErrRequireDelimiter)).Error()) } // TestParseFIBeneficiaryReaderParseError parses a wrong FIBeneficiary reader parse error func TestParseFIBeneficiaryReaderParseError(t *testing.T) { - var line = "{6400}Line Si® " + var line = "{6400}Line Si® *" r := NewReader(strings.NewReader(line)) r.line = line @@ -138,7 +138,7 @@ func TestStringFIBeneficiaryVariableLength(t *testing.T) { r.line = line err = r.parseFIBeneficiary() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{6400}********" r = NewReader(strings.NewReader(line)) @@ -165,7 +165,7 @@ func TestStringFIBeneficiaryOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.FIBeneficiary - require.Equal(t, record.String(), "{6400} ") + require.Equal(t, record.String(), "{6400} * * * * * *") require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{6400}*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/fiDrawdownDebitAccountAdvice.go b/fiDrawdownDebitAccountAdvice.go index c734abd0..6e072072 100644 --- a/fiDrawdownDebitAccountAdvice.go +++ b/fiDrawdownDebitAccountAdvice.go @@ -121,12 +121,12 @@ func (debitDDAdvice *FIDrawdownDebitAccountAdvice) Format(options FormatOptions) buf.WriteString(debitDDAdvice.tag) buf.WriteString(debitDDAdvice.AdviceCodeField()) - buf.WriteString(debitDDAdvice.FormatLineOne(options)) - buf.WriteString(debitDDAdvice.FormatLineTwo(options)) - buf.WriteString(debitDDAdvice.FormatLineThree(options)) - buf.WriteString(debitDDAdvice.FormatLineFour(options)) - buf.WriteString(debitDDAdvice.FormatLineFive(options)) - buf.WriteString(debitDDAdvice.FormatLineSix(options)) + buf.WriteString(debitDDAdvice.FormatLineOne(options) + Delimiter) + buf.WriteString(debitDDAdvice.FormatLineTwo(options) + Delimiter) + buf.WriteString(debitDDAdvice.FormatLineThree(options) + Delimiter) + buf.WriteString(debitDDAdvice.FormatLineFour(options) + Delimiter) + buf.WriteString(debitDDAdvice.FormatLineFive(options) + Delimiter) + buf.WriteString(debitDDAdvice.FormatLineSix(options) + Delimiter) if options.VariableLengthFields { return debitDDAdvice.stripDelimiters(buf.String()) diff --git a/fiDrawdownDebitAccountAdvice_test.go b/fiDrawdownDebitAccountAdvice_test.go index 1645b1d5..79547bfb 100644 --- a/fiDrawdownDebitAccountAdvice_test.go +++ b/fiDrawdownDebitAccountAdvice_test.go @@ -106,12 +106,12 @@ func TestParseFIDrawdownDebitAccountAdviceWrongLength(t *testing.T) { err := r.parseFIDrawdownDebitAccountAdvice() - require.EqualError(t, err, r.parseError(fieldError("LineSix", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("LineOne", ErrRequireDelimiter)).Error()) } // TestParseFIDrawdownDebitAccountAdviceReaderParseError parses a wrong FIDrawdownDebitAccountAdvice reader parse error func TestParseFIDrawdownDebitAccountAdviceReaderParseError(t *testing.T) { - var line = "{6110}LTR®ine One Line Two Line Three Line Four Line Five Line Six " + var line = "{6110}LTR®ine One *Line Two *Line Three *Line Four *Line Five *Line Six *" r := NewReader(strings.NewReader(line)) r.line = line @@ -150,7 +150,7 @@ func TestStringFIDrawdownDebitAccountAdviceVariableLength(t *testing.T) { r.line = line err = r.parseFIDrawdownDebitAccountAdvice() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{6110}HLD********" r = NewReader(strings.NewReader(line)) @@ -177,7 +177,7 @@ func TestStringFIDrawdownDebitAccountAdviceOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.FIDrawdownDebitAccountAdvice - require.Equal(t, record.String(), "{6110}HLD ") + require.Equal(t, record.String(), "{6110}HLD * * * * * *") require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{6110}HLD*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/fiIntermediaryFI.go b/fiIntermediaryFI.go index fd2a7e2a..e49cea12 100644 --- a/fiIntermediaryFI.go +++ b/fiIntermediaryFI.go @@ -119,12 +119,12 @@ func (fiifi *FIIntermediaryFI) Format(options FormatOptions) string { buf.Grow(201) buf.WriteString(fiifi.tag) - buf.WriteString(fiifi.FormatLineOne(options)) - buf.WriteString(fiifi.FormatLineTwo(options)) - buf.WriteString(fiifi.FormatLineThree(options)) - buf.WriteString(fiifi.FormatLineFour(options)) - buf.WriteString(fiifi.FormatLineFive(options)) - buf.WriteString(fiifi.FormatLineSix(options)) + buf.WriteString(fiifi.FormatLineOne(options) + Delimiter) + buf.WriteString(fiifi.FormatLineTwo(options) + Delimiter) + buf.WriteString(fiifi.FormatLineThree(options) + Delimiter) + buf.WriteString(fiifi.FormatLineFour(options) + Delimiter) + buf.WriteString(fiifi.FormatLineFive(options) + Delimiter) + buf.WriteString(fiifi.FormatLineSix(options) + Delimiter) if options.VariableLengthFields { return fiifi.stripDelimiters(buf.String()) diff --git a/fiIntermediaryFIAdvice.go b/fiIntermediaryFIAdvice.go index 2ce46b97..082ba619 100644 --- a/fiIntermediaryFIAdvice.go +++ b/fiIntermediaryFIAdvice.go @@ -121,12 +121,12 @@ func (fiifia *FIIntermediaryFIAdvice) Format(options FormatOptions) string { buf.WriteString(fiifia.tag) buf.WriteString(fiifia.AdviceCodeField()) - buf.WriteString(fiifia.FormatLineOne(options)) - buf.WriteString(fiifia.FormatLineTwo(options)) - buf.WriteString(fiifia.FormatLineThree(options)) - buf.WriteString(fiifia.FormatLineFour(options)) - buf.WriteString(fiifia.FormatLineFive(options)) - buf.WriteString(fiifia.FormatLineSix(options)) + buf.WriteString(fiifia.FormatLineOne(options) + Delimiter) + buf.WriteString(fiifia.FormatLineTwo(options) + Delimiter) + buf.WriteString(fiifia.FormatLineThree(options) + Delimiter) + buf.WriteString(fiifia.FormatLineFour(options) + Delimiter) + buf.WriteString(fiifia.FormatLineFive(options) + Delimiter) + buf.WriteString(fiifia.FormatLineSix(options) + Delimiter) if options.VariableLengthFields { return fiifia.stripDelimiters(buf.String()) diff --git a/fiIntermediaryFIAdvice_test.go b/fiIntermediaryFIAdvice_test.go index 95134732..8196f5b8 100644 --- a/fiIntermediaryFIAdvice_test.go +++ b/fiIntermediaryFIAdvice_test.go @@ -105,12 +105,12 @@ func TestParseFIIntermediaryFIAdviceWrongLength(t *testing.T) { r.line = line err := r.parseFIIntermediaryFIAdvice() - require.EqualError(t, err, r.parseError(fieldError("LineSix", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("LineOne", ErrRequireDelimiter)).Error()) } // TestParseFIIntermediaryFIAdviceReaderParseError parses a wrong FIIntermediaryFIAdvice reader parse error func TestParseFIIntermediaryFIAdviceReaderParseError(t *testing.T) { - var line = "{6210}LTRLine ®ne Line Two Line Three Line Four Line Five Line Six " + var line = "{6210}LTRLine ®ne *Line Two *Line Three *Line Four *Line Five *Line Six *" r := NewReader(strings.NewReader(line)) r.line = line @@ -149,7 +149,7 @@ func TestStringFIIntermediaryFIAdviceVariableLength(t *testing.T) { r.line = line err = r.parseFIIntermediaryFIAdvice() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{6210}HLD********" r = NewReader(strings.NewReader(line)) @@ -176,7 +176,7 @@ func TestStringFIIntermediaryFIAdviceOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.FIIntermediaryFIAdvice - require.Equal(t, record.String(), "{6210}HLD ") + require.Equal(t, record.String(), "{6210}HLD * * * * * *") require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{6210}HLD*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/fiIntermediaryFI_test.go b/fiIntermediaryFI_test.go index 158c1145..a6ba8fdb 100644 --- a/fiIntermediaryFI_test.go +++ b/fiIntermediaryFI_test.go @@ -94,12 +94,12 @@ func TestParseFIIntermediaryFIWrongLength(t *testing.T) { r.line = line err := r.parseFIIntermediaryFI() - require.EqualError(t, err, r.parseError(fieldError("LineSix", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("LineOne", ErrRequireDelimiter)).Error()) } // TestParseFIIntermediaryFIReaderParseError parses a wrong FIIntermediaryFI reader parse error func TestParseFIIntermediaryFIReaderParseError(t *testing.T) { - var line = "{6200}Line ®ix " + var line = "{6200}Line ®ix *" r := NewReader(strings.NewReader(line)) r.line = line @@ -138,7 +138,7 @@ func TestStringFIIntermediaryFIVariableLength(t *testing.T) { r.line = line err = r.parseFIIntermediaryFI() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{6200}********" r = NewReader(strings.NewReader(line)) @@ -165,7 +165,7 @@ func TestStringFIIntermediaryFIOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.FIIntermediaryFI - require.Equal(t, record.String(), "{6200} ") + require.Equal(t, record.String(), "{6200} * * * * * *") require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{6200}*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/fiPaymentMethodToBeneficiary.go b/fiPaymentMethodToBeneficiary.go index 1cffc112..ce0d9390 100644 --- a/fiPaymentMethodToBeneficiary.go +++ b/fiPaymentMethodToBeneficiary.go @@ -89,7 +89,7 @@ func (pm *FIPaymentMethodToBeneficiary) Format(options FormatOptions) string { buf.WriteString(pm.tag) buf.WriteString(pm.PaymentMethodField()) - buf.WriteString(pm.FormatAdditionalInformation(options)) + buf.WriteString(pm.FormatAdditionalInformation(options) + Delimiter) return buf.String() } diff --git a/fiPaymentMethodToBeneficiary_test.go b/fiPaymentMethodToBeneficiary_test.go index 7c4219fd..45301bd3 100644 --- a/fiPaymentMethodToBeneficiary_test.go +++ b/fiPaymentMethodToBeneficiary_test.go @@ -50,12 +50,12 @@ func TestParseFIPaymentMethodToBeneficiaryWrongLength(t *testing.T) { r.line = line err := r.parseFIPaymentMethodToBeneficiary() - require.EqualError(t, err, r.parseError(fieldError("AdditionalInformation", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("AdditionalInformation", ErrRequireDelimiter)).Error()) } // TestParseFIPaymentMethodToBeneficiaryReaderParseError parses a wrong FIPaymentMethodToBeneficiary reader parse error func TestParseFIPaymentMethodToBeneficiaryReaderParseError(t *testing.T) { - var line = "{6420}CHECK®dditional Information " + var line = "{6420}CHECK®dditional Information *" r := NewReader(strings.NewReader(line)) r.line = line @@ -94,7 +94,7 @@ func TestStringFIPaymentMethodToBeneficiaryVariableLength(t *testing.T) { r.line = line err = r.parseFIPaymentMethodToBeneficiary() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{6420}CHECK***" r = NewReader(strings.NewReader(line)) @@ -121,7 +121,7 @@ func TestStringFIPaymentMethodToBeneficiaryOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.FIPaymentMethodToBeneficiary - require.Equal(t, record.String(), "{6420}CHECK ") + require.Equal(t, record.String(), "{6420}CHECK *") require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{6420}CHECK*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/fiReceiverFI.go b/fiReceiverFI.go index c42c0b12..d9207088 100644 --- a/fiReceiverFI.go +++ b/fiReceiverFI.go @@ -119,12 +119,12 @@ func (firfi *FIReceiverFI) Format(options FormatOptions) string { buf.Grow(201) buf.WriteString(firfi.tag) - buf.WriteString(firfi.FormatLineOne(options)) - buf.WriteString(firfi.FormatLineTwo(options)) - buf.WriteString(firfi.FormatLineThree(options)) - buf.WriteString(firfi.FormatLineFour(options)) - buf.WriteString(firfi.FormatLineFive(options)) - buf.WriteString(firfi.FormatLineSix(options)) + buf.WriteString(firfi.FormatLineOne(options) + Delimiter) + buf.WriteString(firfi.FormatLineTwo(options) + Delimiter) + buf.WriteString(firfi.FormatLineThree(options) + Delimiter) + buf.WriteString(firfi.FormatLineFour(options) + Delimiter) + buf.WriteString(firfi.FormatLineFive(options) + Delimiter) + buf.WriteString(firfi.FormatLineSix(options) + Delimiter) if options.VariableLengthFields { return firfi.stripDelimiters(buf.String()) diff --git a/fiReceiverFI_test.go b/fiReceiverFI_test.go index 06793075..020d2737 100644 --- a/fiReceiverFI_test.go +++ b/fiReceiverFI_test.go @@ -94,12 +94,12 @@ func TestParseFIReceiverFIWrongLength(t *testing.T) { r.line = line err := r.parseFIReceiverFI() - require.EqualError(t, err, r.parseError(fieldError("LineSix", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("LineOne", ErrRequireDelimiter)).Error()) } // TestParseFIReceiverFIReaderParseError parses a wrong FIReceiverFI reader parse error func TestParseFIReceiverFIReaderParseError(t *testing.T) { - var line = "{6100}Line Si® " + var line = "{6100}Line Si® *" r := NewReader(strings.NewReader(line)) r.line = line @@ -138,7 +138,7 @@ func TestStringFIReceiverFIVariableLength(t *testing.T) { r.line = line err = r.parseFIReceiverFI() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{6100}********" r = NewReader(strings.NewReader(line)) @@ -165,7 +165,7 @@ func TestStringFIReceiverFIOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.FIReceiverFI - require.Equal(t, record.String(), "{6100} ") + require.Equal(t, record.String(), "{6100} * * * * * *") require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{6100}*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) diff --git a/fieldErrors.go b/fieldErrors.go index b7801a0d..c16b34cb 100644 --- a/fieldErrors.go +++ b/fieldErrors.go @@ -125,6 +125,9 @@ var ( // ErrValidLength is returned for an field with invalid length ErrValidLength = errors.New("is an invalid length") + + // ErrRequireDelimiter is returned for an field without a delimiter + ErrRequireDelimiter = errors.New("is require delimiter") ) // FieldError is returned for errors at a field level in a tag diff --git a/grossAmountRemittanceDocument.go b/grossAmountRemittanceDocument.go index 61df294f..4520f354 100644 --- a/grossAmountRemittanceDocument.go +++ b/grossAmountRemittanceDocument.go @@ -43,7 +43,7 @@ func (gard *GrossAmountRemittanceDocument) Parse(record string) error { gard.tag = record[:6] length := 6 - value, read, err := gard.parseVariableStringField(record[length:], 3) + value, read, err := gard.parseFixedStringField(record[length:], 3) if err != nil { return fieldError("CurrencyCode", err) } @@ -91,8 +91,8 @@ func (gard *GrossAmountRemittanceDocument) Format(options FormatOptions) string buf.Grow(28) buf.WriteString(gard.tag) - buf.WriteString(gard.FormatCurrencyCode(options)) - buf.WriteString(gard.FormatAmount(options)) + buf.WriteString(gard.CurrencyCodeField()) + buf.WriteString(gard.FormatAmount(options) + Delimiter) if options.VariableLengthFields { return gard.stripDelimiters(buf.String()) diff --git a/grossAmountRemittanceDocument_test.go b/grossAmountRemittanceDocument_test.go index 31c728bd..b21db85a 100644 --- a/grossAmountRemittanceDocument_test.go +++ b/grossAmountRemittanceDocument_test.go @@ -63,12 +63,12 @@ func TestParseGrossAmountRemittanceWrongLength(t *testing.T) { err := r.parseGrossAmountRemittanceDocument() - require.EqualError(t, err, r.parseError(fieldError("Amount", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("Amount", ErrRequireDelimiter)).Error()) } // TestParseGrossAmountRemittanceReaderParseError parses a wrong GrossAmountRemittance reader parse error func TestParseGrossAmountRemittanceReaderParseError(t *testing.T) { - var line = "{8500}USD1234.56Z " + var line = "{8500}USD1234.56Z *" r := NewReader(strings.NewReader(line)) r.line = line @@ -105,7 +105,7 @@ func TestStringGrossAmountRemittanceDocumentVariableLength(t *testing.T) { r.line = line err = r.parseGrossAmountRemittanceDocument() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{8500}USD1234.56***" r = NewReader(strings.NewReader(line)) @@ -132,7 +132,7 @@ func TestStringGrossAmountRemittanceDocumentOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.GrossAmountRemittanceDocument - require.Equal(t, record.String(), "{8500}USD1234.56 ") + require.Equal(t, record.String(), "{8500}USD1234.56 *") require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{8500}USD1234.56*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/institutionAccount.go b/institutionAccount.go index f0da021c..12ccaf86 100644 --- a/institutionAccount.go +++ b/institutionAccount.go @@ -119,12 +119,12 @@ func (iAccount *InstitutionAccount) Format(options FormatOptions) string { buf.Grow(186) buf.WriteString(iAccount.tag) - buf.WriteString(iAccount.FormatSwiftFieldTag(options)) - buf.WriteString(iAccount.FormatSwiftLineOne(options)) - buf.WriteString(iAccount.FormatSwiftLineTwo(options)) - buf.WriteString(iAccount.FormatSwiftLineThree(options)) - buf.WriteString(iAccount.FormatSwiftLineFour(options)) - buf.WriteString(iAccount.FormatSwiftLineFive(options)) + buf.WriteString(iAccount.FormatSwiftFieldTag(options) + Delimiter) + buf.WriteString(iAccount.FormatSwiftLineOne(options) + Delimiter) + buf.WriteString(iAccount.FormatSwiftLineTwo(options) + Delimiter) + buf.WriteString(iAccount.FormatSwiftLineThree(options) + Delimiter) + buf.WriteString(iAccount.FormatSwiftLineFour(options) + Delimiter) + buf.WriteString(iAccount.FormatSwiftLineFive(options) + Delimiter) if options.VariableLengthFields { return iAccount.stripDelimiters(buf.String()) diff --git a/institutionAccount_test.go b/institutionAccount_test.go index e0e750fe..46e7492f 100644 --- a/institutionAccount_test.go +++ b/institutionAccount_test.go @@ -105,12 +105,12 @@ func TestParseInstitutionAccountWrongLength(t *testing.T) { err := r.parseInstitutionAccount() - require.EqualError(t, err, r.parseError(fieldError("SwiftLineFive", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("SwiftFieldTag", ErrRequireDelimiter)).Error()) } // TestParseInstitutionAccountReaderParseError parses a wrong InstitutionAccount reader parse error func TestParseInstitutionAccountReaderParseError(t *testing.T) { - var line = "{7057}SwiftSwift ®ine One Swift Line Two Swift Line Three Swift Line Four Swift Line Five " + var line = "{7057}Swift*Swift ®ine One *Swift Line Two *Swift Line Three *Swift Line Four *Swift Line Five *" r := NewReader(strings.NewReader(line)) r.line = line @@ -145,7 +145,7 @@ func TestStringInstitutionAccountVariableLength(t *testing.T) { r.line = line err = r.parseInstitutionAccount() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{7057}********" r = NewReader(strings.NewReader(line)) @@ -172,7 +172,7 @@ func TestStringInstitutionAccountOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.InstitutionAccount - require.Equal(t, record.String(), "{7057}Swift ") + require.Equal(t, record.String(), "{7057}Swift* * * * * *") require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{7057}Swift*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/instructedAmount.go b/instructedAmount.go index 92807e1c..88353148 100644 --- a/instructedAmount.go +++ b/instructedAmount.go @@ -46,7 +46,7 @@ func (ia *InstructedAmount) Parse(record string) error { ia.tag = record[:6] length := 6 - value, read, err := ia.parseVariableStringField(record[length:], 3) + value, read, err := ia.parseFixedStringField(record[length:], 3) if err != nil { return fieldError("SwiftFieldTag", err) } @@ -94,8 +94,8 @@ func (ia *InstructedAmount) Format(options FormatOptions) string { buf.Grow(24) buf.WriteString(ia.tag) - buf.WriteString(ia.FormatCurrencyCode(options)) - buf.WriteString(ia.FormatAmount(options)) + buf.WriteString(ia.CurrencyCodeField()) + buf.WriteString(ia.FormatAmount(options) + Delimiter) return buf.String() } diff --git a/instructedAmount_test.go b/instructedAmount_test.go index f411c086..a2a04c80 100644 --- a/instructedAmount_test.go +++ b/instructedAmount_test.go @@ -71,12 +71,12 @@ func TestParseInstructedAmountWrongLength(t *testing.T) { err := r.parseInstructedAmount() - require.EqualError(t, err, r.parseError(fieldError("Amount", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("Amount", ErrRequireDelimiter)).Error()) } // TestParseInstructedAmountReaderParseError parses a wrong InstructedAmount reader parse error func TestParseInstructedAmountReaderParseError(t *testing.T) { - var line = "{3710}USD000000004567Z89" + var line = "{3710}USD000000004567Z89*" r := NewReader(strings.NewReader(line)) r.line = line @@ -111,7 +111,7 @@ func TestStringInstructedAmountVariableLength(t *testing.T) { r.line = line err = r.parseInstructedAmount() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{3710}USD4567,89***" r = NewReader(strings.NewReader(line)) @@ -138,7 +138,7 @@ func TestStringInstructedAmountOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.InstructedAmount - require.Equal(t, record.String(), "{3710}USD4567,89 ") + require.Equal(t, record.String(), "{3710}USD4567,89 *") require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{3710}USD4567,89*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/instructingFI.go b/instructingFI.go index d7d3c1f9..f16a209c 100644 --- a/instructingFI.go +++ b/instructingFI.go @@ -51,9 +51,6 @@ func (ifi *InstructingFI) Parse(record string) error { ifi.FinancialInstitution.Identifier = value length += read - if len(ifi.FinancialInstitution.Identifier) >= 34 && record[length-1:length] != "*" { - length += (strings.Index(record[length:], "*") + 1) - } value, read, err = ifi.parseVariableStringField(record[length:], 35) if err != nil { return fieldError("Name", err) @@ -61,9 +58,6 @@ func (ifi *InstructingFI) Parse(record string) error { ifi.FinancialInstitution.Name = value length += read - if len(ifi.FinancialInstitution.Name) >= 35 && record[length-1:length] != "*" { - length += (strings.Index(record[length:], "*") + 1) - } value, read, err = ifi.parseVariableStringField(record[length:], 35) if err != nil { return fieldError("AddressLineOne", err) @@ -71,9 +65,6 @@ func (ifi *InstructingFI) Parse(record string) error { ifi.FinancialInstitution.Address.AddressLineOne = value length += read - if len(ifi.FinancialInstitution.Address.AddressLineOne) >= 35 && record[length-1:length] != "*" { - length += (strings.Index(record[length:], "*") + 1) - } value, read, err = ifi.parseVariableStringField(record[length:], 35) if err != nil { return fieldError("AddressLineTwo", err) @@ -81,9 +72,6 @@ func (ifi *InstructingFI) Parse(record string) error { ifi.FinancialInstitution.Address.AddressLineTwo = value length += read - if len(ifi.FinancialInstitution.Address.AddressLineTwo) >= 35 && record[length-1:length] != "*" { - length += (strings.Index(record[length:], "*") + 1) - } value, read, err = ifi.parseVariableStringField(record[length:], 35) if err != nil { return fieldError("AddressLineThree", err) @@ -126,11 +114,11 @@ func (ifi *InstructingFI) Format(options FormatOptions) string { buf.WriteString(ifi.tag) buf.WriteString(ifi.IdentificationCodeField()) - buf.WriteString(ifi.FormatIdentifier(options)) - buf.WriteString(ifi.FormatName(options)) - buf.WriteString(ifi.FormatAddressLineOne(options)) - buf.WriteString(ifi.FormatAddressLineTwo(options)) - buf.WriteString(ifi.FormatAddressLineThree(options)) + buf.WriteString(ifi.FormatIdentifier(options) + Delimiter) + buf.WriteString(ifi.FormatName(options) + Delimiter) + buf.WriteString(ifi.FormatAddressLineOne(options) + Delimiter) + buf.WriteString(ifi.FormatAddressLineTwo(options) + Delimiter) + buf.WriteString(ifi.FormatAddressLineThree(options) + Delimiter) if options.VariableLengthFields { return ifi.stripDelimiters(buf.String()) diff --git a/instructingFI_test.go b/instructingFI_test.go index ab36706d..3da96483 100644 --- a/instructingFI_test.go +++ b/instructingFI_test.go @@ -125,12 +125,12 @@ func TestParseInstructingFIWrongLength(t *testing.T) { err := r.parseInstructingFI() - require.EqualError(t, err, r.parseError(fieldError("AddressLineThree", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("Identifier", ErrRequireDelimiter)).Error()) } // TestParseInstructingFIReaderParseError parses a wrong InstructingFI reader parse error func TestParseInstructingFIReaderParseError(t *testing.T) { - var line = "{5200}D123456789 ®I Name Address One Address Two Address Three " + var line = "{5200}D123456789 *®I Name *Address One *Address Two *Address Three *" r := NewReader(strings.NewReader(line)) r.line = line @@ -165,7 +165,7 @@ func TestStringInstructingFIVariableLength(t *testing.T) { r.line = line err = r.parseInstructingFI() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{5200}D12***********" r = NewReader(strings.NewReader(line)) @@ -192,7 +192,7 @@ func TestStringInstructingFIOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.InstructingFI - require.Equal(t, record.String(), "{5200}D12 ") + require.Equal(t, record.String(), "{5200}D12 * * * * *") require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{5200}D12*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/intermediaryInstitution.go b/intermediaryInstitution.go index 83821054..b9a23071 100644 --- a/intermediaryInstitution.go +++ b/intermediaryInstitution.go @@ -119,12 +119,12 @@ func (ii *IntermediaryInstitution) Format(options FormatOptions) string { buf.Grow(186) buf.WriteString(ii.tag) - buf.WriteString(ii.FormatSwiftFieldTag(options)) - buf.WriteString(ii.FormatSwiftLineOne(options)) - buf.WriteString(ii.FormatSwiftLineTwo(options)) - buf.WriteString(ii.FormatSwiftLineThree(options)) - buf.WriteString(ii.FormatSwiftLineFour(options)) - buf.WriteString(ii.FormatSwiftLineFive(options)) + buf.WriteString(ii.FormatSwiftFieldTag(options) + Delimiter) + buf.WriteString(ii.FormatSwiftLineOne(options) + Delimiter) + buf.WriteString(ii.FormatSwiftLineTwo(options) + Delimiter) + buf.WriteString(ii.FormatSwiftLineThree(options) + Delimiter) + buf.WriteString(ii.FormatSwiftLineFour(options) + Delimiter) + buf.WriteString(ii.FormatSwiftLineFive(options) + Delimiter) if options.VariableLengthFields { return ii.stripDelimiters(buf.String()) diff --git a/intermediaryInstitution_test.go b/intermediaryInstitution_test.go index f80274e3..2f748acb 100644 --- a/intermediaryInstitution_test.go +++ b/intermediaryInstitution_test.go @@ -105,12 +105,12 @@ func TestParseIntermediaryInstitutionWrongLength(t *testing.T) { err := r.parseIntermediaryInstitution() - require.EqualError(t, err, r.parseError(fieldError("SwiftLineFive", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("SwiftFieldTag", ErrRequireDelimiter)).Error()) } // TestParseIntermediaryInstitutionReaderParseError parses a wrong IntermediaryInstitution reader parse error func TestParseIntermediaryInstitutionReaderParseError(t *testing.T) { - var line = "{7056}SwiftSwift ®ine One Swift Line Two Swift Line Three Swift Line Four Swift Line Five " + var line = "{7056}Swift*Swift ®ine One *Swift Line Two *Swift Line Three *Swift Line Four *Swift Line Five *" r := NewReader(strings.NewReader(line)) r.line = line @@ -145,7 +145,7 @@ func TestStringIntermediaryInstitutionVariableLength(t *testing.T) { r.line = line err = r.parseIntermediaryInstitution() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{7056}***********" r = NewReader(strings.NewReader(line)) @@ -172,7 +172,7 @@ func TestStringIntermediaryInstitutionOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.IntermediaryInstitution - require.Equal(t, record.String(), "{7056} ") + require.Equal(t, record.String(), "{7056} * * * * * *") require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{7056}*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/localInstrument.go b/localInstrument.go index c86f371e..ab8fef9b 100644 --- a/localInstrument.go +++ b/localInstrument.go @@ -45,9 +45,9 @@ func (li *LocalInstrument) Parse(record string) error { li.tag = record[:6] length := 6 - value, read, err := li.parseVariableStringField(record[length:], 4) + value, read, err := li.parseFixedStringField(record[length:], 4) if err != nil { - return fieldError("SwiftFieldTag", err) + return fieldError("LocalInstrumentCode", err) } li.LocalInstrumentCode = value length += read @@ -93,8 +93,8 @@ func (li *LocalInstrument) Format(options FormatOptions) string { buf.Grow(45) buf.WriteString(li.tag) - buf.WriteString(li.FormatLocalInstrumentCode(options)) - buf.WriteString(li.FormatProprietaryCode(options)) + buf.WriteString(li.LocalInstrumentCodeField()) + buf.WriteString(li.FormatProprietaryCode(options) + Delimiter) if options.VariableLengthFields { return li.stripDelimiters(buf.String()) diff --git a/localInstrument_test.go b/localInstrument_test.go index 705090f0..310303f7 100644 --- a/localInstrument_test.go +++ b/localInstrument_test.go @@ -1,7 +1,6 @@ package wire import ( - "errors" "strings" "testing" @@ -62,12 +61,12 @@ func TestParseLocalInstrumentWrongLength(t *testing.T) { err := r.parseLocalInstrument() - require.EqualError(t, err, r.parseError(fieldError("ProprietaryCode", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("ProprietaryCode", ErrRequireDelimiter)).Error()) } // TestParseLocalInstrumentReaderParseError parses a wrong LocalInstrumente reader parse error func TestParseLocalInstrumentReaderParseError(t *testing.T) { - var line = "{3610}ABCD " + var line = "{3610}ABCD *" r := NewReader(strings.NewReader(line)) r.line = line @@ -102,14 +101,14 @@ func TestStringLocalInstrumentVariableLength(t *testing.T) { r.line = line err = r.parseLocalInstrument() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{3610}***********" r = NewReader(strings.NewReader(line)) r.line = line err = r.parseLocalInstrument() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrValidLength.Error()) line = "{3610}ANSI*" r = NewReader(strings.NewReader(line)) @@ -129,7 +128,7 @@ func TestStringLocalInstrumentOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.LocalInstrument - require.Equal(t, record.String(), "{3610}ANSI ") + require.Equal(t, record.String(), "{3610}ANSI *") require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{3610}ANSI*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/messageDisposition.go b/messageDisposition.go index 6975c7ba..c7768eba 100644 --- a/messageDisposition.go +++ b/messageDisposition.go @@ -52,28 +52,28 @@ func (md *MessageDisposition) Parse(record string) error { md.tag = record[:6] length := 6 - value, read, err := md.parseVariableStringField(record[length:], 2) + value, read, err := md.parseFixedStringField(record[length:], 2) if err != nil { return fieldError("FormatVersion", err) } md.FormatVersion = value length += read - value, read, err = md.parseVariableStringField(record[length:], 1) + value, read, err = md.parseFixedStringField(record[length:], 1) if err != nil { return fieldError("TestProductionCode", err) } md.TestProductionCode = value length += read - value, read, err = md.parseVariableStringField(record[length:], 1) + value, read, err = md.parseFixedStringField(record[length:], 1) if err != nil { return fieldError("MessageDuplicationCode", err) } md.MessageDuplicationCode = value length += read - value, read, err = md.parseVariableStringField(record[length:], 1) + value, read, err = md.parseFixedStringField(record[length:], 1) if err != nil { return fieldError("MessageStatusIndicator", err) } @@ -114,10 +114,10 @@ func (md *MessageDisposition) Format(options FormatOptions) string { buf.Grow(11) buf.WriteString(md.tag) - buf.WriteString(md.FormatMessageDispositionFormatVersion(options)) - buf.WriteString(md.FormatMessageDispositionTestProductionCode(options)) - buf.WriteString(md.FormatMessageDispositionMessageDuplicationCode(options)) - buf.WriteString(md.FormatMessageDispositionMessageStatusIndicator(options)) + buf.WriteString(md.MessageDispositionFormatVersionField()) + buf.WriteString(md.MessageDispositionTestProductionCodeField()) + buf.WriteString(md.MessageDispositionMessageDuplicationCodeField()) + buf.WriteString(md.MessageDispositionMessageStatusIndicatorField()) if options.VariableLengthFields { return md.stripDelimiters(buf.String()) diff --git a/messageDisposition_test.go b/messageDisposition_test.go index f5131972..8c2eea99 100644 --- a/messageDisposition_test.go +++ b/messageDisposition_test.go @@ -81,9 +81,9 @@ func TestStringMessageDispositionVariableLength(t *testing.T) { r.line = line err = r.parseMessageDisposition() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrValidLength.Error()) - line = "{1100}*" + line = "{1100} *" r = NewReader(strings.NewReader(line)) r.line = line @@ -102,6 +102,6 @@ func TestStringMessageDispositionOptions(t *testing.T) { record := r.currentFEDWireMessage.MessageDisposition require.Equal(t, record.String(), "{1100} ") - require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{1100}*") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{1100} ") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/orderingCustomer.go b/orderingCustomer.go index 39f47609..eeb0664f 100644 --- a/orderingCustomer.go +++ b/orderingCustomer.go @@ -119,12 +119,12 @@ func (oc *OrderingCustomer) Format(options FormatOptions) string { buf.Grow(186) buf.WriteString(oc.tag) - buf.WriteString(oc.FormatSwiftFieldTag(options)) - buf.WriteString(oc.FormatSwiftLineOne(options)) - buf.WriteString(oc.FormatSwiftLineTwo(options)) - buf.WriteString(oc.FormatSwiftLineThree(options)) - buf.WriteString(oc.FormatSwiftLineFour(options)) - buf.WriteString(oc.FormatSwiftLineFive(options)) + buf.WriteString(oc.FormatSwiftFieldTag(options) + Delimiter) + buf.WriteString(oc.FormatSwiftLineOne(options) + Delimiter) + buf.WriteString(oc.FormatSwiftLineTwo(options) + Delimiter) + buf.WriteString(oc.FormatSwiftLineThree(options) + Delimiter) + buf.WriteString(oc.FormatSwiftLineFour(options) + Delimiter) + buf.WriteString(oc.FormatSwiftLineFive(options) + Delimiter) if options.VariableLengthFields { return oc.stripDelimiters(buf.String()) diff --git a/orderingCustomer_test.go b/orderingCustomer_test.go index 20162843..25b45f84 100644 --- a/orderingCustomer_test.go +++ b/orderingCustomer_test.go @@ -105,12 +105,12 @@ func TestParseOrderingCustomerWrongLength(t *testing.T) { err := r.parseOrderingCustomer() - require.EqualError(t, err, r.parseError(fieldError("SwiftLineFive", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("SwiftFieldTag", ErrRequireDelimiter)).Error()) } // TestParseOrderingCustomerReaderParseError parses a wrong OrderingCustomer reader parse error func TestParseOrderingCustomerReaderParseError(t *testing.T) { - var line = "{7050}SwiftSwift ®ine One Swift Line Two Swift Line Three Swift Line Four Swift Line Five " + var line = "{7050}Swift*Swift ®ine One *Swift Line Two *Swift Line Three *Swift Line Four *Swift Line Five *" r := NewReader(strings.NewReader(line)) r.line = line @@ -145,7 +145,7 @@ func TestStringOrderingCustomerVariableLength(t *testing.T) { r.line = line err = r.parseOrderingCustomer() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{7050}********" r = NewReader(strings.NewReader(line)) @@ -172,7 +172,7 @@ func TestStringOrderingCustomerOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.OrderingCustomer - require.Equal(t, record.String(), "{7050} ") + require.Equal(t, record.String(), "{7050} * * * * * *") require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{7050}*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/orderingInstitution.go b/orderingInstitution.go index c443512a..219ff622 100644 --- a/orderingInstitution.go +++ b/orderingInstitution.go @@ -119,12 +119,12 @@ func (oi *OrderingInstitution) Format(options FormatOptions) string { buf.Grow(186) buf.WriteString(oi.tag) - buf.WriteString(oi.FormatSwiftFieldTag(options)) - buf.WriteString(oi.FormatSwiftLineOne(options)) - buf.WriteString(oi.FormatSwiftLineTwo(options)) - buf.WriteString(oi.FormatSwiftLineThree(options)) - buf.WriteString(oi.FormatSwiftLineFour(options)) - buf.WriteString(oi.FormatSwiftLineFive(options)) + buf.WriteString(oi.FormatSwiftFieldTag(options) + Delimiter) + buf.WriteString(oi.FormatSwiftLineOne(options) + Delimiter) + buf.WriteString(oi.FormatSwiftLineTwo(options) + Delimiter) + buf.WriteString(oi.FormatSwiftLineThree(options) + Delimiter) + buf.WriteString(oi.FormatSwiftLineFour(options) + Delimiter) + buf.WriteString(oi.FormatSwiftLineFive(options) + Delimiter) if options.VariableLengthFields { return oi.stripDelimiters(buf.String()) diff --git a/orderingInstitution_test.go b/orderingInstitution_test.go index 08be0050..e27f58dd 100644 --- a/orderingInstitution_test.go +++ b/orderingInstitution_test.go @@ -104,12 +104,12 @@ func TestParseOrderingInstitutionWrongLength(t *testing.T) { r.line = line err := r.parseOrderingInstitution() - require.EqualError(t, err, r.parseError(fieldError("SwiftLineFive", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("SwiftFieldTag", ErrRequireDelimiter)).Error()) } // TestParseOrderingInstitutionReaderParseError parses a wrong OrderingInstitution reader parse error func TestParseOrderingInstitutionReaderParseError(t *testing.T) { - var line = "{7052}SwiftSwift ®ine One Swift Line Two Swift Line Three Swift Line Four Swift Line Five " + var line = "{7052}Swift*Swift ®ine One *Swift Line Two *Swift Line Three *Swift Line Four *Swift Line Five *" r := NewReader(strings.NewReader(line)) r.line = line @@ -144,7 +144,7 @@ func TestStringOrderingInstitutionVariableLength(t *testing.T) { r.line = line err = r.parseOrderingInstitution() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{7052}********" r = NewReader(strings.NewReader(line)) @@ -171,7 +171,7 @@ func TestStringOrderingInstitutionOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.OrderingInstitution - require.Equal(t, record.String(), "{7052} ") + require.Equal(t, record.String(), "{7052} * * * * * *") require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{7052}*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/originator.go b/originator.go index 09e2c98e..f786f206 100644 --- a/originator.go +++ b/originator.go @@ -121,11 +121,11 @@ func (o *Originator) Format(options FormatOptions) string { buf.WriteString(o.tag) buf.WriteString(o.IdentificationCodeField()) - buf.WriteString(o.FormatIdentifier(options)) - buf.WriteString(o.FormatName(options)) - buf.WriteString(o.FormatAddressLineOne(options)) - buf.WriteString(o.FormatAddressLineTwo(options)) - buf.WriteString(o.FormatAddressLineThree(options)) + buf.WriteString(o.FormatIdentifier(options) + Delimiter) + buf.WriteString(o.FormatName(options) + Delimiter) + buf.WriteString(o.FormatAddressLineOne(options) + Delimiter) + buf.WriteString(o.FormatAddressLineTwo(options) + Delimiter) + buf.WriteString(o.FormatAddressLineThree(options) + Delimiter) if options.VariableLengthFields { return o.stripDelimiters(buf.String()) diff --git a/originatorFI.go b/originatorFI.go index 4cdba66e..084123d0 100644 --- a/originatorFI.go +++ b/originatorFI.go @@ -43,7 +43,7 @@ func (ofi *OriginatorFI) Parse(record string) error { ofi.tag = record[:6] length := 6 - value, read, err := ofi.parseVariableStringField(record[length:], 1) + value, read, err := ofi.parseFixedStringField(record[length:], 1) if err != nil { return fieldError("IdentificationCode", err) } @@ -119,12 +119,12 @@ func (ofi *OriginatorFI) Format(options FormatOptions) string { buf.Grow(181) buf.WriteString(ofi.tag) - buf.WriteString(ofi.FormatIdentificationCode(options)) - buf.WriteString(ofi.FormatIdentifier(options)) - buf.WriteString(ofi.FormatName(options)) - buf.WriteString(ofi.FormatAddressLineOne(options)) - buf.WriteString(ofi.FormatAddressLineTwo(options)) - buf.WriteString(ofi.FormatAddressLineThree(options)) + buf.WriteString(ofi.IdentificationCodeField()) + buf.WriteString(ofi.FormatIdentifier(options) + Delimiter) + buf.WriteString(ofi.FormatName(options) + Delimiter) + buf.WriteString(ofi.FormatAddressLineOne(options) + Delimiter) + buf.WriteString(ofi.FormatAddressLineTwo(options) + Delimiter) + buf.WriteString(ofi.FormatAddressLineThree(options) + Delimiter) if options.VariableLengthFields { return ofi.stripDelimiters(buf.String()) diff --git a/originatorFI_test.go b/originatorFI_test.go index 9c7d4cbb..6c669e4a 100644 --- a/originatorFI_test.go +++ b/originatorFI_test.go @@ -125,12 +125,12 @@ func TestParseOriginatorFIWrongLength(t *testing.T) { err := r.parseOriginatorFI() - require.EqualError(t, err, r.parseError(fieldError("AddressLineThree", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("Identifier", ErrRequireDelimiter)).Error()) } // TestParseOriginatorFIReaderParseError parses a wrong OriginatorFI reader parse error func TestParseOriginatorFIReaderParseError(t *testing.T) { - var line = "{5100}D123456789 ®I Name Address One Address Two Address Three " + var line = "{5100}D123456789 *®I Name *Address One *Address Two *Address Three *" r := NewReader(strings.NewReader(line)) r.line = line @@ -165,7 +165,7 @@ func TestStringOriginatorFIVariableLength(t *testing.T) { r.line = line err = r.parseOriginatorFI() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{5100}B1*******" r = NewReader(strings.NewReader(line)) @@ -192,7 +192,7 @@ func TestStringOriginatorFIOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.OriginatorFI - require.Equal(t, record.String(), "{5100}B1 ") + require.Equal(t, record.String(), "{5100}B1 * * * * *") require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{5100}B1*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/originatorOptionF.go b/originatorOptionF.go index ba6e8fc3..534904bd 100644 --- a/originatorOptionF.go +++ b/originatorOptionF.go @@ -176,11 +176,11 @@ func (oof *OriginatorOptionF) Format(options FormatOptions) string { buf.Grow(181) buf.WriteString(oof.tag) - buf.WriteString(oof.FormatPartyIdentifier(options)) - buf.WriteString(oof.FormatName(options)) - buf.WriteString(oof.FormatLineOne(options)) - buf.WriteString(oof.FormatLineTwo(options)) - buf.WriteString(oof.FormatLineThree(options)) + buf.WriteString(oof.FormatPartyIdentifier(options) + Delimiter) + buf.WriteString(oof.FormatName(options) + Delimiter) + buf.WriteString(oof.FormatLineOne(options) + Delimiter) + buf.WriteString(oof.FormatLineTwo(options) + Delimiter) + buf.WriteString(oof.FormatLineThree(options) + Delimiter) if options.VariableLengthFields { return oof.stripDelimiters(buf.String()) diff --git a/originatorOptionF_test.go b/originatorOptionF_test.go index 0d2935aa..010947d8 100644 --- a/originatorOptionF_test.go +++ b/originatorOptionF_test.go @@ -157,12 +157,12 @@ func TestParseOriginatorOptionFWrongLength(t *testing.T) { err := r.parseOriginatorOptionF() - require.EqualError(t, err, r.parseError(fieldError("LineThree", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("PartyIdentifier", ErrRequireDelimiter)).Error()) } // TestParseOriginatorOptionFReaderParseError parses a wrong OriginatorOptionF reader parse error func TestParseOriginatorOptionFReaderParseError(t *testing.T) { - var line = "{5010}TXID/123-45-6789 ®ame LineOne LineTwo LineThree " + var line = "{5010}TXID/123-45-6789 *®ame *LineOne *LineTwo *LineThree *" r := NewReader(strings.NewReader(line)) r.line = line @@ -189,7 +189,7 @@ func TestStringOriginatorOptionFVariableLength(t *testing.T) { r.line = line err = r.parseOriginatorOptionF() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{5010}TXID/123-45-6789*1/Name********" r = NewReader(strings.NewReader(line)) @@ -216,7 +216,7 @@ func TestStringOriginatorOptionFOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.OriginatorOptionF - require.Equal(t, record.String(), "{5010}TXID/123-45-6789 1/Name ") + require.Equal(t, record.String(), "{5010}TXID/123-45-6789 *1/Name * * * *") require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{5010}TXID/123-45-6789*1/Name*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/originatorToBeneficiary.go b/originatorToBeneficiary.go index d0360643..4d191ed8 100644 --- a/originatorToBeneficiary.go +++ b/originatorToBeneficiary.go @@ -56,9 +56,6 @@ func (ob *OriginatorToBeneficiary) Parse(record string) error { ob.LineOne = value length += read - if len(ob.LineOne) >= 35 && record[length-1:length] != "*" { - length += (strings.Index(record[length:], "*") + 1) - } value, read, err = ob.parseVariableStringField(record[length:], 35) if err != nil { return fieldError("LineTwo", err) @@ -66,9 +63,6 @@ func (ob *OriginatorToBeneficiary) Parse(record string) error { ob.LineTwo = value length += read - if len(ob.LineTwo) >= 35 && record[length-1:length] != "*" { - length += (strings.Index(record[length:], "*") + 1) - } value, read, err = ob.parseVariableStringField(record[length:], 35) if err != nil { return fieldError("LineThree", err) @@ -76,9 +70,6 @@ func (ob *OriginatorToBeneficiary) Parse(record string) error { ob.LineThree = value length += read - if len(ob.LineThree) >= 35 && record[length-1:length] != "*" { - length += (strings.Index(record[length:], "*") + 1) - } value, read, err = ob.parseVariableStringField(record[length:], 35) if err != nil { return fieldError("LineFour", err) @@ -120,10 +111,10 @@ func (ob *OriginatorToBeneficiary) Format(options FormatOptions) string { buf.Grow(146) buf.WriteString(ob.tag) - buf.WriteString(ob.FormatLineOne(options)) - buf.WriteString(ob.FormatLineTwo(options)) - buf.WriteString(ob.FormatLineThree(options)) - buf.WriteString(ob.FormatLineFour(options)) + buf.WriteString(ob.FormatLineOne(options) + Delimiter) + buf.WriteString(ob.FormatLineTwo(options) + Delimiter) + buf.WriteString(ob.FormatLineThree(options) + Delimiter) + buf.WriteString(ob.FormatLineFour(options) + Delimiter) if options.VariableLengthFields { return ob.stripDelimiters(buf.String()) diff --git a/originatorToBeneficiary_test.go b/originatorToBeneficiary_test.go index 3a7a30f2..d9e18c25 100644 --- a/originatorToBeneficiary_test.go +++ b/originatorToBeneficiary_test.go @@ -73,12 +73,12 @@ func TestParseOriginatorToBeneficiaryWrongLength(t *testing.T) { err := r.parseOriginatorToBeneficiary() - require.EqualError(t, err, r.parseError(fieldError("LineFour", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("LineOne", ErrRequireDelimiter)).Error()) } // TestParseOriginatorToBeneficiaryReaderParseError parses a wrong OriginatorToBeneficiary reader parse error func TestParseOriginatorToBeneficiaryReaderParseError(t *testing.T) { - var line = "{6000}LineOne ®ineTwo LineThree LineFour " + var line = "{6000}LineOne *®ineTwo *LineThree *LineFour *" r := NewReader(strings.NewReader(line)) r.line = line @@ -113,7 +113,7 @@ func TestStringOriginatorToBeneficiaryVariableLength(t *testing.T) { r.line = line err = r.parseOriginatorToBeneficiary() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{6000}********" r = NewReader(strings.NewReader(line)) @@ -140,7 +140,7 @@ func TestStringOriginatorToBeneficiaryOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.OriginatorToBeneficiary - require.Equal(t, record.String(), "{6000} ") + require.Equal(t, record.String(), "{6000} * * * *") require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{6000}*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/originator_test.go b/originator_test.go index 3895a072..710c632a 100644 --- a/originator_test.go +++ b/originator_test.go @@ -118,12 +118,12 @@ func TestParseOriginatorWrongLength(t *testing.T) { err := r.parseOriginator() - require.EqualError(t, err, r.parseError(fieldError("AddressLineThree", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("Identifier", ErrRequireDelimiter)).Error()) } // TestParseOriginatorReaderParseError parses a wrong Originator reader parse error func TestParseOriginatorReaderParseError(t *testing.T) { - var line = "{5000}11234 ®ame Address One Address Two Address Three " + var line = "{5000}11234 *®ame *Address One *Address Two *Address Three *" r := NewReader(strings.NewReader(line)) r.line = line @@ -158,7 +158,7 @@ func TestStringOriginatorVariableLength(t *testing.T) { r.line = line err = r.parseOriginator() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{5000}B1*******" r = NewReader(strings.NewReader(line)) @@ -185,7 +185,7 @@ func TestStringOriginatorOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.Originator - require.Equal(t, record.String(), "{5000}B1 ") + require.Equal(t, record.String(), "{5000}B1 * * * * *") require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{5000}B1*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/outputMessageAccountabilityData.go b/outputMessageAccountabilityData.go index e928a6cd..cbf76f7a 100644 --- a/outputMessageAccountabilityData.go +++ b/outputMessageAccountabilityData.go @@ -53,14 +53,14 @@ func (omad *OutputMessageAccountabilityData) Parse(record string) error { omad.tag = record[:6] length := 6 - value, read, err := omad.parseVariableStringField(record[length:], 8) + value, read, err := omad.parseFixedStringField(record[length:], 8) if err != nil { return fieldError("OutputCycleDate", err) } omad.OutputCycleDate = value length += read - value, read, err = omad.parseVariableStringField(record[length:], 8) + value, read, err = omad.parseFixedStringField(record[length:], 8) if err != nil { return fieldError("OutputDestinationID", err) } @@ -74,21 +74,21 @@ func (omad *OutputMessageAccountabilityData) Parse(record string) error { omad.OutputSequenceNumber = record[length : length+6] length += 6 - value, read, err = omad.parseVariableStringField(record[length:], 4) + value, read, err = omad.parseFixedStringField(record[length:], 4) if err != nil { return fieldError("OutputDate", err) } omad.OutputDate = value length += read - value, read, err = omad.parseVariableStringField(record[length:], 4) + value, read, err = omad.parseFixedStringField(record[length:], 4) if err != nil { return fieldError("OutputTime", err) } omad.OutputTime = value length += read - value, read, err = omad.parseVariableStringField(record[length:], 4) + value, read, err = omad.parseFixedStringField(record[length:], 4) if err != nil { return fieldError("OutputFRBApplicationIdentification", err) } @@ -128,13 +128,16 @@ func (omad *OutputMessageAccountabilityData) Format(options FormatOptions) strin var buf strings.Builder buf.Grow(40) + // All fields are fixed fields + options.VariableLengthFields = false + buf.WriteString(omad.tag) - buf.WriteString(omad.FormatOutputCycleDate(options)) - buf.WriteString(omad.FormatOutputDestinationID(options)) + buf.WriteString(omad.OutputCycleDateField()) + buf.WriteString(omad.OutputDestinationIDField()) buf.WriteString(omad.OutputSequenceNumberField()) - buf.WriteString(omad.FormatOutputDate(options)) - buf.WriteString(omad.FormatOutputTime(options)) - buf.WriteString(omad.FormatOutputFRBApplicationIdentification(options)) + buf.WriteString(omad.OutputDateField()) + buf.WriteString(omad.OutputTimeField()) + buf.WriteString(omad.OutputFRBApplicationIdentificationField()) if options.VariableLengthFields { return omad.stripDelimiters(buf.String()) @@ -153,11 +156,21 @@ func (omad *OutputMessageAccountabilityData) Validate() error { return nil } +// OutputCycleDateField +func (omad *OutputMessageAccountabilityData) OutputCycleDateField() string { + return omad.parseAlphaField(omad.OutputCycleDate, 8) +} + // FormatOutputCycleDate returns OutputCycleDate formatted according to the FormatOptions func (omad *OutputMessageAccountabilityData) FormatOutputCycleDate(options FormatOptions) string { return omad.formatAlphaField(omad.OutputCycleDate, 8, options) } +// OutputDestinationIDField +func (omad *OutputMessageAccountabilityData) OutputDestinationIDField() string { + return omad.parseAlphaField(omad.OutputDestinationID, 8) +} + // FormatOutputDestinationID returns OutputDestinationID formatted according to the FormatOptions func (omad *OutputMessageAccountabilityData) FormatOutputDestinationID(options FormatOptions) string { return omad.formatAlphaField(omad.OutputDestinationID, 8, options) @@ -168,16 +181,31 @@ func (omad *OutputMessageAccountabilityData) OutputSequenceNumberField() string return omad.numericStringField(omad.OutputSequenceNumber, 6) } +// OutputDateField +func (omad *OutputMessageAccountabilityData) OutputDateField() string { + return omad.parseAlphaField(omad.OutputDate, 4) +} + // FormatOutputDate returns OutputDate formatted according to the FormatOptions func (omad *OutputMessageAccountabilityData) FormatOutputDate(options FormatOptions) string { return omad.formatAlphaField(omad.OutputDate, 4, options) } +// OutputTimeField +func (omad *OutputMessageAccountabilityData) OutputTimeField() string { + return omad.parseAlphaField(omad.OutputTime, 4) +} + // FormatOutputTime returns OutputTime formatted according to the FormatOptions func (omad *OutputMessageAccountabilityData) FormatOutputTime(options FormatOptions) string { return omad.formatAlphaField(omad.OutputTime, 4, options) } +// OutputFRBApplicationIdentificationField +func (omad *OutputMessageAccountabilityData) OutputFRBApplicationIdentificationField() string { + return omad.parseAlphaField(omad.OutputFRBApplicationIdentification, 4) +} + // FormatOutputFRBApplicationIdentification returns OutputFRBApplicationIdentification formatted according to the FormatOptions func (omad *OutputMessageAccountabilityData) FormatOutputFRBApplicationIdentification(options FormatOptions) string { return omad.formatAlphaField(omad.OutputFRBApplicationIdentification, 4, options) diff --git a/outputMessageAccountabilityData_test.go b/outputMessageAccountabilityData_test.go index 5d243373..cb98b808 100644 --- a/outputMessageAccountabilityData_test.go +++ b/outputMessageAccountabilityData_test.go @@ -66,7 +66,7 @@ func TestOutputMessageAccountabilityDataTagError(t *testing.T) { // TestStringOutputMessageAccountabilityDataVariableLength parses using variable length func TestStringOutputMessageAccountabilityDataVariableLength(t *testing.T) { - var line = "{1120}**000001" + var line = "{1120} 000001 " r := NewReader(strings.NewReader(line)) r.line = line @@ -85,9 +85,9 @@ func TestStringOutputMessageAccountabilityDataVariableLength(t *testing.T) { r.line = line err = r.parseOutputMessageAccountabilityData() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrValidLength.Error()) - line = "{1120}**000001*" + line = "{1120} 000001 *" r = NewReader(strings.NewReader(line)) r.line = line @@ -97,7 +97,7 @@ func TestStringOutputMessageAccountabilityDataVariableLength(t *testing.T) { // TestStringOutputMessageAccountabilityDataOptions validates Format() formatted according to the FormatOptions func TestStringOutputMessageAccountabilityDataOptions(t *testing.T) { - var line = "{1120}**000001" + var line = "{1120} 000001 *" r := NewReader(strings.NewReader(line)) r.line = line @@ -106,6 +106,6 @@ func TestStringOutputMessageAccountabilityDataOptions(t *testing.T) { record := r.currentFEDWireMessage.OutputMessageAccountabilityData require.Equal(t, record.String(), "{1120} 000001 ") - require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{1120}**000001*") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{1120} 000001 ") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/paymentNotification.go b/paymentNotification.go index b6387e2e..9dbb721e 100644 --- a/paymentNotification.go +++ b/paymentNotification.go @@ -57,7 +57,7 @@ func (pn *PaymentNotification) Parse(record string) error { pn.tag = record[:6] length := 6 - value, read, err := pn.parseVariableStringField(record[length:], 1) + value, read, err := pn.parseFixedStringField(record[length:], 1) if err != nil { return fieldError("PaymentNotificationIndicator", err) } @@ -140,13 +140,13 @@ func (pn *PaymentNotification) Format(options FormatOptions) string { buf.Grow(2335) buf.WriteString(pn.tag) - buf.WriteString(pn.FormatPaymentNotificationIndicator(options)) - buf.WriteString(pn.FormatContactNotificationElectronicAddress(options)) - buf.WriteString(pn.FormatContactName(options)) - buf.WriteString(pn.FormatContactPhoneNumber(options)) - buf.WriteString(pn.FormatContactMobileNumber(options)) - buf.WriteString(pn.FormatContactFaxNumber(options)) - buf.WriteString(pn.FormatEndToEndIdentification(options)) + buf.WriteString(pn.PaymentNotificationIndicatorField()) + buf.WriteString(pn.FormatContactNotificationElectronicAddress(options) + Delimiter) + buf.WriteString(pn.FormatContactName(options) + Delimiter) + buf.WriteString(pn.FormatContactPhoneNumber(options) + Delimiter) + buf.WriteString(pn.FormatContactMobileNumber(options) + Delimiter) + buf.WriteString(pn.FormatContactFaxNumber(options) + Delimiter) + buf.WriteString(pn.FormatEndToEndIdentification(options) + Delimiter) if options.VariableLengthFields { return pn.stripDelimiters(buf.String()) @@ -185,6 +185,11 @@ func (pn *PaymentNotification) Validate() error { return nil } +// PaymentNotificationIndicatorField gets a string of PaymentNotificationIndicator field +func (pn *PaymentNotification) PaymentNotificationIndicatorField() string { + return pn.alphaField(pn.PaymentNotificationIndicator, 1) +} + // PaymentNotificationIndicatorField gets a string of PaymentNotificationIndicator field func (pn *PaymentNotification) FormatPaymentNotificationIndicator(options FormatOptions) string { return pn.formatAlphaField(pn.PaymentNotificationIndicator, 1, options) diff --git a/paymentNotification_test.go b/paymentNotification_test.go index 71c1dcde..856d8b97 100644 --- a/paymentNotification_test.go +++ b/paymentNotification_test.go @@ -1,7 +1,6 @@ package wire import ( - "errors" "strings" "testing" @@ -106,12 +105,12 @@ func TestParsePaymentNotificationWrongLength(t *testing.T) { err := r.parsePaymentNotification() - require.EqualError(t, err, r.parseError(fieldError("EndToEndIdentification", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("ContactNotificationElectronicAddress", ErrRequireDelimiter)).Error()) } // TestParsePaymentNotificationReaderParseError parses a wrong PaymentNotification reader parse error func TestParsePaymentNotificationReaderParseError(t *testing.T) { - var line = "{3620}Zhttp://moov.io Contact Name 5555551212 5551231212 5554561212 End To End Identification" + var line = "{3620}Zhttp://moov.io Contact Name 5555551212 5551231212 5554561212 End To End Identification*" r := NewReader(strings.NewReader(line)) r.line = line @@ -146,21 +145,14 @@ func TestStringPaymentNotificationVariableLength(t *testing.T) { r.line = line err = r.parsePaymentNotification() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{3620}*********" r = NewReader(strings.NewReader(line)) r.line = line err = r.parsePaymentNotification() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) - - line = "{3620}*" - r = NewReader(strings.NewReader(line)) - r.line = line - - err = r.parsePaymentNotification() - require.Equal(t, err, nil) + require.ErrorContains(t, err, ErrValidLength.Error()) } // TestStringPaymentNotificationOptions validates Format() formatted according to the FormatOptions @@ -173,7 +165,7 @@ func TestStringPaymentNotificationOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.PaymentNotification - require.Equal(t, record.String(), "{3620} ") - require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{3620}*") + require.Equal(t, record.String(), "{3620} * * * * * *") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{3620} *") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/previousMessageIdentifier.go b/previousMessageIdentifier.go index f872303c..d107501d 100644 --- a/previousMessageIdentifier.go +++ b/previousMessageIdentifier.go @@ -43,7 +43,7 @@ func (pmi *PreviousMessageIdentifier) Parse(record string) error { pmi.tag = record[:6] length := 6 - value, read, err := pmi.parseVariableStringField(record[length:], 22) + value, read, err := pmi.parseFixedStringField(record[length:], 22) if err != nil { return fieldError("PreviousMessageIdentifier", err) } @@ -84,7 +84,7 @@ func (pmi *PreviousMessageIdentifier) Format(options FormatOptions) string { buf.Grow(28) buf.WriteString(pmi.tag) - buf.WriteString(pmi.FormatPreviousMessageIdentifier(options)) + buf.WriteString(pmi.PreviousMessageIdentifierField()) return buf.String() } diff --git a/previousMessageIdentifier_test.go b/previousMessageIdentifier_test.go index df5a16c3..66ac85b1 100644 --- a/previousMessageIdentifier_test.go +++ b/previousMessageIdentifier_test.go @@ -87,9 +87,9 @@ func TestStringPreviousMessageIdentifierVariableLength(t *testing.T) { r.line = line err = r.parsePreviousMessageIdentifier() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrValidLength.Error()) - line = "{3500}*" + line = "{3500} *" r = NewReader(strings.NewReader(line)) r.line = line @@ -108,6 +108,6 @@ func TestStringPreviousMessageIdentifierOptions(t *testing.T) { record := r.currentFEDWireMessage.PreviousMessageIdentifier require.Equal(t, record.String(), "{3500} ") - require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{3500}*") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{3500} ") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/primaryRemittanceDocument.go b/primaryRemittanceDocument.go index 4857cff8..0fcbf919 100644 --- a/primaryRemittanceDocument.go +++ b/primaryRemittanceDocument.go @@ -106,9 +106,9 @@ func (prd *PrimaryRemittanceDocument) Format(options FormatOptions) string { buf.WriteString(prd.tag) buf.WriteString(prd.DocumentTypeCodeField()) - buf.WriteString(prd.FormatProprietaryDocumentTypeCode(options)) - buf.WriteString(prd.FormatDocumentIdentificationNumber(options)) - buf.WriteString(prd.FormatIssuer(options)) + buf.WriteString(prd.FormatProprietaryDocumentTypeCode(options) + Delimiter) + buf.WriteString(prd.FormatDocumentIdentificationNumber(options) + Delimiter) + buf.WriteString(prd.FormatIssuer(options) + Delimiter) if options.VariableLengthFields { return prd.stripDelimiters(buf.String()) diff --git a/primaryRemittanceDocument_test.go b/primaryRemittanceDocument_test.go index a325312c..cb503495 100644 --- a/primaryRemittanceDocument_test.go +++ b/primaryRemittanceDocument_test.go @@ -106,12 +106,12 @@ func TestParsePrimaryRemittanceDocumentWrongLength(t *testing.T) { err := r.parsePrimaryRemittanceDocument() - require.EqualError(t, err, r.parseError(fieldError("Issuer", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("ProprietaryDocumentTypeCode", ErrRequireDelimiter)).Error()) } // TestParsePrimaryRemittanceDocumentReaderParseError parses a wrong PrimaryRemittanceDocument reader parse error func TestParsePrimaryRemittanceDocumentReaderParseError(t *testing.T) { - var line = "{8400}ZZZZ 111111 Issuer " + var line = "{8400}ZZZZ *111111 *Issuer *" r := NewReader(strings.NewReader(line)) r.line = line @@ -146,7 +146,7 @@ func TestStringPrimaryRemittanceDocumentVariableLength(t *testing.T) { r.line = line err = r.parsePrimaryRemittanceDocument() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{8400}CMCN********" r = NewReader(strings.NewReader(line)) @@ -173,7 +173,7 @@ func TestStringPrimaryRemittanceDocumentOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.PrimaryRemittanceDocument - require.Equal(t, record.String(), "{8400}AROI Issuer ") + require.Equal(t, record.String(), "{8400}AROI *Issuer * *") require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{8400}AROI*Issuer*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/reader_test.go b/reader_test.go index 441719b7..a61f5487 100644 --- a/reader_test.go +++ b/reader_test.go @@ -80,8 +80,7 @@ func TestRead_missingTag(t *testing.T) { r := NewReader(f) _, err = r.Read() - - require.EqualError(t, err, "file validation failed: FIBeneficiaryAdvice is a required field") + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) } func TestReadWithValidateOpts(t *testing.T) { diff --git a/receiptTimeStamp.go b/receiptTimeStamp.go index e417767b..4b423986 100644 --- a/receiptTimeStamp.go +++ b/receiptTimeStamp.go @@ -47,21 +47,21 @@ func (rts *ReceiptTimeStamp) Parse(record string) error { rts.tag = record[:6] length := 6 - value, read, err := rts.parseVariableStringField(record[length:], 4) + value, read, err := rts.parseFixedStringField(record[length:], 4) if err != nil { return fieldError("ReceiptDate", err) } rts.ReceiptDate = value length += read - value, read, err = rts.parseVariableStringField(record[length:], 4) + value, read, err = rts.parseFixedStringField(record[length:], 4) if err != nil { return fieldError("ReceiptTime", err) } rts.ReceiptTime = value length += read - value, read, err = rts.parseVariableStringField(record[length:], 4) + value, read, err = rts.parseFixedStringField(record[length:], 4) if err != nil { return fieldError("ReceiptApplicationIdentification", err) } @@ -102,9 +102,9 @@ func (rts *ReceiptTimeStamp) Format(options FormatOptions) string { buf.Grow(18) buf.WriteString(rts.tag) - buf.WriteString(rts.FormatReceiptDate(options)) - buf.WriteString(rts.FormatReceiptTime(options)) - buf.WriteString(rts.FormatReceiptApplicationIdentification(options)) + buf.WriteString(rts.ReceiptDateField()) + buf.WriteString(rts.ReceiptTimeField()) + buf.WriteString(rts.ReceiptApplicationIdentificationField()) if options.VariableLengthFields { return rts.stripDelimiters(buf.String()) diff --git a/receiptTimeStamp_test.go b/receiptTimeStamp_test.go index d47fd986..31ff17ba 100644 --- a/receiptTimeStamp_test.go +++ b/receiptTimeStamp_test.go @@ -79,9 +79,9 @@ func TestStringReceiptTimeStampVariableLength(t *testing.T) { r.line = line err = r.parseReceiptTimeStamp() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrValidLength.Error()) - line = "{1110}*" + line = "{1110} *" r = NewReader(strings.NewReader(line)) r.line = line @@ -100,6 +100,6 @@ func TestStringReceiptTimeStampOptions(t *testing.T) { record := r.currentFEDWireMessage.ReceiptTimeStamp require.Equal(t, record.String(), "{1110} ") - require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{1110}*") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{1110} ") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/receiverDepositoryInstitution.go b/receiverDepositoryInstitution.go index 740751e1..b81dad91 100644 --- a/receiverDepositoryInstitution.go +++ b/receiverDepositoryInstitution.go @@ -45,7 +45,7 @@ func (rdi *ReceiverDepositoryInstitution) Parse(record string) error { rdi.tag = record[:6] length := 6 - value, read, err := rdi.parseVariableStringField(record[length:], 9) + value, read, err := rdi.parseFixedStringField(record[length:], 9) if err != nil { return fieldError("ReceiverABANumber", err) } @@ -93,8 +93,8 @@ func (rdi *ReceiverDepositoryInstitution) Format(options FormatOptions) string { buf.Grow(33) buf.WriteString(rdi.tag) - buf.WriteString(rdi.FormatReceiverABANumber(options)) - buf.WriteString(rdi.FormatReceiverShortName(options)) + buf.WriteString(rdi.ReceiverABANumberField()) + buf.WriteString(rdi.FormatReceiverShortName(options) + Delimiter) return buf.String() } diff --git a/receiverDepositoryInstitution_test.go b/receiverDepositoryInstitution_test.go index 464bb612..1eecaacc 100644 --- a/receiverDepositoryInstitution_test.go +++ b/receiverDepositoryInstitution_test.go @@ -1,7 +1,6 @@ package wire import ( - "errors" "strings" "testing" @@ -66,7 +65,7 @@ func TestParseReceiverWrongLength(t *testing.T) { // TestParseReceiverReaderParseError parses a wrong Receiver reader parse error func TestParseReceiverReaderParseError(t *testing.T) { - var line = "{3400}2313Z0104Citadel " + var line = "{3400}2313Z0104Citadel *" r := NewReader(strings.NewReader(line)) r.line = line @@ -89,28 +88,28 @@ func TestReceiverDepositoryInstitutionTagError(t *testing.T) { // TestStringReceiverDepositoryInstitutionVariableLength parses using variable length func TestStringReceiverDepositoryInstitutionVariableLength(t *testing.T) { - var line = "{3400}1*A*" + var line = "{3400}1 A*" r := NewReader(strings.NewReader(line)) r.line = line err := r.parseReceiverDepositoryInstitution() require.Nil(t, err) - line = "{3400}1 A NNN" + line = "{3400}1 A NNN*" r = NewReader(strings.NewReader(line)) r.line = line err = r.parseReceiverDepositoryInstitution() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.NoError(t, err) line = "{3400}1*A********" r = NewReader(strings.NewReader(line)) r.line = line err = r.parseReceiverDepositoryInstitution() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrValidLength.Error()) - line = "{3400}1*A*" + line = "{3400}1 A*" r = NewReader(strings.NewReader(line)) r.line = line @@ -120,7 +119,7 @@ func TestStringReceiverDepositoryInstitutionVariableLength(t *testing.T) { // TestStringReceiverDepositoryInstitutionOptions validates Format() formatted according to the FormatOptions func TestStringReceiverDepositoryInstitutionOptions(t *testing.T) { - var line = "{3400}1*A*" + var line = "{3400}1 A*" r := NewReader(strings.NewReader(line)) r.line = line @@ -128,11 +127,11 @@ func TestStringReceiverDepositoryInstitutionOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.ReceiverDepositoryInstitution - require.Equal(t, record.String(), "{3400}1 A ") - require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{3400}1*A*") + require.Equal(t, record.String(), "{3400}1 A *") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{3400}1 A*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) - line = "{3400}1*" + line = "{3400}1 *" r = NewReader(strings.NewReader(line)) r.line = line @@ -140,8 +139,8 @@ func TestStringReceiverDepositoryInstitutionOptions(t *testing.T) { require.Equal(t, err, nil) record = r.currentFEDWireMessage.ReceiverDepositoryInstitution - require.Equal(t, record.String(), "{3400}1 ") - require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{3400}1*") + require.Equal(t, record.String(), "{3400}1 *") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{3400}1 *") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) line = "{3400}111111111*" @@ -152,7 +151,7 @@ func TestStringReceiverDepositoryInstitutionOptions(t *testing.T) { require.Equal(t, err, nil) record = r.currentFEDWireMessage.ReceiverDepositoryInstitution - require.Equal(t, record.String(), "{3400}111111111 ") - require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{3400}111111111") + require.Equal(t, record.String(), "{3400}111111111 *") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{3400}111111111*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/relatedRemittance.go b/relatedRemittance.go index 9bbb64e6..89e965d6 100644 --- a/relatedRemittance.go +++ b/relatedRemittance.go @@ -223,26 +223,26 @@ func (rr *RelatedRemittance) Format(options FormatOptions) string { buf.Grow(3041) buf.WriteString(rr.tag) - buf.WriteString(rr.FormatRemittanceIdentification(options)) - buf.WriteString(rr.FormatRemittanceLocationMethod(options)) - buf.WriteString(rr.FormatRemittanceLocationElectronicAddress(options)) - buf.WriteString(rr.FormatName(options)) - buf.WriteString(rr.FormatAddressType(options)) - buf.WriteString(rr.FormatDepartment(options)) - buf.WriteString(rr.FormatSubDepartment(options)) - buf.WriteString(rr.FormatStreetName(options)) - buf.WriteString(rr.FormatBuildingNumber(options)) - buf.WriteString(rr.FormatPostCode(options)) - buf.WriteString(rr.FormatTownName(options)) - buf.WriteString(rr.FormatCountrySubDivisionState(options)) - buf.WriteString(rr.FormatCountry(options)) - buf.WriteString(rr.FormatAddressLineOne(options)) - buf.WriteString(rr.FormatAddressLineTwo(options)) - buf.WriteString(rr.FormatAddressLineThree(options)) - buf.WriteString(rr.FormatAddressLineFour(options)) - buf.WriteString(rr.FormatAddressLineFive(options)) - buf.WriteString(rr.FormatAddressLineSix(options)) - buf.WriteString(rr.FormatAddressLineSeven(options)) + buf.WriteString(rr.FormatRemittanceIdentification(options) + Delimiter) + buf.WriteString(rr.FormatRemittanceLocationMethod(options) + Delimiter) + buf.WriteString(rr.FormatRemittanceLocationElectronicAddress(options) + Delimiter) + buf.WriteString(rr.FormatName(options) + Delimiter) + buf.WriteString(rr.FormatAddressType(options) + Delimiter) + buf.WriteString(rr.FormatDepartment(options) + Delimiter) + buf.WriteString(rr.FormatSubDepartment(options) + Delimiter) + buf.WriteString(rr.FormatStreetName(options) + Delimiter) + buf.WriteString(rr.FormatBuildingNumber(options) + Delimiter) + buf.WriteString(rr.FormatPostCode(options) + Delimiter) + buf.WriteString(rr.FormatTownName(options) + Delimiter) + buf.WriteString(rr.FormatCountrySubDivisionState(options) + Delimiter) + buf.WriteString(rr.FormatCountry(options) + Delimiter) + buf.WriteString(rr.FormatAddressLineOne(options) + Delimiter) + buf.WriteString(rr.FormatAddressLineTwo(options) + Delimiter) + buf.WriteString(rr.FormatAddressLineThree(options) + Delimiter) + buf.WriteString(rr.FormatAddressLineFour(options) + Delimiter) + buf.WriteString(rr.FormatAddressLineFive(options) + Delimiter) + buf.WriteString(rr.FormatAddressLineSix(options) + Delimiter) + buf.WriteString(rr.FormatAddressLineSeven(options) + Delimiter) if options.VariableLengthFields { return rr.stripDelimiters(buf.String()) diff --git a/relatedRemittance_test.go b/relatedRemittance_test.go index f203ae9f..a84b9227 100644 --- a/relatedRemittance_test.go +++ b/relatedRemittance_test.go @@ -254,18 +254,18 @@ func TestRelatedRemittanceNameRequired(t *testing.T) { // TestParseRelatedRemittanceWrongLength parses a wrong RelatedRemittance record length func TestParseRelatedRemittanceWrongLength(t *testing.T) { - var line = "{8250}Remittance Identification EDIChttp://moov.io Name ADDRDepartment Sub-Department 16 19405 AnyTown PA UAAddress Line One Address Line Two Address Line Three Address Line Four Address Line Five Address Line Six Address Line Seven " + var line = "{8250}Remittance Identification EDIChttp://moov.io Name ADDRDepartment Sub-Department 16 19405 AnyTown PA *UAAddress Line One *Address Line Two *Address Line Three *Address Line Four *Address Line Five *Address Line Six *Address Line Seven " r := NewReader(strings.NewReader(line)) r.line = line err := r.parseRelatedRemittance() - require.EqualError(t, err, r.parseError(fieldError("AddressLineSeven", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("StreetName", ErrRequireDelimiter)).Error()) } // TestParseRelatedRemittanceReaderParseError parses a wrong RelatedRemittance reader parse error func TestParseRelatedRemittanceReaderParseError(t *testing.T) { - var line = "{8250}Remittance ®dentification EDIChttp://moov.io Name ADDRDepartment Sub-Department 16 19405 AnyTown PA UAAddress Line One Address Line Two Address Line Three Address Line Four Address Line Five Address Line Six Address Line Seven " + var line = "{8250}Remittance ®dentification *EDIC*http://moov.io *Name *ADDRDepartment *Sub-Department *16 *19405 *AnyTown *PA *UAAddress Line One *Address Line Two *Address Line Three *Address Line Four *Address Line Five *Address Line Six *Address Line Seven *" r := NewReader(strings.NewReader(line)) r.line = line @@ -300,7 +300,7 @@ func TestStringRelatedRemittanceVariableLength(t *testing.T) { r.line = line err = r.parseRelatedRemittance() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{8250}*EDIC*A*ADDR***************************" r = NewReader(strings.NewReader(line)) @@ -327,7 +327,7 @@ func TestStringRelatedRemittanceOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.RelatedRemittance - require.Equal(t, record.String(), "{8250} EDIC A ADDR ") - require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{8250}*EDIC*A*ADDR*") + require.Equal(t, record.String(), "{8250} *EDIC* *A *ADDR* * * * * * * * * * * * * * * *") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{8250}*EDIC**A*ADDR*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/remittance.go b/remittance.go index f635f333..112f8210 100644 --- a/remittance.go +++ b/remittance.go @@ -112,11 +112,11 @@ func (ri *Remittance) Format(options FormatOptions) string { buf.Grow(151) buf.WriteString(ri.tag) - buf.WriteString(ri.FormatSwiftFieldTag(options)) - buf.WriteString(ri.FormatSwiftLineOne(options)) - buf.WriteString(ri.FormatSwiftLineTwo(options)) - buf.WriteString(ri.FormatSwiftLineThree(options)) - buf.WriteString(ri.FormatSwiftLineFour(options)) + buf.WriteString(ri.FormatSwiftFieldTag(options) + Delimiter) + buf.WriteString(ri.FormatSwiftLineOne(options) + Delimiter) + buf.WriteString(ri.FormatSwiftLineTwo(options) + Delimiter) + buf.WriteString(ri.FormatSwiftLineThree(options) + Delimiter) + buf.WriteString(ri.FormatSwiftLineFour(options) + Delimiter) if options.VariableLengthFields { return ri.stripDelimiters(buf.String()) diff --git a/remittanceBeneficiary.go b/remittanceBeneficiary.go index 0433cc18..1ef53b48 100644 --- a/remittanceBeneficiary.go +++ b/remittanceBeneficiary.go @@ -246,29 +246,29 @@ func (rb *RemittanceBeneficiary) Format(options FormatOptions) string { buf.Grow(1114) buf.WriteString(rb.tag) - buf.WriteString(rb.FormatName(options)) - buf.WriteString(rb.FormatIdentificationType(options)) - buf.WriteString(rb.FormatIdentificationCode(options)) - buf.WriteString(rb.FormatIdentificationNumber(options)) - buf.WriteString(rb.FormatIdentificationNumberIssuer(options)) - buf.WriteString(rb.FormatDateBirthPlace(options)) - buf.WriteString(rb.FormatAddressType(options)) - buf.WriteString(rb.FormatDepartment(options)) - buf.WriteString(rb.FormatSubDepartment(options)) - buf.WriteString(rb.FormatStreetName(options)) + buf.WriteString(rb.FormatName(options) + Delimiter) + buf.WriteString(rb.FormatIdentificationType(options) + Delimiter) + buf.WriteString(rb.FormatIdentificationCode(options) + Delimiter) + buf.WriteString(rb.FormatIdentificationNumber(options) + Delimiter) + buf.WriteString(rb.FormatIdentificationNumberIssuer(options) + Delimiter) + buf.WriteString(rb.FormatDateBirthPlace(options) + Delimiter) + buf.WriteString(rb.FormatAddressType(options) + Delimiter) + buf.WriteString(rb.FormatDepartment(options) + Delimiter) + buf.WriteString(rb.FormatSubDepartment(options) + Delimiter) + buf.WriteString(rb.FormatStreetName(options) + Delimiter) buf.WriteString(rb.FormatBuildingNumber(options)) - buf.WriteString(rb.FormatPostCode(options)) - buf.WriteString(rb.FormatTownName(options)) - buf.WriteString(rb.FormatCountrySubDivisionState(options)) - buf.WriteString(rb.FormatCountry(options)) - buf.WriteString(rb.FormatAddressLineOne(options)) - buf.WriteString(rb.FormatAddressLineTwo(options)) - buf.WriteString(rb.FormatAddressLineThree(options)) - buf.WriteString(rb.FormatAddressLineFour(options)) - buf.WriteString(rb.FormatAddressLineFive(options)) - buf.WriteString(rb.FormatAddressLineSix(options)) - buf.WriteString(rb.FormatAddressLineSeven(options)) - buf.WriteString(rb.FormatCountryOfResidence(options)) + buf.WriteString(rb.FormatPostCode(options) + Delimiter) + buf.WriteString(rb.FormatTownName(options) + Delimiter) + buf.WriteString(rb.FormatCountrySubDivisionState(options) + Delimiter) + buf.WriteString(rb.FormatCountry(options) + Delimiter) + buf.WriteString(rb.FormatAddressLineOne(options) + Delimiter) + buf.WriteString(rb.FormatAddressLineTwo(options) + Delimiter) + buf.WriteString(rb.FormatAddressLineThree(options) + Delimiter) + buf.WriteString(rb.FormatAddressLineFour(options) + Delimiter) + buf.WriteString(rb.FormatAddressLineFive(options) + Delimiter) + buf.WriteString(rb.FormatAddressLineSix(options) + Delimiter) + buf.WriteString(rb.FormatAddressLineSeven(options) + Delimiter) + buf.WriteString(rb.FormatCountryOfResidence(options) + Delimiter) if options.VariableLengthFields { return rb.stripDelimiters(buf.String()) diff --git a/remittanceBeneficiary_test.go b/remittanceBeneficiary_test.go index 805a80e4..18ea4c83 100644 --- a/remittanceBeneficiary_test.go +++ b/remittanceBeneficiary_test.go @@ -349,12 +349,12 @@ func TestParseRemittanceBeneficiaryWrongLength(t *testing.T) { err := r.parseRemittanceBeneficiary() - require.EqualError(t, err, r.parseError(fieldError("AddressLineSeven", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("Name", ErrRequireDelimiter)).Error()) } // TestParseRemittanceBeneficiaryReaderParseError parses a wrong RemittanceBeneficiary reader parse error func TestParseRemittanceBeneficiaryReaderParseError(t *testing.T) { - var line = "{8350}®ame OICUST111111 Bank ADDRDepartment Sub-Department Street Name 16 19405 AnyTown PA UAAddress Line One Address Line Two Address Line Three Address Line Four Address Line Five Address Line Six Address Line Seven US" + var line = "{8350}®ame *OICUST*111111 Bank ADDRDepartment Sub-Department Street Name 16 19405 AnyTown PA UAAddress Line One Address Line Two Address Line Three Address Line Four Address Line Five Address Line Six Address Line Seven US*" r := NewReader(strings.NewReader(line)) r.line = line @@ -377,7 +377,7 @@ func TestRemittanceBeneficiaryTagError(t *testing.T) { // TestStringRemittanceBeneficiaryVariableLength parses using variable length func TestStringRemittanceBeneficiaryVariableLength(t *testing.T) { - var line = "{8350}Name*PIARNU****ADDR*" + var line = "{8350}Name*PI*ARNU****ADDR*" r := NewReader(strings.NewReader(line)) r.line = line @@ -389,26 +389,26 @@ func TestStringRemittanceBeneficiaryVariableLength(t *testing.T) { r.line = line err = r.parseRemittanceBeneficiary() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) - line = "{8350}Name*PIARNU***ADDR****************************" + line = "{8350}Name*PI*ARNU***ADDR****************************" r = NewReader(strings.NewReader(line)) r.line = line err = r.parseRemittanceBeneficiary() require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) - line = "{8350}Name*PIARNU****ADDR*" + line = "{8350}Name*PI*ARNU****ADDR****" r = NewReader(strings.NewReader(line)) r.line = line err = r.parseRemittanceBeneficiary() - require.Equal(t, err, nil) + require.Nil(t, err) } // TestStringRemittanceBeneficiaryOptions validates Format() formatted according to the FormatOptions func TestStringRemittanceBeneficiaryOptions(t *testing.T) { - var line = "{8350}Name*PIARNU****ADDR" + var line = "{8350}Name*PI*ARNU****ADDR*" r := NewReader(strings.NewReader(line)) r.line = line @@ -416,7 +416,7 @@ func TestStringRemittanceBeneficiaryOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.RemittanceBeneficiary - require.Equal(t, record.String(), "{8350}Name PIARNU ADDR ") - require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{8350}Name*PIARNU***ADDR*") + require.Equal(t, record.String(), "{8350}Name *PI*ARNU* * * *ADDR* * * * * * * * * * * * * * * *") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{8350}Name*PI*ARNU****ADDR*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/remittanceFreeText.go b/remittanceFreeText.go index c68065c7..353625e5 100644 --- a/remittanceFreeText.go +++ b/remittanceFreeText.go @@ -102,9 +102,9 @@ func (rft *RemittanceFreeText) Format(options FormatOptions) string { buf.Grow(426) buf.WriteString(rft.tag) - buf.WriteString(rft.FormatLineOne(options)) - buf.WriteString(rft.FormatLineTwo(options)) - buf.WriteString(rft.FormatLineThree(options)) + buf.WriteString(rft.FormatLineOne(options) + Delimiter) + buf.WriteString(rft.FormatLineTwo(options) + Delimiter) + buf.WriteString(rft.FormatLineThree(options) + Delimiter) if options.VariableLengthFields { return rft.stripDelimiters(buf.String()) diff --git a/remittanceFreeText_test.go b/remittanceFreeText_test.go index 2c98e271..bdac1768 100644 --- a/remittanceFreeText_test.go +++ b/remittanceFreeText_test.go @@ -62,12 +62,12 @@ func TestParseRemittanceFreeTextWrongLength(t *testing.T) { err := r.parseRemittanceFreeText() - require.EqualError(t, err, r.parseError(fieldError("LineThree", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("LineOne", ErrRequireDelimiter)).Error()) } // TestParseRemittanceFreeTextReaderParseError parses a wrong RemittanceFreeText reader parse error func TestParseRemittanceFreeTextReaderParseError(t *testing.T) { - var line = "{8750}Re®ittance Free Text Line One Remittance Free Text Line Two Remittance Free Text Line Three " + var line = "{8750}Re®ittance Free Text Line One *Remittance Free Text Line Two Remittance Free Text Line Three *" r := NewReader(strings.NewReader(line)) r.line = line @@ -102,7 +102,7 @@ func TestStringRemittanceFreeTextVariableLength(t *testing.T) { r.line = line err = r.parseRemittanceFreeText() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{8750}****************************" r = NewReader(strings.NewReader(line)) @@ -129,7 +129,7 @@ func TestStringRemittanceFreeTextOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.RemittanceFreeText - require.Equal(t, record.String(), "{8750} ") + require.Equal(t, record.String(), "{8750} * * *") require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{8750}*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/remittanceOriginator.go b/remittanceOriginator.go index baaa479d..9cdf0eca 100644 --- a/remittanceOriginator.go +++ b/remittanceOriginator.go @@ -63,14 +63,14 @@ func (ro *RemittanceOriginator) Parse(record string) error { ro.tag = record[:6] length := 6 - value, read, err := ro.parseVariableStringField(record[length:], 2) + value, read, err := ro.parseFixedStringField(record[length:], 2) if err != nil { return fieldError("IdentificationType", err) } ro.IdentificationType = value length += read - value, read, err = ro.parseVariableStringField(record[length:], 4) + value, read, err = ro.parseFixedStringField(record[length:], 4) if err != nil { return fieldError("IdentificationCode", err) } @@ -300,35 +300,35 @@ func (ro *RemittanceOriginator) Format(options FormatOptions) string { buf.Grow(3442) buf.WriteString(ro.tag) - buf.WriteString(ro.FormatIdentificationType(options)) - buf.WriteString(ro.FormatIdentificationCode(options)) - buf.WriteString(ro.FormatName(options)) - buf.WriteString(ro.FormatIdentificationNumber(options)) - buf.WriteString(ro.FormatIdentificationNumberIssuer(options)) - buf.WriteString(ro.FormatDateBirthPlace(options)) - buf.WriteString(ro.FormatAddressType(options)) - buf.WriteString(ro.FormatDepartment(options)) - buf.WriteString(ro.FormatSubDepartment(options)) - buf.WriteString(ro.FormatStreetName(options)) - buf.WriteString(ro.FormatBuildingNumber(options)) - buf.WriteString(ro.FormatPostCode(options)) - buf.WriteString(ro.FormatTownName(options)) - buf.WriteString(ro.FormatCountrySubDivisionState(options)) - buf.WriteString(ro.FormatCountry(options)) - buf.WriteString(ro.FormatAddressLineOne(options)) - buf.WriteString(ro.FormatAddressLineTwo(options)) - buf.WriteString(ro.FormatAddressLineThree(options)) - buf.WriteString(ro.FormatAddressLineFour(options)) - buf.WriteString(ro.FormatAddressLineFive(options)) - buf.WriteString(ro.FormatAddressLineSix(options)) - buf.WriteString(ro.FormatAddressLineSeven(options)) - buf.WriteString(ro.FormatCountryOfResidence(options)) - buf.WriteString(ro.FormatContactName(options)) - buf.WriteString(ro.FormatContactPhoneNumber(options)) - buf.WriteString(ro.FormatContactMobileNumber(options)) - buf.WriteString(ro.FormatContactFaxNumber(options)) - buf.WriteString(ro.FormatContactElectronicAddress(options)) - buf.WriteString(ro.FormatContactOther(options)) + buf.WriteString(ro.IdentificationTypeField()) + buf.WriteString(ro.IdentificationCodeField()) + buf.WriteString(ro.FormatName(options) + Delimiter) + buf.WriteString(ro.FormatIdentificationNumber(options) + Delimiter) + buf.WriteString(ro.FormatIdentificationNumberIssuer(options) + Delimiter) + buf.WriteString(ro.FormatDateBirthPlace(options) + Delimiter) + buf.WriteString(ro.FormatAddressType(options) + Delimiter) + buf.WriteString(ro.FormatDepartment(options) + Delimiter) + buf.WriteString(ro.FormatSubDepartment(options) + Delimiter) + buf.WriteString(ro.FormatStreetName(options) + Delimiter) + buf.WriteString(ro.FormatBuildingNumber(options) + Delimiter) + buf.WriteString(ro.FormatPostCode(options) + Delimiter) + buf.WriteString(ro.FormatTownName(options) + Delimiter) + buf.WriteString(ro.FormatCountrySubDivisionState(options) + Delimiter) + buf.WriteString(ro.FormatCountry(options) + Delimiter) + buf.WriteString(ro.FormatAddressLineOne(options) + Delimiter) + buf.WriteString(ro.FormatAddressLineTwo(options) + Delimiter) + buf.WriteString(ro.FormatAddressLineThree(options) + Delimiter) + buf.WriteString(ro.FormatAddressLineFour(options) + Delimiter) + buf.WriteString(ro.FormatAddressLineFive(options) + Delimiter) + buf.WriteString(ro.FormatAddressLineSix(options) + Delimiter) + buf.WriteString(ro.FormatAddressLineSeven(options) + Delimiter) + buf.WriteString(ro.FormatCountryOfResidence(options) + Delimiter) + buf.WriteString(ro.FormatContactName(options) + Delimiter) + buf.WriteString(ro.FormatContactPhoneNumber(options) + Delimiter) + buf.WriteString(ro.FormatContactMobileNumber(options) + Delimiter) + buf.WriteString(ro.FormatContactFaxNumber(options) + Delimiter) + buf.WriteString(ro.FormatContactElectronicAddress(options) + Delimiter) + buf.WriteString(ro.FormatContactOther(options) + Delimiter) if options.VariableLengthFields { return ro.stripDelimiters(buf.String()) diff --git a/remittanceOriginator_test.go b/remittanceOriginator_test.go index 16c04000..dbeca0ac 100644 --- a/remittanceOriginator_test.go +++ b/remittanceOriginator_test.go @@ -417,22 +417,7 @@ func TestParseRemittanceOriginatorWrongLength(t *testing.T) { err := r.parseRemittanceOriginator() - require.EqualError(t, err, r.parseError(fieldError("ContactOther", ErrValidLength)).Error()) -} - -// TestParseRemittanceOriginatorReaderParseError parses a wrong RemittanceOriginator reader parse error -func TestParseRemittanceOriginatorReaderParseError(t *testing.T) { - var line = "{8300}OICUSTName 111111 Bank ADDRDepartment Sub-Department Street Name 16 19405 AnyTown PA UA®ddress Line One Address Line Two Address Line Three Address Line Four Address Line Five Address Line Six Address Line Seven USContact Name 5551231212 5551231212 5551231212 http://www.moov.io Contact Other " - r := NewReader(strings.NewReader(line)) - r.line = line - - err := r.parseRemittanceOriginator() - - require.EqualError(t, err, r.parseError(fieldError("AddressLineOne", ErrNonAlphanumeric, "®ddress Line One")).Error()) - - _, err = r.Read() - - require.EqualError(t, err, r.parseError(fieldError("AddressLineOne", ErrNonAlphanumeric, "®ddress Line One")).Error()) + require.EqualError(t, err, r.parseError(fieldError("Name", ErrRequireDelimiter)).Error()) } // TestRemittanceOriginatorTagError validates a RemittanceOriginator tag @@ -445,7 +430,7 @@ func TestRemittanceOriginatorTagError(t *testing.T) { // TestStringRemittanceOriginatorVariableLength parses using variable length func TestStringRemittanceOriginatorVariableLength(t *testing.T) { - var line = "{8300}OICUSTName****ADDR" + var line = "{8300}OICUSTName****ADDR*" r := NewReader(strings.NewReader(line)) r.line = line @@ -457,7 +442,7 @@ func TestStringRemittanceOriginatorVariableLength(t *testing.T) { r.line = line err = r.parseRemittanceOriginator() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{8300}OICUSTName****ADDR*****************************" r = NewReader(strings.NewReader(line)) @@ -476,7 +461,7 @@ func TestStringRemittanceOriginatorVariableLength(t *testing.T) { // TestStringRemittanceOriginatorOptions validates Format() formatted according to the FormatOptions func TestStringRemittanceOriginatorOptions(t *testing.T) { - var line = "{8300}OICUSTName****ADDR" + var line = "{8300}OICUSTName****ADDR*" r := NewReader(strings.NewReader(line)) r.line = line @@ -484,7 +469,7 @@ func TestStringRemittanceOriginatorOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.RemittanceOriginator - require.Equal(t, record.String(), "{8300}OICUSTName ADDR ") + require.Equal(t, record.String(), "{8300}OICUSTName * * * *ADDR* * * * * * * * * * * * * * * * * * * * * * *") require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{8300}OICUSTName****ADDR*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/remittance_test.go b/remittance_test.go index edb64d45..b5c07b0a 100644 --- a/remittance_test.go +++ b/remittance_test.go @@ -98,18 +98,18 @@ func TestRemittanceSwiftLineSixAlphaNumeric(t *testing.T) { // TestParseRemittanceWrongLength parses a wrong Remittance record length func TestParseRemittanceWrongLength(t *testing.T) { - var line = "{7070}SwiftSwift Line One Swift Line Two Swift Line Three Swift Line Four " + var line = "{7070}Swift*Swift Line One *Swift Line Two *Swift Line Three *Swift Line Four " r := NewReader(strings.NewReader(line)) r.line = line err := r.parseRemittance() - require.EqualError(t, err, r.parseError(fieldError("SwiftLineFour", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("SwiftLineFour", ErrRequireDelimiter)).Error()) } // TestParseRemittanceReaderParseError parses a wrong Remittance reader parse error func TestParseRemittanceReaderParseError(t *testing.T) { - var line = "{7070}Swift®wift Line One Swift Line Two Swift Line Three Swift Line Four " + var line = "{7070}Swift*®wift Line One *Swift Line Two *Swift Line Three *Swift Line Four *" r := NewReader(strings.NewReader(line)) r.line = line @@ -144,7 +144,7 @@ func TestStringRemittanceVariableLength(t *testing.T) { r.line = line err = r.parseRemittance() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{7070}************" r = NewReader(strings.NewReader(line)) @@ -171,7 +171,7 @@ func TestStringRemittanceOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.Remittance - require.Equal(t, record.String(), "{7070} ") + require.Equal(t, record.String(), "{7070} * * * * *") require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{7070}*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/secondaryRemittanceDocument.go b/secondaryRemittanceDocument.go index 2126ecc7..6f11dd9b 100644 --- a/secondaryRemittanceDocument.go +++ b/secondaryRemittanceDocument.go @@ -49,7 +49,7 @@ func (srd *SecondaryRemittanceDocument) Parse(record string) error { srd.tag = record[:6] length := 6 - value, read, err := srd.parseVariableStringField(record[length:], 4) + value, read, err := srd.parseFixedStringField(record[length:], 4) if err != nil { return fieldError("DocumentTypeCode", err) } @@ -111,10 +111,10 @@ func (srd *SecondaryRemittanceDocument) Format(options FormatOptions) string { buf.Grow(115) buf.WriteString(srd.tag) - buf.WriteString(srd.FormatDocumentTypeCode(options)) - buf.WriteString(srd.FormatProprietaryDocumentTypeCode(options)) - buf.WriteString(srd.FormatDocumentIdentificationNumber(options)) - buf.WriteString(srd.FormatIssuer(options)) + buf.WriteString(srd.DocumentTypeCodeField()) + buf.WriteString(srd.FormatProprietaryDocumentTypeCode(options) + Delimiter) + buf.WriteString(srd.FormatDocumentIdentificationNumber(options) + Delimiter) + buf.WriteString(srd.FormatIssuer(options) + Delimiter) if options.VariableLengthFields { return srd.stripDelimiters(buf.String()) @@ -168,6 +168,11 @@ func (srd *SecondaryRemittanceDocument) fieldInclusion() error { return nil } +// DocumentTypeCodeField +func (srd *SecondaryRemittanceDocument) DocumentTypeCodeField() string { + return srd.alphaField(srd.DocumentTypeCode, 4) +} + // FormatDocumentTypeCode returns DocumentTypeCode formatted according to the FormatOptions func (srd *SecondaryRemittanceDocument) FormatDocumentTypeCode(options FormatOptions) string { return srd.formatAlphaField(srd.DocumentTypeCode, 4, options) diff --git a/secondaryRemittanceDocument_test.go b/secondaryRemittanceDocument_test.go index 574244fb..23d0e209 100644 --- a/secondaryRemittanceDocument_test.go +++ b/secondaryRemittanceDocument_test.go @@ -106,12 +106,12 @@ func TestParseSecondaryRemittanceDocumentWrongLength(t *testing.T) { err := r.parseSecondaryRemittanceDocument() - require.EqualError(t, err, r.parseError(fieldError("Issuer", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("ProprietaryDocumentTypeCode", ErrRequireDelimiter)).Error()) } // TestParseSecondaryRemittanceDocumentReaderParseError parses a wrong SecondaryRemittanceDocument reader parse error func TestParseSecondaryRemittanceDocumentReaderParseError(t *testing.T) { - var line = "{8700}ZZZZ 222222 Issuer 2 " + var line = "{8700}ZZZZ *222222 *Issuer 2 *" r := NewReader(strings.NewReader(line)) r.line = line @@ -134,7 +134,7 @@ func TestSecondaryRemittanceDocumentTagError(t *testing.T) { // TestStringSecondaryRemittanceDocumentVariableLength parses using variable length func TestStringSecondaryRemittanceDocumentVariableLength(t *testing.T) { - var line = "{8700}AROI**A*" + var line = "{8700}AROI*A*" r := NewReader(strings.NewReader(line)) r.line = line @@ -146,7 +146,7 @@ func TestStringSecondaryRemittanceDocumentVariableLength(t *testing.T) { r.line = line err = r.parseSecondaryRemittanceDocument() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{8700}AROI*A******************************" r = NewReader(strings.NewReader(line)) @@ -155,7 +155,7 @@ func TestStringSecondaryRemittanceDocumentVariableLength(t *testing.T) { err = r.parseSecondaryRemittanceDocument() require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) - line = "{8700}AROI**A*" + line = "{8700}AROI*A*" r = NewReader(strings.NewReader(line)) r.line = line @@ -165,7 +165,7 @@ func TestStringSecondaryRemittanceDocumentVariableLength(t *testing.T) { // TestStringSecondaryRemittanceDocumentOptions validates Format() formatted according to the FormatOptions func TestStringSecondaryRemittanceDocumentOptions(t *testing.T) { - var line = "{8700}AROI**A*" + var line = "{8700}AROI*A*" r := NewReader(strings.NewReader(line)) r.line = line @@ -173,7 +173,7 @@ func TestStringSecondaryRemittanceDocumentOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.SecondaryRemittanceDocument - require.Equal(t, record.String(), "{8700}AROI A ") + require.Equal(t, record.String(), "{8700}AROI *A * *") require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{8700}AROI*A*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/senderDepositoryInstitution.go b/senderDepositoryInstitution.go index 89e7a8b6..f90540cc 100644 --- a/senderDepositoryInstitution.go +++ b/senderDepositoryInstitution.go @@ -45,7 +45,7 @@ func (sdi *SenderDepositoryInstitution) Parse(record string) error { sdi.tag = record[:6] length := 6 - value, read, err := sdi.parseVariableStringField(record[length:], 9) + value, read, err := sdi.parseFixedStringField(record[length:], 9) if err != nil { return fieldError("SenderABANumber", err) } @@ -93,8 +93,8 @@ func (sdi *SenderDepositoryInstitution) Format(options FormatOptions) string { buf.Grow(39) buf.WriteString(sdi.tag) - buf.WriteString(sdi.FormatSenderABANumber(options)) - buf.WriteString(sdi.FormatSenderShortName(options)) + buf.WriteString(sdi.SenderABANumberField()) + buf.WriteString(sdi.FormatSenderShortName(options) + Delimiter) return buf.String() } diff --git a/senderDepositoryInstitution_test.go b/senderDepositoryInstitution_test.go index c6a5258e..b7a8a908 100644 --- a/senderDepositoryInstitution_test.go +++ b/senderDepositoryInstitution_test.go @@ -1,7 +1,6 @@ package wire import ( - "errors" "strings" "testing" @@ -69,7 +68,7 @@ func TestParseSenderWrongLength(t *testing.T) { // TestParseSenderReaderParseError parses a wrong Sender reader parse error func TestParseSenderReaderParseError(t *testing.T) { - var line = "{3100}1210Z2882Wells Fargo NA " + var line = "{3100}1210Z2882Wells Fargo NA *" r := NewReader(strings.NewReader(line)) r.line = line @@ -92,7 +91,7 @@ func TestSenderDepositoryInstitutionTagError(t *testing.T) { // TestStringSenderDepositoryInstitutionVariableLength parses using variable length func TestStringSenderDepositoryInstitutionVariableLength(t *testing.T) { - var line = "{3100}1*A*" + var line = "{3100}1 A*" r := NewReader(strings.NewReader(line)) r.line = line @@ -104,16 +103,16 @@ func TestStringSenderDepositoryInstitutionVariableLength(t *testing.T) { r.line = line err = r.parseSenderDepositoryInstitution() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{3100}1*A***" r = NewReader(strings.NewReader(line)) r.line = line err = r.parseSenderDepositoryInstitution() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrValidLength.Error()) - line = "{3100}1*A*" + line = "{3100}1 A*" r = NewReader(strings.NewReader(line)) r.line = line @@ -123,7 +122,7 @@ func TestStringSenderDepositoryInstitutionVariableLength(t *testing.T) { // TestStringSenderDepositoryInstitutionOptions validates Format() formatted according to the FormatOptions func TestStringSenderDepositoryInstitutionOptions(t *testing.T) { - var line = "{3100}1*A*" + var line = "{3100}1 A*" r := NewReader(strings.NewReader(line)) r.line = line @@ -131,11 +130,11 @@ func TestStringSenderDepositoryInstitutionOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.SenderDepositoryInstitution - require.Equal(t, record.String(), "{3100}1 A ") - require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{3100}1*A*") + require.Equal(t, record.String(), "{3100}1 A *") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{3100}1 A*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) - line = "{3100}1*" + line = "{3100}1 *" r = NewReader(strings.NewReader(line)) r.line = line @@ -143,8 +142,8 @@ func TestStringSenderDepositoryInstitutionOptions(t *testing.T) { require.Equal(t, err, nil) record = r.currentFEDWireMessage.SenderDepositoryInstitution - require.Equal(t, record.String(), "{3100}1 ") - require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{3100}1*") + require.Equal(t, record.String(), "{3100}1 *") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{3100}1 *") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) line = "{3100}111111111*" @@ -155,7 +154,7 @@ func TestStringSenderDepositoryInstitutionOptions(t *testing.T) { require.Equal(t, err, nil) record = r.currentFEDWireMessage.SenderDepositoryInstitution - require.Equal(t, record.String(), "{3100}111111111 ") - require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{3100}111111111") + require.Equal(t, record.String(), "{3100}111111111 *") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{3100}111111111*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/senderReference.go b/senderReference.go index 6ba4086f..57ad5a5b 100644 --- a/senderReference.go +++ b/senderReference.go @@ -84,7 +84,7 @@ func (sr *SenderReference) Format(options FormatOptions) string { buf.Grow(22) buf.WriteString(sr.tag) - buf.WriteString(sr.FormatSenderReference(options)) + buf.WriteString(sr.FormatSenderReference(options) + Delimiter) return buf.String() } diff --git a/senderReference_test.go b/senderReference_test.go index 202efc25..58f469a2 100644 --- a/senderReference_test.go +++ b/senderReference_test.go @@ -40,12 +40,12 @@ func TestParseSenderReferenceWrongLength(t *testing.T) { err := r.parseSenderReference() - require.EqualError(t, err, r.parseError(fieldError("SenderReference", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("SenderReference", ErrRequireDelimiter)).Error()) } // TestParseSenderReferenceReaderParseError parses a wrong SenderReference reader parse error func TestParseSenderReferenceReaderParseError(t *testing.T) { - var line = "{3320}Sender®Referenc" + var line = "{3320}Sender®Referenc*" r := NewReader(strings.NewReader(line)) r.line = line @@ -80,7 +80,7 @@ func TestStringSenderReferenceVariableLength(t *testing.T) { r.line = line err = r.parseSenderReference() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{3320}***" r = NewReader(strings.NewReader(line)) @@ -107,7 +107,7 @@ func TestStringSenderReferenceOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.SenderReference - require.Equal(t, record.String(), "{3320} ") + require.Equal(t, record.String(), "{3320} *") require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{3320}*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/senderSupplied.go b/senderSupplied.go index 257386ff..8f1b5755 100644 --- a/senderSupplied.go +++ b/senderSupplied.go @@ -53,7 +53,7 @@ func (ss *SenderSupplied) Parse(record string) error { ss.FormatVersion = ss.parseStringField(record[6:8]) length := 8 - value, read, err := ss.parseVariableStringField(record[length:], 8) + value, read, err := ss.parseFixedStringField(record[length:], 8) if err != nil { return fieldError("UserRequestCorrelation", err) } @@ -105,9 +105,9 @@ func (ss *SenderSupplied) Format(options FormatOptions) string { buf.WriteString(ss.tag) buf.WriteString(ss.FormatVersionField()) - buf.WriteString(ss.FormatUserRequestCorrelation(options)) + buf.WriteString(ss.UserRequestCorrelationField()) buf.WriteString(ss.TestProductionCodeField()) - buf.WriteString(ss.FormatMessageDuplicationCode(options)) + buf.WriteString(ss.MessageDuplicationCodeField()) return buf.String() } diff --git a/senderSupplied_test.go b/senderSupplied_test.go index f7b9f8fd..1703abd9 100644 --- a/senderSupplied_test.go +++ b/senderSupplied_test.go @@ -127,7 +127,7 @@ func TestStringSenderSuppliedVariableLength(t *testing.T) { r.line = line err := r.parseSenderSupplied() - require.Nil(t, err) + require.ErrorContains(t, err, ErrValidLength.Error()) line = "{1500}301 T NNN " r = NewReader(strings.NewReader(line)) @@ -141,19 +141,12 @@ func TestStringSenderSuppliedVariableLength(t *testing.T) { r.line = line err = r.parseSenderSupplied() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) - - line = "{1500}301*T " - r = NewReader(strings.NewReader(line)) - r.line = line - - err = r.parseSenderSupplied() - require.Equal(t, err, nil) + require.ErrorContains(t, err, ErrValidLength.Error()) } // TestStringSenderSuppliedOptions validates Format() formatted according to the FormatOptions func TestStringSenderSuppliedOptions(t *testing.T) { - var line = "{1500}301*T " + var line = "{1500}301 T " r := NewReader(strings.NewReader(line)) r.line = line @@ -162,6 +155,6 @@ func TestStringSenderSuppliedOptions(t *testing.T) { record := r.currentFEDWireMessage.SenderSupplied require.Equal(t, record.String(), "{1500}301 T ") - require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{1500}301*T ") + require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{1500}301 T ") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/senderToReceiver.go b/senderToReceiver.go index 770f563e..03e0c23a 100644 --- a/senderToReceiver.go +++ b/senderToReceiver.go @@ -126,13 +126,13 @@ func (str *SenderToReceiver) Format(options FormatOptions) string { buf.Grow(221) buf.WriteString(str.tag) - buf.WriteString(str.FormatSwiftFieldTag(options)) - buf.WriteString(str.FormatSwiftLineOne(options)) - buf.WriteString(str.FormatSwiftLineTwo(options)) - buf.WriteString(str.FormatSwiftLineThree(options)) - buf.WriteString(str.FormatSwiftLineFour(options)) - buf.WriteString(str.FormatSwiftLineFive(options)) - buf.WriteString(str.FormatSwiftLineSix(options)) + buf.WriteString(str.FormatSwiftFieldTag(options) + Delimiter) + buf.WriteString(str.FormatSwiftLineOne(options) + Delimiter) + buf.WriteString(str.FormatSwiftLineTwo(options) + Delimiter) + buf.WriteString(str.FormatSwiftLineThree(options) + Delimiter) + buf.WriteString(str.FormatSwiftLineFour(options) + Delimiter) + buf.WriteString(str.FormatSwiftLineFive(options) + Delimiter) + buf.WriteString(str.FormatSwiftLineSix(options) + Delimiter) if options.VariableLengthFields { return str.stripDelimiters(buf.String()) diff --git a/senderToReceiver_test.go b/senderToReceiver_test.go index ce3de9c4..1c5e7d19 100644 --- a/senderToReceiver_test.go +++ b/senderToReceiver_test.go @@ -106,12 +106,12 @@ func TestParseSenderToReceiverWrongLength(t *testing.T) { err := r.parseSenderToReceiver() - require.EqualError(t, err, r.parseError(fieldError("SwiftLineSix", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("SwiftFieldTag", ErrRequireDelimiter)).Error()) } // TestParseSenderToReceiverReaderParseError parses a wrong SenderToReceiver reader parse error func TestParseSenderToReceiverReaderParseError(t *testing.T) { - var line = "{7072}Swift®wift Line One Swift Line Two Swift Line Three Swift Line Four Swift Line Five Swift Line Six " + var line = "{7072}Swift*®wift Line One *Swift Line Two *Swift Line Three *Swift Line Four *Swift Line Five *Swift Line Six *" r := NewReader(strings.NewReader(line)) r.line = line @@ -146,7 +146,7 @@ func TestStringSenderToReceiverVariableLength(t *testing.T) { r.line = line err = r.parseSenderToReceiver() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{7072}**************" r = NewReader(strings.NewReader(line)) @@ -173,7 +173,7 @@ func TestStringSenderToReceiverOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.SenderToReceiver - require.Equal(t, record.String(), "{7072} ") + require.Equal(t, record.String(), "{7072} * * * * * * *") require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{7072}*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) } diff --git a/serviceMessage.go b/serviceMessage.go index b805171a..041a799a 100644 --- a/serviceMessage.go +++ b/serviceMessage.go @@ -183,18 +183,18 @@ func (sm *ServiceMessage) Format(options FormatOptions) string { buf.Grow(426) buf.WriteString(sm.tag) - buf.WriteString(sm.FormatLineOne(options)) - buf.WriteString(sm.FormatLineTwo(options)) - buf.WriteString(sm.FormatLineThree(options)) - buf.WriteString(sm.FormatLineFour(options)) - buf.WriteString(sm.FormatLineFive(options)) - buf.WriteString(sm.FormatLineSix(options)) - buf.WriteString(sm.FormatLineSeven(options)) - buf.WriteString(sm.FormatLineEight(options)) - buf.WriteString(sm.FormatLineNine(options)) - buf.WriteString(sm.FormatLineTen(options)) - buf.WriteString(sm.FormatLineEleven(options)) - buf.WriteString(sm.FormatLineTwelve(options)) + buf.WriteString(sm.FormatLineOne(options) + Delimiter) + buf.WriteString(sm.FormatLineTwo(options) + Delimiter) + buf.WriteString(sm.FormatLineThree(options) + Delimiter) + buf.WriteString(sm.FormatLineFour(options) + Delimiter) + buf.WriteString(sm.FormatLineFive(options) + Delimiter) + buf.WriteString(sm.FormatLineSix(options) + Delimiter) + buf.WriteString(sm.FormatLineSeven(options) + Delimiter) + buf.WriteString(sm.FormatLineEight(options) + Delimiter) + buf.WriteString(sm.FormatLineNine(options) + Delimiter) + buf.WriteString(sm.FormatLineTen(options) + Delimiter) + buf.WriteString(sm.FormatLineEleven(options) + Delimiter) + buf.WriteString(sm.FormatLineTwelve(options) + Delimiter) if options.VariableLengthFields { return sm.stripDelimiters(buf.String()) diff --git a/serviceMessage_test.go b/serviceMessage_test.go index 5c8f0519..1b91e78b 100644 --- a/serviceMessage_test.go +++ b/serviceMessage_test.go @@ -171,12 +171,12 @@ func TestParseServiceMessageWrongLength(t *testing.T) { err := r.parseServiceMessage() - require.EqualError(t, err, r.parseError(fieldError("LineTwelve", ErrValidLength)).Error()) + require.EqualError(t, err, r.parseError(fieldError("LineOne", ErrRequireDelimiter)).Error()) } // TestParseServiceMessageReaderParseError parses a wrong ServiceMessage reader parse error func TestParseServiceMessageReaderParseError(t *testing.T) { - var line = "{9000}®ine One Line Two Line Three Line Four Line Five Line Six Line Seven Line Eight Line Nine Line Ten Line Eleven line Twelve " + var line = "{9000}®ine One *Line Two *Line Three *Line Four *Line Five *Line Six *Line Seven *Line Eight *Line Nine *Line Ten *Line Eleven *line Twelve *" r := NewReader(strings.NewReader(line)) r.line = line @@ -370,7 +370,7 @@ func TestStringServiceMessageVariableLength(t *testing.T) { r.line = line err = r.parseServiceMessage() - require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error()) + require.ErrorContains(t, err, ErrRequireDelimiter.Error()) line = "{9000}**************" r = NewReader(strings.NewReader(line)) @@ -397,7 +397,7 @@ func TestStringServiceMessageOptions(t *testing.T) { require.Equal(t, err, nil) record := r.currentFEDWireMessage.ServiceMessage - require.Equal(t, record.String(), "{9000}A ") + require.Equal(t, record.String(), "{9000}A * * * * * * * * * * * *") require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{9000}A*") require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false})) }