Skip to content

Commit

Permalink
fix: Added tests for NL & LF (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephan committed May 30, 2023
1 parent a9c2457 commit 6fd7fe8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
30 changes: 10 additions & 20 deletions ebcdic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

/**
Expand All @@ -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)
}

/**
Expand Down
7 changes: 7 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
)
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=

0 comments on commit 6fd7fe8

Please sign in to comment.