Skip to content

Commit

Permalink
Add game test for properly handling infinite loops, #28
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Dec 28, 2024
1 parent 8253e21 commit bcab928
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.cyclops.integratedscripting.gametest;

import com.google.common.collect.Lists;
import net.minecraft.core.BlockPos;
import net.minecraft.gametest.framework.GameTest;
import net.minecraft.gametest.framework.GameTestHelper;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack;
import net.neoforged.neoforge.gametest.GameTestHolder;
import net.neoforged.neoforge.gametest.PrefixGameTestTemplate;
Expand Down Expand Up @@ -81,4 +83,35 @@ public void testScriptsDisplayScriptApplied(GameTestHelper helper) {
});
}

@GameTest(template = TEMPLATE_EMPTY, timeoutTicks = TIMEOUT)
public void testScriptsDisplayScriptInfiniteLoop(GameTestHelper helper) {
GameTestHelpersIntegratedScripting.NetworkPositions positions = createBasicNetwork(helper, POS);

// Write script
ScriptingNetworkHelpers.getScriptingData().setScript(positions.diskId(), Path.of("script0.js"), "function oops() {\n" +
" while (true) {}\n" +
"}", IScriptingData.ChangeLocation.MEMORY);

// Create variable from script
ItemStack variableScript = createVariableForScript(helper.getLevel(), positions.diskId(), Path.of("script0.js"), "abc");

// Insert all variables into the variable store
positions.variableStore().getInventory().setItem(0, variableScript);

// Create variable card for applying the function
ItemStack variableAdded = createVariableForOperator(helper.getLevel(), Operators.OPERATOR_APPLY_0, new int[]{
getVariableFacade(helper.getLevel(), variableScript).getId()
});

// Place variable in display
Pair<PartTypePanelDisplay, PartTypePanelDisplay.State> partAndState = placeVariableInDisplayPanel(helper.getLevel(), positions.displayPanel(), variableAdded);

helper.succeedWhen(() -> {
helper.assertValueEqual(partAndState.getRight().getGlobalErrors(), Lists.newArrayList(
Component.translatable("script.integratedscripting.error.member_not_in_network", positions.diskId(), "abc", "script0.js"),
Component.translatable("script.integratedscripting.error.member_not_in_network", positions.diskId(), "abc", "script0.js")
), "Display panel errors do not match");
});
}

}

0 comments on commit bcab928

Please sign in to comment.