38 lines
1.2 KiB
Java
38 lines
1.2 KiB
Java
package mc.nbt.io;
|
|
|
|
import mc.nbt.CompoundTag;
|
|
import mc.nbt.StringTag;
|
|
import mc.nbt.TagType;
|
|
import mc.nbt.TagValue;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import java.io.IOException;
|
|
import java.util.Objects;
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
class NbtInputStreamTest {
|
|
|
|
@Test
|
|
void testSimple() throws IOException {
|
|
try (var stream = Objects.requireNonNull(NbtInputStreamTest.class.getResourceAsStream("/hello_world.nbt"));
|
|
NbtInputStream nbtInputStream = new NbtInputStream(stream)) {
|
|
|
|
TagValue tag = nbtInputStream.readTag();
|
|
assertNotNull(tag);
|
|
assertEquals(TagType.COMPOUND, tag.getType());
|
|
|
|
CompoundTag compoundTag = tag.asCompound();
|
|
assertEquals("hello world", compoundTag.getName());
|
|
assertEquals(1, compoundTag.size());
|
|
|
|
assertTrue(compoundTag.containsKey("name"));
|
|
tag = compoundTag.get("name");
|
|
assertEquals(TagType.STRING, tag.getType());
|
|
|
|
StringTag stringTag = tag.asString();
|
|
assertEquals("name", stringTag.getName());
|
|
assertEquals("Bananrama", stringTag.getValue());
|
|
}
|
|
}
|
|
} |