From ce60b817f31b20125644c12fbf13f981809d5324 Mon Sep 17 00:00:00 2001 From: StackDoubleFlow Date: Mon, 15 Nov 2021 13:08:56 -0600 Subject: [PATCH] Add test for array value serialization in blobs --- tests/serde_basics.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/serde_basics.rs b/tests/serde_basics.rs index 8f1f163..998672e 100644 --- a/tests/serde_basics.rs +++ b/tests/serde_basics.rs @@ -567,3 +567,34 @@ fn roundtrip_hashmap() { assert_roundtrip_eq(nbt, &bytes, None); } + +#[test] +fn ser_blob_array() { + let mut blob = nbt::Blob::new(); + blob.insert("larr", nbt::Value::LongArray(vec![456, 123])).unwrap(); + blob.insert("iarr", nbt::Value::IntArray(vec![123, 456])).unwrap(); + + #[rustfmt::skip] + let bytes = vec![ + 0x0a, + 0x00, 0x00, + 0x0c, + 0x00, 0x04, + 0x6c, 0x61, 0x72, 0x72, + 0x00, 0x00, 0x00, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc8, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7b, + 0x0b, + 0x00, 0x04, + 0x69, 0x61, 0x72, 0x72, + 0x00, 0x00, 0x00, 0x02, + 0x00, 0x00, 0x00, 0x7b, + 0x00, 0x00, 0x01, 0xc8, + 0x00 + ]; + + let mut dst = Vec::with_capacity(bytes.len()); + + nbt::ser::to_writer(&mut dst, &blob, None).expect("NBT serialization."); + assert_eq!(bytes, &dst[..]); +}