From 6fd7fe8d59ad89d9b1ccb66b30d1dc947301967a Mon Sep 17 00:00:00 2001 From: stephan Date: Tue, 30 May 2023 03:33:07 +0200 Subject: [PATCH] fix: Added tests for NL & LF (#2) --- Makefile | 5 ++++- ebcdic_test.go | 30 ++++++++++-------------------- go.mod | 7 +++++++ go.sum | 9 +++++++++ 4 files changed, 30 insertions(+), 21 deletions(-) create mode 100644 go.sum diff --git a/Makefile b/Makefile index 07839fb..78088aa 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,10 @@ # Project config BUILD_VERSION ?= SNAPSHOT -all: build_ebcdictoutf8 build_utf8toebcdic +all: test build_ebcdictoutf8 build_utf8toebcdic + +test: + go test ./... build_ebcdictoutf8: cd ./cmd/ebcdictoutf8 && BUILD_VERSION=${BUILD_VERSION} make --always-make diff --git a/ebcdic_test.go b/ebcdic_test.go index 347f076..c235403 100644 --- a/ebcdic_test.go +++ b/ebcdic_test.go @@ -3,30 +3,26 @@ package ebcdic import ( "reflect" "testing" + + "github.com/stretchr/testify/assert" ) /** * Test encoding unicode to EBCDIC 037 **/ func TestSplitEncodeEBCDIC037(t *testing.T) { - in := "This string è contains $%? different special _chars_, z.B. § and Ö" + in := "This string è contains $%? different special _chars_, z.B. § and Ö\u0085\n\x0A" want := []byte{ 0xE3, 0x88, 0x89, 0xA2, 0x40, 0xA2, 0xA3, 0x99, 0x89, 0x95, 0x87, 0x40, 0x54, 0x40, 0x83, 0x96, 0x95, 0xA3, 0x81, 0x89, 0x95, 0xA2, 0x40, 0x5B, 0x6C, 0x6F, 0x40, 0x84, 0x89, 0x86, 0x86, 0x85, 0x99, 0x85, 0x95, 0xA3, 0x40, 0xA2, 0x97, 0x85, 0x83, 0x89, 0x81, 0x93, 0x40, 0x6D, 0x83, 0x88, 0x81, 0x99, 0xA2, 0x6D, 0x6B, 0x40, 0xA9, 0x4B, 0xC2, 0x4B, 0x40, 0xB5, 0x40, 0x81, 0x95, 0x84, - 0x40, 0xEC, + 0x40, 0xEC, 0x15, 0x25, 0x25, } got, err := Encode(in, EBCDIC037) - - if err != nil { - t.Error(err) - } - - if !reflect.DeepEqual(got, want) { - t.Errorf("Encode(\"%s\", EBCDIC037) = %v; want %v", in, got, want) - } + assert.NoError(t, err) + assert.Equal(t, want, got, "Encode(\"%s\", EBCDIC037) = %v; want %v", in, got, want) } /** @@ -38,19 +34,13 @@ func TestSplitDecodeEBCDIC037(t *testing.T) { 0x95, 0xA3, 0x81, 0x89, 0x95, 0xA2, 0x40, 0x5B, 0x6C, 0x6F, 0x40, 0x84, 0x89, 0x86, 0x86, 0x85, 0x99, 0x85, 0x95, 0xA3, 0x40, 0xA2, 0x97, 0x85, 0x83, 0x89, 0x81, 0x93, 0x40, 0x6D, 0x83, 0x88, 0x81, 0x99, 0xA2, 0x6D, 0x6B, 0x40, 0xA9, 0x4B, 0xC2, 0x4B, 0x40, 0xB5, 0x40, 0x81, 0x95, 0x84, - 0x40, 0xEC, + 0x40, 0xEC, 0x15, 0x25, } - want := "This string è contains $%? different special _chars_, z.B. § and Ö" + want := "This string è contains $%? different special _chars_, z.B. § and Ö\u0085\n" got, err := Decode(in, EBCDIC037) - - if err != nil { - t.Error(err) - } - - if got != want { - t.Errorf("Decode(%v, EBCDIC037) = \"%s\"; want \"%s\"", in, got, want) - } + assert.NoError(t, err) + assert.Equal(t, want, got, "Decode(%v, EBCDIC037) = \"%s\"; want \"%s\"", in, got, want) } /** diff --git a/go.mod b/go.mod index 6a71bb9..dc93590 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,10 @@ module github.com/indece-official/go-ebcdic go 1.18 + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/stretchr/testify v1.8.3 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..387a547 --- /dev/null +++ b/go.sum @@ -0,0 +1,9 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= +github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=