Skip to content

Commit

Permalink
utf8 example
Browse files Browse the repository at this point in the history
  • Loading branch information
alovak committed Nov 14, 2023
1 parent 9226221 commit 2885c7c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions field/string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/moov-io/iso8583/encoding"
"github.com/moov-io/iso8583/padding"
"github.com/moov-io/iso8583/prefix"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -59,6 +60,28 @@ func TestStringField(t *testing.T) {
require.Equal(t, "hello", str.Value())
}

func TestStringWithUTF8Encoding(t *testing.T) {
spec := &Spec{
Length: 10,
Description: "Field",
Enc: encoding.Binary,
Pref: prefix.Binary.Fixed,
Pad: padding.Left(' '),
}
str := NewStringValue("hüllo")
str.SetSpec(spec)
packed, err := str.Pack()
require.NoError(t, err)

assert.Len(t, packed, 10)

str2 := NewString(spec)
_, err = str2.Unpack(packed)
require.NoError(t, err)

assert.Equal(t, "hüllo", str2.Value())
}

func TestStringWithNonUTF8Encoding(t *testing.T) {
spec := &Spec{
Length: 10,
Expand Down

0 comments on commit 2885c7c

Please sign in to comment.