aboutsummaryrefslogtreecommitdiff
path: root/azalea-nbt/tests/decode.rs
diff options
context:
space:
mode:
Diffstat (limited to 'azalea-nbt/tests/decode.rs')
-rw-r--r--azalea-nbt/tests/decode.rs47
1 files changed, 45 insertions, 2 deletions
diff --git a/azalea-nbt/tests/decode.rs b/azalea-nbt/tests/decode.rs
index f4060512..2c69745b 100644
--- a/azalea-nbt/tests/decode.rs
+++ b/azalea-nbt/tests/decode.rs
@@ -1,8 +1,15 @@
use azalea_nbt::Tag;
-use std::collections::HashMap;
+use flate2::{
+ read::{GzDecoder, ZlibDecoder},
+ write::{GzEncoder, ZlibEncoder},
+};
+use std::{
+ collections::HashMap,
+ io::{Cursor, Read},
+};
#[test]
-fn test_hello_world() {
+fn test_decode_hello_world() {
// read hello_world.nbt
let mut file = std::fs::File::open("tests/hello_world.nbt").unwrap();
let tag = Tag::read(&mut file).unwrap();
@@ -17,3 +24,39 @@ fn test_hello_world() {
)]))
);
}
+
+#[test]
+fn test_roundtrip_hello_world() {
+ let mut file = std::fs::File::open("tests/hello_world.nbt").unwrap();
+ let mut original = Vec::new();
+ file.read_to_end(&mut original).unwrap();
+
+ let mut original_stream = Cursor::new(original.clone());
+ let tag = Tag::read(&mut original_stream).unwrap();
+
+ println!("ok read {:?}", tag);
+
+ // write hello_world.nbt
+ let mut result = Cursor::new(Vec::new());
+ tag.write(&mut result).unwrap();
+
+ assert_eq!(result.into_inner(), original);
+}
+
+#[test]
+fn test_bigtest() {
+ // read bigtest.nbt
+ let mut file = std::fs::File::open("tests/bigtest.nbt").unwrap();
+ let mut original = Vec::new();
+ file.read_to_end(&mut original).unwrap();
+
+ let mut original_stream = Cursor::new(original.clone());
+ let original_tag = Tag::read_gzip(&mut original_stream).unwrap();
+
+ let mut result = Vec::new();
+ original_tag.write(&mut result).unwrap();
+
+ let decoded_tag = Tag::read(&mut Cursor::new(result)).unwrap();
+
+ assert_eq!(decoded_tag, original_tag);
+}