util: add YAML marshaler to Fixed8
This commit is contained in:
parent
7a6d6f43ce
commit
2f865480d3
2 changed files with 33 additions and 2 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue