aboutsummaryrefslogtreecommitdiff
path: root/src/test/kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/kotlin')
-rw-r--r--src/test/kotlin/root.kt29
-rw-r--r--src/test/kotlin/testutil/ItemResources.kt30
-rw-r--r--src/test/kotlin/util/ColorCodeTest.kt (renamed from src/test/kotlin/moe/nea/firmament/test/ColorCode.kt)7
-rw-r--r--src/test/kotlin/util/skyblock/AbilityUtilsTest.kt79
4 files changed, 142 insertions, 3 deletions
diff --git a/src/test/kotlin/root.kt b/src/test/kotlin/root.kt
new file mode 100644
index 0000000..679ecb4
--- /dev/null
+++ b/src/test/kotlin/root.kt
@@ -0,0 +1,29 @@
+package moe.nea.firmament.test
+
+import net.minecraft.Bootstrap
+import net.minecraft.SharedConstants
+import moe.nea.firmament.util.TimeMark
+
+ object FirmTestBootstrap {
+ val loadStart = TimeMark.now()
+
+ init {
+ println("Bootstrap started at $loadStart")
+ }
+
+ init {
+ SharedConstants.createGameVersion()
+ Bootstrap.initialize()
+ }
+
+ val loadEnd = TimeMark.now()
+
+ val loadDuration = loadStart.passedAt(loadEnd)
+
+ init {
+ println("Bootstrap completed at $loadEnd after $loadDuration")
+ }
+
+ fun bootstrapMinecraft() {
+ }
+}
diff --git a/src/test/kotlin/testutil/ItemResources.kt b/src/test/kotlin/testutil/ItemResources.kt
new file mode 100644
index 0000000..bd3c438
--- /dev/null
+++ b/src/test/kotlin/testutil/ItemResources.kt
@@ -0,0 +1,30 @@
+package moe.nea.firmament.test.testutil
+
+import net.minecraft.item.ItemStack
+import net.minecraft.nbt.NbtCompound
+import net.minecraft.nbt.NbtOps
+import net.minecraft.nbt.StringNbtReader
+import moe.nea.firmament.test.FirmTestBootstrap
+
+object ItemResources {
+ init {
+ FirmTestBootstrap.bootstrapMinecraft()
+ }
+
+ fun loadString(path: String): String {
+ require(!path.startsWith("/"))
+ return ItemResources::class.java.classLoader
+ .getResourceAsStream(path)!!
+ .readAllBytes().decodeToString()
+ }
+
+ fun loadSNbt(path: String): NbtCompound {
+ return StringNbtReader.parse(loadString(path))
+ }
+
+ fun loadItem(name: String): ItemStack {
+ // TODO: make the load work with enchantments
+ return ItemStack.CODEC.parse(NbtOps.INSTANCE, loadSNbt("testdata/items/$name.snbt"))
+ .getOrThrow { IllegalStateException("Could not load test item '$name': $it") }
+ }
+}
diff --git a/src/test/kotlin/moe/nea/firmament/test/ColorCode.kt b/src/test/kotlin/util/ColorCodeTest.kt
index 5889bc7..d9de36a 100644
--- a/src/test/kotlin/moe/nea/firmament/test/ColorCode.kt
+++ b/src/test/kotlin/util/ColorCodeTest.kt
@@ -1,12 +1,13 @@
-
-package moe.nea.firmament.test
+package moe.nea.firmament.test.util
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
+import net.minecraft.Bootstrap
+import net.minecraft.SharedConstants
import moe.nea.firmament.util.removeColorCodes
-class ColorCode {
+class ColorCodeTest {
@Test
fun testWhatever() {
Assertions.assertEquals("", "".removeColorCodes().toString())
diff --git a/src/test/kotlin/util/skyblock/AbilityUtilsTest.kt b/src/test/kotlin/util/skyblock/AbilityUtilsTest.kt
new file mode 100644
index 0000000..abe739d
--- /dev/null
+++ b/src/test/kotlin/util/skyblock/AbilityUtilsTest.kt
@@ -0,0 +1,79 @@
+package moe.nea.firmament.test.util.skyblock
+
+import org.junit.jupiter.api.Assertions
+import org.junit.jupiter.api.Test
+import kotlin.time.Duration.Companion.minutes
+import kotlin.time.Duration.Companion.seconds
+import net.minecraft.text.Text
+import moe.nea.firmament.test.testutil.ItemResources
+import moe.nea.firmament.util.skyblock.AbilityUtils
+import moe.nea.firmament.util.unformattedString
+
+class AbilityUtilsTest {
+
+ fun List<AbilityUtils.ItemAbility>.stripDescriptions() = map {
+ it.copy(descriptionLines = it.descriptionLines.map { Text.literal(it.unformattedString) })
+ }
+
+ @Test
+ fun testUnpoweredDrill() {
+ Assertions.assertEquals(
+ listOf(
+ AbilityUtils.ItemAbility(
+ "Pickobulus",
+ false,
+ AbilityUtils.AbilityActivation.RIGHT_CLICK,
+ null,
+ listOf("Throw your pickaxe to create an",
+ "explosion mining all ores in a 3 block",
+ "radius.").map(Text::literal),
+ 48.seconds
+ )
+ ),
+ AbilityUtils.getAbilities(ItemResources.loadItem("titanium-drill")).stripDescriptions()
+ )
+ }
+
+ @Test
+ fun testPoweredPickaxe() {
+ Assertions.assertEquals(
+ listOf(
+ AbilityUtils.ItemAbility(
+ "Mining Speed Boost",
+ true,
+ AbilityUtils.AbilityActivation.RIGHT_CLICK,
+ null,
+ listOf("Grants +200% ⸕ Mining Speed for",
+ "10s.").map(Text::literal),
+ 2.minutes
+ )
+ ),
+ AbilityUtils.getAbilities(ItemResources.loadItem("diamond-pickaxe")).stripDescriptions()
+ )
+ }
+
+ @Test
+ fun testAOTV() {
+ Assertions.assertEquals(
+ listOf(
+ AbilityUtils.ItemAbility(
+ "Instant Transmission", true, AbilityUtils.AbilityActivation.RIGHT_CLICK, 23,
+ listOf("Teleport 12 blocks ahead of you and",
+ "gain +50 ✦ Speed for 3 seconds.").map(Text::literal),
+ null
+ ),
+ AbilityUtils.ItemAbility(
+ "Ether Transmission",
+ false,
+ AbilityUtils.AbilityActivation.SNEAK_RIGHT_CLICK,
+ 90,
+ listOf("Teleport to your targeted block up",
+ "to 61 blocks away.",
+ "Soulflow Cost: 1").map(Text::literal),
+ null
+ )
+ ),
+ AbilityUtils.getAbilities(ItemResources.loadItem("aspect-of-the-void")).stripDescriptions()
+ )
+ }
+}