util: add YAML marshaler to Fixed8

This commit is contained in:
Evgenii Stratonikov 2020-01-22 09:58:24 +03:00
parent 7a6d6f43ce
commit 2f865480d3
2 changed files with 33 additions and 2 deletions

View file

@ -6,6 +6,7 @@ import (
"testing"
"github.com/CityOfZion/neo-go/pkg/io"
"github.com/go-yaml/yaml"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@ -125,6 +126,19 @@ func TestFixed8_MarshalJSON(t *testing.T) {
assert.Equal(t, []byte(`"123.4"`), s)
}
func TestFixed8_UnmarshalYAML(t *testing.T) {
u, err := Fixed8FromString("123.4")
assert.NoError(t, err)
s, err := yaml.Marshal(u)
assert.NoError(t, err)
assert.Equal(t, []byte("\"123.4\"\n"), s) // yaml marshaler inserts LF at the end
var f Fixed8
assert.NoError(t, yaml.Unmarshal([]byte(`"123.4"`), &f))
assert.Equal(t, u, f)
}
func TestFixed8_Arith(t *testing.T) {
u1 := Fixed8FromInt64(3)
u2 := Fixed8FromInt64(8)