Skip to content

Commit

Permalink
changed length verification logic, stripping new lines
Browse files Browse the repository at this point in the history
  • Loading branch information
mfdeveloper508 committed Jun 13, 2022
1 parent d8ee14a commit cb710dd
Show file tree
Hide file tree
Showing 89 changed files with 133 additions and 97 deletions.
2 changes: 1 addition & 1 deletion accountCreditedDrawdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (creditDD *AccountCreditedDrawdown) Parse(record string) error {
creditDD.DrawdownCreditAccountNumber = value
length += read

if len(record) != length {
if !creditDD.verifyDataWithReadLength(record, length) {
return NewTagMaxLengthErr()
}

Expand Down
2 changes: 1 addition & 1 deletion accountDebitedDrawdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (debitDD *AccountDebitedDrawdown) Parse(record string) error {
debitDD.Address.AddressLineThree = value
length += read

if len(record) != length {
if !debitDD.verifyDataWithReadLength(record, length) {
return NewTagMaxLengthErr()
}

Expand Down
2 changes: 1 addition & 1 deletion actualAmountPaid.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (aap *ActualAmountPaid) Parse(record string) error {
aap.RemittanceAmount.Amount = value
length += read

if len(record) != length {
if !aap.verifyDataWithReadLength(record, length) {
return NewTagMaxLengthErr()
}

Expand Down
2 changes: 1 addition & 1 deletion actualAmountPaid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestStringActualAmountPaidVariableLength(t *testing.T) {
err = r.parseActualAmountPaid()
require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error())

line = "{8450}***"
line = "{8450}****"
r = NewReader(strings.NewReader(line))
r.line = line

Expand Down
2 changes: 1 addition & 1 deletion adjustment.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (adj *Adjustment) Parse(record string) error {
adj.AdditionalInfo = value
length += read

if len(record) != length {
if !adj.verifyDataWithReadLength(record, length) {
return NewTagMaxLengthErr()
}

Expand Down
2 changes: 1 addition & 1 deletion adjustment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func TestStringAdjustmentVariableLength(t *testing.T) {
err = r.parseAdjustment()
require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error())

line = "{8600}01CRDTUSD1234.56***"
line = "{8600}01CRDTUSD1234.56****"
r = NewReader(strings.NewReader(line))
r.line = line

Expand Down
2 changes: 1 addition & 1 deletion amountNegotiatedDiscount.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (nd *AmountNegotiatedDiscount) Parse(record string) error {
nd.RemittanceAmount.Amount = value
length += read

if len(record) != length {
if !nd.verifyDataWithReadLength(record, length) {
return NewTagMaxLengthErr()
}

Expand Down
2 changes: 1 addition & 1 deletion amountNegotiatedDiscount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestStringAmountNegotiatedDiscountVariableLength(t *testing.T) {
err = r.parseAmountNegotiatedDiscount()
require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error())

line = "{8550}USD1234.56**"
line = "{8550}USD1234.56***"
r = NewReader(strings.NewReader(line))
r.line = line

Expand Down
2 changes: 1 addition & 1 deletion beneficiary.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (ben *Beneficiary) Parse(record string) error {
ben.Personal.Address.AddressLineThree = value
length += read

if len(record) != length {
if !ben.verifyDataWithReadLength(record, length) {
return NewTagMaxLengthErr()
}

Expand Down
2 changes: 1 addition & 1 deletion beneficiaryCustomer.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (bc *BeneficiaryCustomer) Parse(record string) error {
bc.CoverPayment.SwiftLineFive = value
length += read

if len(record) != length {
if !bc.verifyDataWithReadLength(record, length) {
return NewTagMaxLengthErr()
}

Expand Down
2 changes: 1 addition & 1 deletion beneficiaryCustomer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func TestStringBeneficiaryCustomerVariableLength(t *testing.T) {
err = r.parseBeneficiaryCustomer()
require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error())

line = "{7059}*******"
line = "{7059}********"
r = NewReader(strings.NewReader(line))
r.line = line

Expand Down
2 changes: 1 addition & 1 deletion beneficiaryFI.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (bfi *BeneficiaryFI) Parse(record string) error {
bfi.FinancialInstitution.Address.AddressLineThree = value
length += read

if len(record) != length {
if !bfi.verifyDataWithReadLength(record, length) {
return NewTagMaxLengthErr()
}

Expand Down
2 changes: 1 addition & 1 deletion beneficiaryFI_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func TestStringBeneficiaryFIVariableLength(t *testing.T) {
err = r.parseBeneficiaryFI()
require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error())

line = "{4100}D123456789******"
line = "{4100}D123456789*******"
r = NewReader(strings.NewReader(line))
r.line = line

Expand Down
2 changes: 1 addition & 1 deletion beneficiaryIntermediaryFI.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (bifi *BeneficiaryIntermediaryFI) Parse(record string) error {
bifi.FinancialInstitution.Address.AddressLineThree = value
length += read

if len(record) != length {
if !bifi.verifyDataWithReadLength(record, length) {
return NewTagMaxLengthErr()
}

Expand Down
2 changes: 1 addition & 1 deletion beneficiaryIntermediaryFI_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func TestStringBeneficiaryIntermediaryFIVariableLength(t *testing.T) {
err = r.parseBeneficiaryIntermediaryFI()
require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error())

line = "{4000}D123456789******"
line = "{4000}D123456789*******"
r = NewReader(strings.NewReader(line))
r.line = line

Expand Down
2 changes: 1 addition & 1 deletion beneficiaryReference.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (br *BeneficiaryReference) Parse(record string) error {
br.BeneficiaryReference = value
length += read

if len(record) != length {
if !br.verifyDataWithReadLength(record, length) {
return NewTagMaxLengthErr()
}

Expand Down
2 changes: 1 addition & 1 deletion beneficiaryReference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestStringBeneficiaryReferenceVariableLength(t *testing.T) {
err = r.parseBeneficiaryReference()
require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error())

line = "{4320}**"
line = "{4320}***"
r = NewReader(strings.NewReader(line))
r.line = line

Expand Down
2 changes: 1 addition & 1 deletion beneficiary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func TestStringBeneficiaryVariableLength(t *testing.T) {
err = r.parseBeneficiary()
require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error())

line = "{4200}31234******"
line = "{4200}31234*******"
r = NewReader(strings.NewReader(line))
r.line = line

Expand Down
2 changes: 1 addition & 1 deletion businessFunctionCode.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (bfc *BusinessFunctionCode) Parse(record string) error {
bfc.TransactionTypeCode = value
length += read

if len(record) != length {
if !bfc.verifyDataWithReadLength(record, length) {
return NewTagMaxLengthErr()
}

Expand Down
2 changes: 1 addition & 1 deletion businessFunctionCode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func TestStringBusinessFunctionCodeVariableLength(t *testing.T) {
err = r.parseBusinessFunctionCode()
require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error())

line = "{3600}BTR**"
line = "{3600}BTR***"
r = NewReader(strings.NewReader(line))
r.line = line

Expand Down
2 changes: 1 addition & 1 deletion charges.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (c *Charges) Parse(record string) error {
c.SendersChargesFour = value
length += read

if len(record) != length {
if !c.verifyDataWithReadLength(record, length) {
return NewTagMaxLengthErr()
}

Expand Down
2 changes: 1 addition & 1 deletion charges_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestStringChargesVariableLength(t *testing.T) {
err = r.parseCharges()
require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error())

line = "{3700}B*****"
line = "{3700}B******"
r = NewReader(strings.NewReader(line))
r.line = line

Expand Down
13 changes: 13 additions & 0 deletions converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,16 @@ func (c *converters) stripDelimiters(data string) string {

return data[:index]
}

// verify input data with read length
func (c *converters) verifyDataWithReadLength(data string, read int) bool {
if len(data) == read {
return true
}

if len(data) > read && data[read:] == "*" {
return true
}

return false
}
2 changes: 1 addition & 1 deletion currencyInstructedAmount.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (cia *CurrencyInstructedAmount) Parse(record string) error {
cia.Amount = cia.parseStringField(record[length : length+18])
length += 18

if len(record) != length {
if !cia.verifyDataWithReadLength(record, length) {
return NewTagMaxLengthErr()
}

Expand Down
2 changes: 1 addition & 1 deletion errorWire.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (ew *ErrorWire) Parse(record string) error {
ew.ErrorDescription = value
length += read

if len(record) != length {
if !ew.verifyDataWithReadLength(record, length) {
return NewTagMaxLengthErr()
}

Expand Down
2 changes: 1 addition & 1 deletion errorWire_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestStringErrorWireAmountVariableLength(t *testing.T) {
err = r.parseErrorWire()
require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error())

line = "{1130}1XYZData Error**"
line = "{1130}1XYZData Error***"
r = NewReader(strings.NewReader(line))
r.line = line

Expand Down
2 changes: 1 addition & 1 deletion exchangeRate.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (eRate *ExchangeRate) Parse(record string) error {
eRate.ExchangeRate = value
length += read

if len(record) != length {
if !eRate.verifyDataWithReadLength(record, length) {
return NewTagMaxLengthErr()
}

Expand Down
2 changes: 1 addition & 1 deletion exchangeRate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestStringErrorExchangeRateVariableLength(t *testing.T) {
err = r.parseExchangeRate()
require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error())

line = "{3720}123**"
line = "{3720}123***"
r = NewReader(strings.NewReader(line))
r.line = line

Expand Down
2 changes: 1 addition & 1 deletion fIBeneficiaryFIAdvice.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (fibfia *FIBeneficiaryFIAdvice) Parse(record string) error {
fibfia.Advice.LineSix = value
length += read

if len(record) != length {
if !fibfia.verifyDataWithReadLength(record, length) {
return NewTagMaxLengthErr()
}

Expand Down
2 changes: 1 addition & 1 deletion fIBeneficiaryFIAdvice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func TestStringFIBeneficiaryFIAdviceVariableLength(t *testing.T) {
err = r.parseFIBeneficiaryFIAdvice()
require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error())

line = "{6310}HLD*******"
line = "{6310}HLD********"
r = NewReader(strings.NewReader(line))
r.line = line

Expand Down
2 changes: 1 addition & 1 deletion fiAdditionalFIToFI.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (fifi *FIAdditionalFIToFI) Parse(record string) error {
fifi.AdditionalFIToFI.LineSix = value
length += read

if len(record) != length {
if !fifi.verifyDataWithReadLength(record, length) {
return NewTagMaxLengthErr()
}

Expand Down
2 changes: 1 addition & 1 deletion fiAdditionalFIToFI_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func TestStringFIAdditionalFIToFIVariableLength(t *testing.T) {
err = r.parseFIAdditionalFIToFI()
require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error())

line = "{6500}*******"
line = "{6500}********"
r = NewReader(strings.NewReader(line))
r.line = line

Expand Down
2 changes: 1 addition & 1 deletion fiBeneficiary.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (fib *FIBeneficiary) Parse(record string) error {
fib.FIToFI.LineSix = value
length += read

if len(record) != length {
if !fib.verifyDataWithReadLength(record, length) {
return NewTagMaxLengthErr()
}

Expand Down
2 changes: 1 addition & 1 deletion fiBeneficiaryAdvice.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (fiba *FIBeneficiaryAdvice) Parse(record string) error {
fiba.Advice.LineSix = value
length += read

if len(record) != length {
if !fiba.verifyDataWithReadLength(record, length) {
return NewTagMaxLengthErr()
}

Expand Down
2 changes: 1 addition & 1 deletion fiBeneficiaryAdvice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func TestStringFIBeneficiaryAdviceVariableLength(t *testing.T) {
err = r.parseFIBeneficiaryAdvice()
require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error())

line = "{6410}HLD*******"
line = "{6410}HLD********"
r = NewReader(strings.NewReader(line))
r.line = line

Expand Down
2 changes: 1 addition & 1 deletion fiBeneficiaryFI.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (fibfi *FIBeneficiaryFI) Parse(record string) error {
fibfi.FIToFI.LineSix = value
length += read

if len(record) != length {
if !fibfi.verifyDataWithReadLength(record, length) {
return NewTagMaxLengthErr()
}

Expand Down
2 changes: 1 addition & 1 deletion fiBeneficiaryFI_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func TestStringFIBeneficiaryFIVariableLength(t *testing.T) {
err = r.parseFIBeneficiaryFI()
require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error())

line = "{6300}*******"
line = "{6300}********"
r = NewReader(strings.NewReader(line))
r.line = line

Expand Down
2 changes: 1 addition & 1 deletion fiBeneficiary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func TestStringFIBeneficiaryVariableLength(t *testing.T) {
err = r.parseFIBeneficiary()
require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error())

line = "{6400}*******"
line = "{6400}********"
r = NewReader(strings.NewReader(line))
r.line = line

Expand Down
2 changes: 1 addition & 1 deletion fiDrawdownDebitAccountAdvice.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (debitDDAdvice *FIDrawdownDebitAccountAdvice) Parse(record string) error {
debitDDAdvice.Advice.LineSix = value
length += read

if len(record) != length {
if !debitDDAdvice.verifyDataWithReadLength(record, length) {
return NewTagMaxLengthErr()
}

Expand Down
2 changes: 1 addition & 1 deletion fiDrawdownDebitAccountAdvice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func TestStringFIDrawdownDebitAccountAdviceVariableLength(t *testing.T) {
err = r.parseFIDrawdownDebitAccountAdvice()
require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error())

line = "{6110}HLD*******"
line = "{6110}HLD********"
r = NewReader(strings.NewReader(line))
r.line = line

Expand Down
2 changes: 1 addition & 1 deletion fiIntermediaryFI.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (fiifi *FIIntermediaryFI) Parse(record string) error {
fiifi.FIToFI.LineSix = value
length += read

if len(record) != length {
if !fiifi.verifyDataWithReadLength(record, length) {
return NewTagMaxLengthErr()
}

Expand Down
2 changes: 1 addition & 1 deletion fiIntermediaryFIAdvice.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (fiifia *FIIntermediaryFIAdvice) Parse(record string) error {
fiifia.Advice.LineSix = value
length += read

if len(record) != length {
if !fiifia.verifyDataWithReadLength(record, length) {
return NewTagMaxLengthErr()
}

Expand Down
2 changes: 1 addition & 1 deletion fiIntermediaryFIAdvice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func TestStringFIIntermediaryFIAdviceVariableLength(t *testing.T) {
err = r.parseFIIntermediaryFIAdvice()
require.EqualError(t, err, r.parseError(NewTagMaxLengthErr()).Error())

line = "{6210}HLD*******"
line = "{6210}HLD********"
r = NewReader(strings.NewReader(line))
r.line = line

Expand Down
Loading

0 comments on commit cb710dd

Please sign in to comment.