Marshal without test and TagList

This commit is contained in:
JunDao
2019-05-19 00:15:14 +08:00
parent 0b9984da07
commit b28cc4f2da
4 changed files with 260 additions and 0 deletions

35
nbt/marshal_test.go Normal file
View File

@ -0,0 +1,35 @@
package nbt
import (
"bytes"
"reflect"
"testing"
)
func TestMarshal(t *testing.T) {
var (
want = []byte{
0x0A, 0, 0,
0x08, 0, 4, 0x4e, 0x61, 0x6d, 0x65, 0, 4, 0x54, 0x6e, 0x7a, 0x65,
0x01, 0x00, 0x08, 0x42, 0x79, 0x74, 0x65, 0x54, 0x65, 0x73, 0x74, 0xFF,
0,
}
value struct {
Name string
ByteTest byte
}
)
value.Name = "Tnze"
value.ByteTest = 0xFF
var buf bytes.Buffer
if err := Marshal(&buf, value); err != nil {
t.Fatal(err)
}
gets := buf.Bytes()
if !reflect.DeepEqual(gets, want) {
t.Errorf("marshal wrong: get [% 02x], want [% 02x]", gets, want)
}
}