From df071d4bfba091873781740ebde0133c670cb97a Mon Sep 17 00:00:00 2001 From: TheMode Date: Wed, 15 Dec 2021 18:39:27 +0100 Subject: [PATCH] Simple tests for tags Signed-off-by: TheMode --- src/test/java/tag/TagTest.java | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/test/java/tag/TagTest.java diff --git a/src/test/java/tag/TagTest.java b/src/test/java/tag/TagTest.java new file mode 100644 index 000000000..20f1342b7 --- /dev/null +++ b/src/test/java/tag/TagTest.java @@ -0,0 +1,37 @@ +package tag; + +import net.minestom.server.tag.Tag; +import net.minestom.server.tag.TagHandler; +import net.minestom.server.tag.TagReadable; +import org.jglrxavpok.hephaistos.nbt.NBTCompound; +import org.jglrxavpok.hephaistos.nbt.mutable.MutableNBTCompound; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class TagTest { + + @Test + public void testTag() { + var mutable = new MutableNBTCompound(); + mutable.setInt("key", 5); + var tag = Tag.Integer("key"); + var handler = TagHandler.fromCompound(new MutableNBTCompound()); + handler.setTag(tag, 5); + assertEquals(mutable.toCompound(), handler.getTag(Tag.NBT), "NBT is not the same"); + + // Removal + handler.setTag(tag, null); + assertEquals(new NBTCompound(), handler.getTag(Tag.NBT), "Tag must be removed when set to null"); + } + + @Test + public void testSnbt() { + var mutable = new MutableNBTCompound(); + mutable.setInt("key", 5); + + var reader = TagReadable.fromCompound(mutable); + final String snbt = reader.getTag(Tag.SNBT); + assertEquals(snbt, mutable.toCompound().toSNBT(), "SNBT is not the same"); + } +}