nbt can encode or decode bool values as TagByte and []bool as TagByteArray now. close #175

This commit is contained in:
Tnze
2022-05-20 13:18:39 +08:00
parent 1ff25ae8ab
commit 588b7872f1
4 changed files with 67 additions and 7 deletions

View File

@ -364,6 +364,29 @@ func TestDecoder_Decode_ByteArray(t *testing.T) {
// t.Log(infValue)
}
func TestDecoder_Decode_bool(t *testing.T) {
data := [][]byte{
{TagByte, 0, 0, 0},
{TagByte, 0, 0, 1},
{TagByte, 0, 0, 2},
{TagByte, 0, 0, 128},
{TagByte, 0, 0, 255},
}
want := []bool{
false, true, true, true, true,
}
var value bool
for i, v := range data {
//Unmarshal to []byte
if err := Unmarshal(v, &value); err != nil {
t.Fatal(err)
}
if value != want[i] {
t.Errorf("parse fail, expect %v, get %v", want, value)
}
}
}
func TestDecoder_Decode_ErrorString(t *testing.T) {
var data = []byte{
0x08, 0x00, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0xFF, 0xFE,