Add tests for loop exit, local/global scope, concurrency, and string escapes

This commit is contained in:
Stone_Red
2026-03-05 01:26:16 +01:00
parent 265f20d4b7
commit ecb6415457
5 changed files with 215 additions and 0 deletions
@@ -132,6 +132,25 @@ public class FunctionStatementsTests
YesNtAssert.ContainsTerminationMessage(lines, "Nested functions are not allowed");
}
[TestMethod]
public void LocalVariableDoesNotLeakToCallerTest()
{
List<string> lines =
[
"goto main",
"func modify:",
"var x = inner",
"return",
"label main:",
"var x = outer",
"call modify",
"${x}"
];
YesNtAssert.IsLastLineEqual(lines, "outer");
}
[TestMethod]
public void ClearCallStackRunsTest()
{
@@ -144,5 +163,66 @@ public class FunctionStatementsTests
YesNtAssert.IsLastLineEqual(lines, "ok");
}
// --- Error path tests ---
[TestMethod]
public void AccessInWithoutArgFailsTest()
{
List<string> lines =
[
"goto main",
"func noin:",
"var x = %in",
"return",
"label main:",
"call noin"
];
YesNtAssert.ContainsTerminationMessage(lines, "No in argument in stack");
}
// --- Nested scope tests ---
[TestMethod]
public void GlobalModifiedInsideFunctionIsVisibleAfterReturnTest()
{
List<string> lines =
[
"goto main",
"func setglobal:",
"global shared = modified",
"return",
"label main:",
"global shared = original",
"call setglobal",
"${shared}"
];
YesNtAssert.IsLastLineEqual(lines, "modified");
}
[TestMethod]
public void NestedFunctionCallsHaveIndependentLocalScopesTest()
{
List<string> lines =
[
"goto main",
"func outer:",
"var x = outer_val",
"call inner",
"push_out ${x}",
"return",
"func inner:",
"var x = inner_val",
"return",
"label main:",
"call outer",
"var result = %out",
"${result}"
];
YesNtAssert.IsLastLineEqual(lines, "outer_val");
}
}