diff options
| author | mat <github@matdoes.dev> | 2021-12-19 13:07:54 -0600 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2021-12-19 13:07:54 -0600 |
| commit | 55c9f58219df0fa4a7bdcc2dd34cd71b172f77ea (patch) | |
| tree | 118c9db496099b0c8fab02e65dc9a0b7a7e5310e /azalea-nbt/tests/tests.rs | |
| parent | b030b9de9345d7b1cfef205e5b9a1e2c7dc6025e (diff) | |
| download | azalea-drasl-55c9f58219df0fa4a7bdcc2dd34cd71b172f77ea.tar.xz | |
nbt tests
Diffstat (limited to 'azalea-nbt/tests/tests.rs')
| -rw-r--r-- | azalea-nbt/tests/tests.rs | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/azalea-nbt/tests/tests.rs b/azalea-nbt/tests/tests.rs new file mode 100644 index 00000000..2c69745b --- /dev/null +++ b/azalea-nbt/tests/tests.rs @@ -0,0 +1,62 @@ +use azalea_nbt::Tag; +use flate2::{ + read::{GzDecoder, ZlibDecoder}, + write::{GzEncoder, ZlibEncoder}, +}; +use std::{ + collections::HashMap, + io::{Cursor, Read}, +}; + +#[test] +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(); + assert_eq!( + tag, + Tag::Compound(HashMap::from_iter(vec![( + "hello world".to_string(), + Tag::Compound(HashMap::from_iter(vec![( + "name".to_string(), + Tag::String("Bananrama".to_string()), + )])) + )])) + ); +} + +#[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); +} |
