Skip to content

Commit

Permalink
Added unit test for empty ListTag type preservation
Browse files Browse the repository at this point in the history
  • Loading branch information
dktapps committed Jan 31, 2025
1 parent b2d1b91 commit 6f4a1e4
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/phpunit/tag/ListTagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
namespace pocketmine\nbt\tag;

use PHPUnit\Framework\TestCase;
use pocketmine\nbt\BigEndianNbtSerializer;
use pocketmine\nbt\NBT;
use pocketmine\nbt\TreeRoot;
use function array_fill;
use function array_key_first;
use function array_keys;
Expand Down Expand Up @@ -145,4 +147,19 @@ public function testDelete() : void{
self::assertSame([0, 2], $list->getAllValues());
self::assertSame([0, 1], array_keys($list->getValue()));
}

/**
* Tests that empty lists remember their original type from deserialization
* Previously we were discarding these, creating problems for read/write integrity testing
*/
public function testEmptyBinarySymmetry() : void{
$list = new ListTag([], NBT::TAG_Byte);

$serializer = new BigEndianNbtSerializer();
$list2 = $serializer->read($serializer->write(new TreeRoot($list)))->getTag();

self::assertInstanceOf(ListTag::class, $list2);
self::assertSame($list->getTagType(), $list2->getTagType());
self::assertSame($list->getCount(), $list2->getCount());
}
}

0 comments on commit 6f4a1e4

Please sign in to comment.