diff options
author | Linnea Gräf <nea@nea.moe> | 2025-06-04 01:06:51 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2025-06-04 01:06:51 +0200 |
commit | 2a1631dadfc0f78eb3b7768f9bca3f9fa1ea619e (patch) | |
tree | 422f0d17f4ee40e930a1a84ca9f0d76b4acd3e7c /src/test/kotlin/features/macros | |
parent | 9ad691bc1ba5f50d89a9c99cbf950fe2390a5a44 (diff) | |
download | Firmament-2a1631dadfc0f78eb3b7768f9bca3f9fa1ea619e.tar.gz Firmament-2a1631dadfc0f78eb3b7768f9bca3f9fa1ea619e.tar.bz2 Firmament-2a1631dadfc0f78eb3b7768f9bca3f9fa1ea619e.zip |
feat: Add basic combo buttons (without editor for now)
Diffstat (limited to 'src/test/kotlin/features/macros')
-rw-r--r-- | src/test/kotlin/features/macros/KeyComboTrieCreation.kt | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/src/test/kotlin/features/macros/KeyComboTrieCreation.kt b/src/test/kotlin/features/macros/KeyComboTrieCreation.kt new file mode 100644 index 0000000..f0e7a1b --- /dev/null +++ b/src/test/kotlin/features/macros/KeyComboTrieCreation.kt @@ -0,0 +1,103 @@ +package moe.nea.firmament.test.features.macros + +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.Test +import net.minecraft.client.util.InputUtil +import moe.nea.firmament.features.macros.Branch +import moe.nea.firmament.features.macros.ComboKeyAction +import moe.nea.firmament.features.macros.CommandAction +import moe.nea.firmament.features.macros.KeyComboTrie +import moe.nea.firmament.features.macros.Leaf +import moe.nea.firmament.keybindings.SavedKeyBinding + +class KeyComboTrieCreation { + val basicAction = CommandAction("ac Hello") + val aPress = SavedKeyBinding(InputUtil.GLFW_KEY_A) + val bPress = SavedKeyBinding(InputUtil.GLFW_KEY_B) + val cPress = SavedKeyBinding(InputUtil.GLFW_KEY_C) + + @Test + fun testValidShortTrie() { + val actions = listOf( + ComboKeyAction(basicAction, listOf(aPress)), + ComboKeyAction(basicAction, listOf(bPress)), + ComboKeyAction(basicAction, listOf(cPress)), + ) + Assertions.assertEquals( + Branch( + mapOf( + aPress to Leaf(basicAction), + bPress to Leaf(basicAction), + cPress to Leaf(basicAction), + ), + ), KeyComboTrie.fromComboList(actions) + ) + } + + @Test + fun testOverlappingLeafs() { + Assertions.assertThrows(IllegalStateException::class.java) { + KeyComboTrie.fromComboList( + listOf( + ComboKeyAction(basicAction, listOf(aPress, aPress)), + ComboKeyAction(basicAction, listOf(aPress, aPress)), + ) + ) + } + Assertions.assertThrows(IllegalStateException::class.java) { + KeyComboTrie.fromComboList( + listOf( + ComboKeyAction(basicAction, listOf(aPress)), + ComboKeyAction(basicAction, listOf(aPress)), + ) + ) + } + } + + @Test + fun testBranchOverlappingLeaf() { + Assertions.assertThrows(IllegalStateException::class.java) { + KeyComboTrie.fromComboList( + listOf( + ComboKeyAction(basicAction, listOf(aPress)), + ComboKeyAction(basicAction, listOf(aPress, aPress)), + ) + ) + } + } + @Test + fun testLeafOverlappingBranch() { + Assertions.assertThrows(IllegalStateException::class.java) { + KeyComboTrie.fromComboList( + listOf( + ComboKeyAction(basicAction, listOf(aPress, aPress)), + ComboKeyAction(basicAction, listOf(aPress)), + ) + ) + } + } + + + @Test + fun testValidNestedTrie() { + val actions = listOf( + ComboKeyAction(basicAction, listOf(aPress, aPress)), + ComboKeyAction(basicAction, listOf(aPress, bPress)), + ComboKeyAction(basicAction, listOf(cPress)), + ) + Assertions.assertEquals( + Branch( + mapOf( + aPress to Branch( + mapOf( + aPress to Leaf(basicAction), + bPress to Leaf(basicAction), + ) + ), + cPress to Leaf(basicAction), + ), + ), KeyComboTrie.fromComboList(actions) + ) + } + +} |