Skip to content

Commit

Permalink
Updates for RuneCountInString
Browse files Browse the repository at this point in the history
  • Loading branch information
bkmoovio committed Jul 16, 2019
1 parent d356b70 commit 084c6aa
Show file tree
Hide file tree
Showing 17 changed files with 139 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,9 @@
## v0.2.1 (Unreleased)

ADDITIONS

- Add RuneCountInString check to Parse(record string) functions

## v0.1.1 (Released 2019-06-25)

BUG FIXES
Expand Down
2 changes: 1 addition & 1 deletion bundleControl.go
Expand Up @@ -55,7 +55,7 @@ func NewBundleControl() *BundleControl {

// Parse takes the input record string and parses the BundleControl values
func (bc *BundleControl) Parse(record string) {
if utf8.RuneCountInString(record) != 80 {
if utf8.RuneCountInString(record) < 56 {
return
}

Expand Down
11 changes: 11 additions & 0 deletions bundleControl_test.go
Expand Up @@ -229,3 +229,14 @@ func TestFieldInclusionBundleTotalAmount(t *testing.T) {
}
}
}

// TestBundleControlRuneCountInString validates RuneCountInString
func TestBundleControlRuneCountInString(t *testing.T) {
bc := NewBundleControl()
var line = "70"
bc.Parse(line)

if bc.BundleItemsCount != 0 {
t.Error("Parsed with an invalid RuneCountInString")
}
}
2 changes: 1 addition & 1 deletion bundleHeader.go
Expand Up @@ -100,7 +100,7 @@ func NewBundleHeader() *BundleHeader {

// Parse takes the input record string and parses the BundleHeader values
func (bh *BundleHeader) Parse(record string) {
if utf8.RuneCountInString(record) != 80 {
if utf8.RuneCountInString(record) < 68 {
return
}

Expand Down
11 changes: 11 additions & 0 deletions bundleHeader_test.go
Expand Up @@ -352,3 +352,14 @@ func TestBHFieldInclusionBundleSequenceNumber(t *testing.T) {
}
}
}

// TestBundleHeaderRuneCountInString validates RuneCountInString
func TestBundleHeaderRuneCountInString(t *testing.T) {
bh := NewBundleHeader()
var line = "20"
bh.Parse(line)

if bh.CycleNumber != "" {
t.Error("Parsed with an invalid RuneCountInString")
}
}
11 changes: 11 additions & 0 deletions cashLetterControl_test.go
Expand Up @@ -217,3 +217,14 @@ func TestFieldInclusionRecordTypeSettlementDate(t *testing.T) {
}
}
}

// TestCashLetterControlRuneCountInString validates RuneCountInString
func TestCashLetterControlRuneCountInString(t *testing.T) {
clc := NewCashLetterControl()
var line = "90"
clc.Parse(line)

if clc.CashLetterBundleCount != 0 {
t.Error("Parsed with an invalid RuneCountInString")
}
}
11 changes: 11 additions & 0 deletions cashLetterHeader_test.go
Expand Up @@ -440,3 +440,14 @@ func TestFieldInclusionCashLetterID(t *testing.T) {
}
}
}

// TestCashLetterHeaderRuneCountInString validates RuneCountInString
func TestCashLetterHeaderRuneCountInString(t *testing.T) {
clh := NewCashLetterHeader()
var line = "10"
clh.Parse(line)

if clh.CollectionTypeIndicator != "" {
t.Error("Parsed with an invalid RuneCountInString")
}
}
4 changes: 4 additions & 0 deletions fileControl.go
Expand Up @@ -7,6 +7,7 @@ package imagecashletter
import (
"fmt"
"strings"
"unicode/utf8"
)

// FileControl Record
Expand Down Expand Up @@ -54,6 +55,9 @@ func NewFileControl() FileControl {

// Parse takes the input record string and parses the FileControl values
func (fc *FileControl) Parse(record string) {
if utf8.RuneCountInString(record) < 65 {
return
}
// Character position 1-2, Always "99"
fc.recordType = "99"
// 03-08
Expand Down
11 changes: 11 additions & 0 deletions fileControl_test.go
Expand Up @@ -254,3 +254,14 @@ func TestFieldInclusionFileTotalAmount(t *testing.T) {
}
}
}

// TestFileControlRuneCountInString validates RuneCountInString
func TestFileControlRuneCountInString(t *testing.T) {
fc := NewFileControl()
var line = "99"
fc.Parse(line)

if fc.CashLetterCount != 0 {
t.Error("Parsed with an invalid RuneCountInString")
}
}
4 changes: 4 additions & 0 deletions fileHeader.go
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"strings"
"time"
"unicode/utf8"
)

// FileHeader Record is mandatory
Expand Down Expand Up @@ -103,6 +104,9 @@ func NewFileHeader() FileHeader {

// Parse takes the input record string and parses the FileHeader values
func (fh *FileHeader) Parse(record string) {
if utf8.RuneCountInString(record) != 80 {
return
}
// Character position 1-2, Always "01"
fh.recordType = "01"
// 03-04
Expand Down
11 changes: 11 additions & 0 deletions fileHeader_test.go
Expand Up @@ -445,3 +445,14 @@ func TestFHFieldInclusionCreationTime(t *testing.T) {
}
}
}

// TestFileHeaderRuneCountInString validates RuneCountInString
func TestFileHeaderRuneCountInString(t *testing.T) {
fh := NewFileHeader()
var line = "01"
fh.Parse(line)

if fh.ImmediateOrigin != "" {
t.Error("Parsed with an invalid RuneCountInString")
}
}
2 changes: 2 additions & 0 deletions go.sum
Expand Up @@ -12,6 +12,7 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-kit/kit v0.8.0 h1:Wz+5lgoB0kkuqLEc6NVmwRknTKP6dTGbSqvhZtBI/j0=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-kit/kit v0.9.0 h1:wDJmvq38kDhkVxi50ni9ykkdUr1PKgqKOoi01fa0Mdk=
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-logfmt/logfmt v0.3.0 h1:8HUsc87TaSWLKwrnumgC8/YconD2fJQsRJAsWaPg2ic=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
Expand All @@ -23,6 +24,7 @@ github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/gorilla/mux v1.7.2 h1:zoNxOV7WjqXptQOVngLmcSQgXmgk4NMz1HibBchjl/I=
github.com/gorilla/mux v1.7.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw=
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
Expand Down
11 changes: 11 additions & 0 deletions imageViewAnalysis_test.go
Expand Up @@ -518,3 +518,14 @@ func TestIVAnalysisFIRecordType(t *testing.T) {
}
}
}

// TestIVAnalysisRuneCountInString validates RuneCountInString
func TestIVAnalysisRuneCountInString(t *testing.T) {
ivAnalysis := NewImageViewAnalysis()
var line = "54"
ivAnalysis.Parse(line)

if ivAnalysis.AmountInWordsUsability != 0 {
t.Error("Parsed with an invalid RuneCountInString")
}
}
11 changes: 11 additions & 0 deletions imageViewDetail_test.go
Expand Up @@ -421,3 +421,14 @@ func TestIVDetailFIViewDescriptor(t *testing.T) {
}
}
}

// TestIVDetailRuneCountInString validates RuneCountInString
func TestIVDetailRuneCountInString(t *testing.T) {
ivDetail := NewImageViewDetail()
var line = "50"
ivDetail.Parse(line)

if ivDetail.ImageCreatorRoutingNumber != "" {
t.Error("Parsed with an invalid RuneCountInString")
}
}
11 changes: 11 additions & 0 deletions returnDetailAddendumC_test.go
Expand Up @@ -246,3 +246,14 @@ func TestRDAddendumCFIMicrofilmArchiveSequenceNumber(t *testing.T) {
}
}
}

// TestRDAddendumCRuneCountInString validates RuneCountInString
func TestRDAddendumCRuneCountInString(t *testing.T) {
rdAddendumC := NewReturnDetailAddendumC()
var line = "34"
rdAddendumC.Parse(line)

if rdAddendumC.Description != "" {
t.Error("Parsed with an invalid RuneCountInString")
}
}
11 changes: 11 additions & 0 deletions returnDetailAddendumD_test.go
Expand Up @@ -368,3 +368,14 @@ func TestRDAddendumDFITruncationIndicator(t *testing.T) {
}
}
}

// TestRDAddendumDRuneCountInString validates RuneCountInString
func TestRDAddendumDRuneCountInString(t *testing.T) {
rdAddendumD := NewReturnDetailAddendumD()
var line = "35"
rdAddendumD.Parse(line)

if rdAddendumD.EndorsingBankRoutingNumber != "" {
t.Error("Parsed with an invalid RuneCountInString")
}
}
11 changes: 11 additions & 0 deletions userPayeeEndorsement_test.go
Expand Up @@ -522,3 +522,14 @@ func TestUPEFILengthUserData(t *testing.T) {
}
}
}

// TestUPERuneCountInString validates RuneCountInString
func TestUPERuneCountInString(t *testing.T) {
upe := NewUserPayeeEndorsement()
var line = "68"
upe.Parse(line)

if upe.BankAccountNumber != "" {
t.Error("Parsed with an invalid RuneCountInString")
}
}

0 comments on commit 084c6aa

Please sign in to comment.