-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for typed array tags + update to 0.2.0
Signed-off-by: hypothermic <admin@hypothermic.nl>
- Loading branch information
1 parent
b7280c1
commit 60c50cb
Showing
11 changed files
with
183 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# erl_nbt tests | ||
|
||
A quick overview what every test is for | ||
|
||
| Name | Description | | ||
| --------------- | -------------------------------------------------------- | | ||
| Basic | Tests the parser using Notch's "basic" example file | | ||
| Integers | Tests support for Byte, Short, Int, Long tags | | ||
| Floating Points | Tests support for Float and Double tags | | ||
| Integer Arrays | Tests support for ByteArray, IntArray and LongArray tags | | ||
| Compounds | Tests support for (nested) Compound tags | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
%%%------------------------------------------------------------------- | ||
%%% @author Matthijs Bakker <matthijs at hypothermic .nl> | ||
%%% @copyright (C) 2021 hypothermic.nl | ||
%%% @doc | ||
%%% Tests the erl_nbt functionality on the "integers.nbt" example | ||
%%% @end | ||
%%% Created : 8. Jul 2021 10:25 PM | ||
%%%------------------------------------------------------------------- | ||
-module(integer_arrays_test). | ||
-author("Matthijs Bakker <matthijs at hypothermic .nl>"). | ||
-copyright("Copyright (C) 2021 hypothermic.nl"). | ||
|
||
-include_lib("erl_nbt.hrl"). | ||
-include_lib("eunit/include/eunit.hrl"). | ||
|
||
-define(TEST_FILE, "test/integer_arrays.nbt"). | ||
-define(EXPECTED_NBT, | ||
#{ | ||
"arrays" => #{ | ||
"bunch of bytes" => {?TAG_BYTE_ARRAY_TYPE, [-43, 67, 49, 108]}, | ||
"flock of ints" => {?TAG_INT_ARRAY_TYPE, [420, 2147483646, -82131929]}, | ||
"lots of longs" => {?TAG_LONG_ARRAY_TYPE, [-921312010, 69, 129391203]} | ||
} | ||
} | ||
). | ||
|
||
integer_arrays_test_() -> [ | ||
{"decode file integer_arrays.nbt", | ||
fun () -> | ||
{ok, InputData} = file:read_file(?TEST_FILE), | ||
{ok, DecodedNbt} = erl_nbt:decode(InputData), | ||
|
||
?assertEqual(?EXPECTED_NBT, DecodedNbt) | ||
end | ||
}, | ||
{"encode map and compare with file integer_arrays.nbt", | ||
fun () -> | ||
{ok, EncodedNbt} = erl_nbt:encode(?EXPECTED_NBT), | ||
{ok, CorrectData} = file:read_file(?TEST_FILE), | ||
|
||
% Because child order of compound tags is not guaranteed | ||
% to be preserved with NBT tags, we can't test for equality. | ||
% So we only test if the length of these binaries are equal. | ||
?assertEqual(byte_size(CorrectData), byte_size(EncodedNbt)) | ||
end | ||
}, | ||
{"encode then decode", | ||
fun () -> | ||
{ok, EncodedNbt} = erl_nbt:encode(?EXPECTED_NBT), | ||
{ok, DecodedNbt} = erl_nbt:decode(EncodedNbt), | ||
?assertEqual(DecodedNbt, ?EXPECTED_NBT) | ||
end | ||
} | ||
]. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters