Test tag defaults

This commit is contained in:
themode 2021-12-26 10:17:27 +01:00 committed by TheMode
parent 90a217eb9b
commit 3c7291298f
1 changed files with 16 additions and 1 deletions

View File

@ -7,7 +7,7 @@ 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;
import static org.junit.jupiter.api.Assertions.*;
public class TagTest {
@ -34,4 +34,19 @@ public class TagTest {
final String snbt = reader.getTag(Tag.SNBT);
assertEquals(snbt, mutable.toCompound().toSNBT(), "SNBT is not the same");
}
@Test
public void testDefault() {
var nullable = Tag.String("key");
var notNull = nullable.defaultValue("Hey");
assertNotSame(nullable, notNull);
var handler = TagHandler.fromCompound(new MutableNBTCompound());
assertFalse(handler.hasTag(nullable));
assertTrue(handler.hasTag(notNull)); // default value is set
assertFalse(handler.hasTag(nullable));
assertNull(handler.getTag(nullable));
assertEquals("Hey", handler.getTag(notNull));
}
}