Improve tag nbt convertor tests

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2022-04-14 01:13:45 +02:00
parent e026a841ab
commit 3371de9556
2 changed files with 25 additions and 8 deletions

View File

@ -3,8 +3,7 @@ package net.minestom.server.tag;
import net.kyori.adventure.text.Component;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.*;
public class TagComponentTest {
@ -31,4 +30,14 @@ public class TagComponentTest {
handler.setTag(Tag.Integer("entry"), 1);
assertNull(handler.getTag(tag));
}
@Test
public void nbtFallback() {
var component = Component.text("Hey");
var tag = Tag.Component("component");
var handler = TagHandler.newHandler();
handler.setTag(tag, component);
handler = TagHandler.fromCompound(handler.asCompound());
assertEquals(component, handler.getTag(tag));
}
}

View File

@ -4,9 +4,10 @@ import org.jglrxavpok.hephaistos.nbt.NBT;
import org.jglrxavpok.hephaistos.nbt.NBTType;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -34,25 +35,32 @@ public class TagNbtSeparatorTest {
"path", NBT.Compound(Map.of("key", NBT.Byte(1))));
}
@Test
public void compoundMultiple() {
assertSeparation(Set.of(new TagNbtSeparator.Entry<>(Tag.Byte("key").path("path"), (byte) 1),
new TagNbtSeparator.Entry<>(Tag.Integer("key2").path("path"), 2)),
"path", NBT.Compound(Map.of("key", NBT.Byte(1), "key2", NBT.Int(2))));
}
@Test
public void list() {
assertSeparation(new TagNbtSeparator.Entry<>(Tag.Integer("key").list(), List.of(1)),
"key", NBT.List(NBTType.TAG_Int, NBT.Int(1)));
}
void assertSeparation(List<TagNbtSeparator.Entry<?>> expected, String key, NBT nbt) {
void assertSeparation(Set<TagNbtSeparator.Entry<?>> expected, String key, NBT nbt) {
assertEquals(expected, retrieve(key, nbt));
}
void assertSeparation(TagNbtSeparator.Entry<?> expected, String key, NBT nbt) {
var entries = retrieve(key, nbt);
assertEquals(1, entries.size());
assertEquals(expected, entries.get(0));
assertEquals(expected, entries.iterator().next());
}
List<TagNbtSeparator.Entry<?>> retrieve(String key, NBT nbt) {
List<TagNbtSeparator.Entry<?>> entries = new ArrayList<>();
Set<TagNbtSeparator.Entry<?>> retrieve(String key, NBT nbt) {
Set<TagNbtSeparator.Entry<?>> entries = new HashSet<>();
TagNbtSeparator.separate(key, nbt, entries::add);
return entries;
return Set.copyOf(entries);
}
}