Skip to content

Commit bcab928

Browse files
committed
Add game test for properly handling infinite loops, #28
1 parent 8253e21 commit bcab928

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/main/java/org/cyclops/integratedscripting/gametest/GameTestsScripts.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package org.cyclops.integratedscripting.gametest;
22

3+
import com.google.common.collect.Lists;
34
import net.minecraft.core.BlockPos;
45
import net.minecraft.gametest.framework.GameTest;
56
import net.minecraft.gametest.framework.GameTestHelper;
7+
import net.minecraft.network.chat.Component;
68
import net.minecraft.world.item.ItemStack;
79
import net.neoforged.neoforge.gametest.GameTestHolder;
810
import net.neoforged.neoforge.gametest.PrefixGameTestTemplate;
@@ -81,4 +83,35 @@ public void testScriptsDisplayScriptApplied(GameTestHelper helper) {
8183
});
8284
}
8385

86+
@GameTest(template = TEMPLATE_EMPTY, timeoutTicks = TIMEOUT)
87+
public void testScriptsDisplayScriptInfiniteLoop(GameTestHelper helper) {
88+
GameTestHelpersIntegratedScripting.NetworkPositions positions = createBasicNetwork(helper, POS);
89+
90+
// Write script
91+
ScriptingNetworkHelpers.getScriptingData().setScript(positions.diskId(), Path.of("script0.js"), "function oops() {\n" +
92+
" while (true) {}\n" +
93+
"}", IScriptingData.ChangeLocation.MEMORY);
94+
95+
// Create variable from script
96+
ItemStack variableScript = createVariableForScript(helper.getLevel(), positions.diskId(), Path.of("script0.js"), "abc");
97+
98+
// Insert all variables into the variable store
99+
positions.variableStore().getInventory().setItem(0, variableScript);
100+
101+
// Create variable card for applying the function
102+
ItemStack variableAdded = createVariableForOperator(helper.getLevel(), Operators.OPERATOR_APPLY_0, new int[]{
103+
getVariableFacade(helper.getLevel(), variableScript).getId()
104+
});
105+
106+
// Place variable in display
107+
Pair<PartTypePanelDisplay, PartTypePanelDisplay.State> partAndState = placeVariableInDisplayPanel(helper.getLevel(), positions.displayPanel(), variableAdded);
108+
109+
helper.succeedWhen(() -> {
110+
helper.assertValueEqual(partAndState.getRight().getGlobalErrors(), Lists.newArrayList(
111+
Component.translatable("script.integratedscripting.error.member_not_in_network", positions.diskId(), "abc", "script0.js"),
112+
Component.translatable("script.integratedscripting.error.member_not_in_network", positions.diskId(), "abc", "script0.js")
113+
), "Display panel errors do not match");
114+
});
115+
}
116+
84117
}

0 commit comments

Comments
 (0)