From 99096fac8a0b746e373ed798f97efdfd20b8b898 Mon Sep 17 00:00:00 2001 From: Tnze Date: Sat, 29 Apr 2023 00:47:52 +0800 Subject: [PATCH] Add unit test case for anonymous field --- nbt/special_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/nbt/special_test.go b/nbt/special_test.go index 3109b06..ccf9442 100644 --- a/nbt/special_test.go +++ b/nbt/special_test.go @@ -80,3 +80,25 @@ func TestMarshal_anonymousPointerNesting(t *testing.T) { t.Errorf("Marshal nesting anonymous struct error, got %q, want %q", snbt, want) } } + +func TestMarshal_anonymousNonStruct(t *testing.T) { + type A [3]int32 + type B struct{ *A } + type C struct{ B } + + val := C{B{&A{0, -1, 3}}} + + data, err := nbt.Marshal(val) + if err != nil { + panic(err) + } + + var snbt nbt.StringifiedMessage + if err := nbt.Unmarshal(data, &snbt); err != nil { + panic(err) + } + want := `{A:[I;0I,-1I,3I]}` + if string(snbt) != want { + t.Errorf("Marshal nesting anonymous struct error, got %q, want %q", snbt, want) + } +}