can parse TAG_String
This commit is contained in:
42
nbt/nbt_test.go
Normal file
42
nbt/nbt_test.go
Normal file
@ -0,0 +1,42 @@
|
||||
package nbt
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestUnmarshal_simple(t *testing.T) {
|
||||
var data = []byte{
|
||||
0x0a, 0x00, 0x0b, 0x68, 0x65, 0x6c, 0x6c, 0x6f,
|
||||
0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x08, 0x00,
|
||||
0x04, 0x6e, 0x61, 0x6d, 0x65, 0x00, 0x09, 0x42,
|
||||
0x61, 0x6e, 0x61, 0x6e, 0x72, 0x61, 0x6d, 0x61,
|
||||
0x00,
|
||||
}
|
||||
|
||||
var value struct {
|
||||
Name string `nbt:"name"`
|
||||
}
|
||||
|
||||
if err := Unmarshal(data, &value); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if value.Name != "Bananrama" {
|
||||
t.Errorf("Unmarshal NBT fail: get %q, want %q", value.Name, "Bananrama")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshal_string(t *testing.T) {
|
||||
var data = []byte{
|
||||
0x08, 0x00, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x00, 0x09,
|
||||
0x42, 0x61, 0x6e, 0x61, 0x6e, 0x72, 0x61, 0x6d, 0x61,
|
||||
}
|
||||
|
||||
var Name string
|
||||
|
||||
if err := Unmarshal(data, &Name); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if Name != "Bananrama" {
|
||||
t.Errorf("Unmarshal NBT fail: get %q, want %q", Name, "Bananrama")
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user