GastinelGarde : arbre de commandes testable, tests des adaptateurs (65 tests), .gitattributes
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Cette révision appartient à :
1 Parent
b07c6b56f2
révision
b7e57250ff
3 fichiers modifiés
+73
-1
Aucun fichier ne correspond à votre recherche
@@ -0,0 +1,4 @@
|
||||
* text=auto
|
||||
*.sh text eol=lf
|
||||
gradlew text eol=lf
|
||||
*.bat text eol=crlf
|
||||
@@ -27,7 +27,11 @@ public final class GardeCommands {
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onRegister(RegisterCommandsEvent event) {
|
||||
CommandDispatcher<CommandSourceStack> d = event.getDispatcher();
|
||||
enregistrer(event.getDispatcher());
|
||||
}
|
||||
|
||||
/** Construit l'arbre de commandes (séparé de l'événement pour pouvoir le tester sans serveur). */
|
||||
public static void enregistrer(CommandDispatcher<CommandSourceStack> d) {
|
||||
|
||||
LiteralArgumentBuilder<CommandSourceStack> racine = Commands.literal("garde")
|
||||
.requires(src -> src.hasPermission(2))
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.gastinelgarde;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import com.gastinelgarde.core.Controle;
|
||||
import com.gastinelgarde.core.GardeConfig;
|
||||
import com.gastinelgarde.core.Mode;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.tree.CommandNode;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Vérifie, sans serveur, que la configuration se construit et que l'arbre des commandes est complet. */
|
||||
class AdaptateursTest {
|
||||
|
||||
@Test
|
||||
void laConfigurationSeConstruitAvecDesValeursParDefautValides() {
|
||||
assertNotNull(GardeSpec.SPEC);
|
||||
// Fichier non chargé : on retombe sur les valeurs par défaut sans exception.
|
||||
assertTrue(GardeSpec.tracesActives());
|
||||
assertEquals(7, GardeSpec.tracesJours());
|
||||
assertEquals(1024L * 1024L * 1024L, GardeSpec.tracesTailleOctets());
|
||||
assertEquals(3, GardeSpec.distanceContraption());
|
||||
assertTrue(GardeSpec.prefixesContraption().contains("com.simibubi.create"));
|
||||
GardeConfig c = new GardeConfig();
|
||||
GardeSpec.appliquer(c); // sans effet tant que le fichier n'est pas chargé
|
||||
for (Controle k : Controle.values()) assertEquals(Mode.OBSERVE, c.mode(k));
|
||||
}
|
||||
|
||||
@Test
|
||||
void arbreDesCommandes() {
|
||||
CommandDispatcher<CommandSourceStack> d = new CommandDispatcher<>();
|
||||
GardeCommands.enregistrer(d);
|
||||
|
||||
CommandNode<CommandSourceStack> garde = d.getRoot().getChild("garde");
|
||||
assertNotNull(garde);
|
||||
for (String sous : new String[] {"status", "alertes", "traces", "mode", "exempter", "reload"}) {
|
||||
assertNotNull(garde.getChild(sous), sous);
|
||||
}
|
||||
CommandNode<CommandSourceStack> mode = garde.getChild("mode");
|
||||
for (Controle c : Controle.values()) {
|
||||
CommandNode<CommandSourceStack> noeud = mode.getChild(c.id());
|
||||
assertNotNull(noeud, c.id());
|
||||
for (Mode m : Mode.values()) {
|
||||
assertNotNull(noeud.getChild(m.name().toLowerCase()), c.id() + " " + m);
|
||||
}
|
||||
}
|
||||
CommandNode<CommandSourceStack> exempter = garde.getChild("exempter").getChild("joueur");
|
||||
assertNotNull(exempter);
|
||||
assertNotNull(exempter.getChild("minutes"));
|
||||
assertFalse(garde.getChildren().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void etatInitialDeLEnregistreur() {
|
||||
// Avant le démarrage du serveur, aucun dossier de traces n'est ouvert.
|
||||
assertFalse(Garde.tracesEnCours());
|
||||
Garde.definirTraces(true);
|
||||
assertFalse(Garde.tracesEnCours());
|
||||
}
|
||||
}
|
||||
Référencer dans un nouveau ticket
Bloquer un utilisateur