mirror of
https://github.com/Stone-Red-Code/YesNt-Interpreter.git
synced 2026-09-08 23:43:18 +02:00
Add new tests for console, function, system, variable, and code flow statements
This commit is contained in:
@@ -136,4 +136,136 @@ public class CodeFlowTests
|
||||
|
||||
YesNtAssert.IsLastLineEqual(lines, "4");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IfElseTrueSkipsElseBranchTest()
|
||||
{
|
||||
List<string> lines =
|
||||
[
|
||||
"let result = 0",
|
||||
"if 2 > 1:",
|
||||
"let result = 1",
|
||||
"else:",
|
||||
"let result = 2",
|
||||
"end_if",
|
||||
"${result}"
|
||||
];
|
||||
|
||||
YesNtAssert.IsLastLineEqual(lines, "1");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IfWithoutElseFalseSkipsBodyTest()
|
||||
{
|
||||
List<string> lines =
|
||||
[
|
||||
"let result = 5",
|
||||
"if 1 == 2:",
|
||||
"let result = 1",
|
||||
"end_if",
|
||||
"${result}"
|
||||
];
|
||||
|
||||
YesNtAssert.IsLastLineEqual(lines, "5");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IfGotoTrueTest()
|
||||
{
|
||||
List<string> lines =
|
||||
[
|
||||
"let result = 0",
|
||||
"if 1 == 1 goto done",
|
||||
"let result = 2",
|
||||
"label done:",
|
||||
"let result = ${result} + 1 calc",
|
||||
"${result}"
|
||||
];
|
||||
|
||||
YesNtAssert.IsLastLineEqual(lines, "1");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IfCallTrueTest()
|
||||
{
|
||||
List<string> lines =
|
||||
[
|
||||
"func set_result:",
|
||||
"global result = ok",
|
||||
"return",
|
||||
"if 1 == 1 call set_result",
|
||||
"${result}"
|
||||
];
|
||||
|
||||
YesNtAssert.IsLastLineEqual(lines, "ok");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void LabelWithoutColonFailsTest()
|
||||
{
|
||||
List<string> lines =
|
||||
[
|
||||
"label loop"
|
||||
];
|
||||
|
||||
YesNtAssert.ContainsTerminationMessage(lines, "Invalid statement");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void FunctionWithoutColonFailsTest()
|
||||
{
|
||||
List<string> lines =
|
||||
[
|
||||
"func missing"
|
||||
];
|
||||
|
||||
YesNtAssert.ContainsTerminationMessage(lines, "Invalid statement");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MissingEndIfFailsTest()
|
||||
{
|
||||
List<string> lines =
|
||||
[
|
||||
"if 1 == 2:",
|
||||
"let result = 1"
|
||||
];
|
||||
|
||||
YesNtAssert.ContainsTerminationMessage(lines, "No matching end_if found");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ElseWithoutIfFailsTest()
|
||||
{
|
||||
List<string> lines =
|
||||
[
|
||||
"else:"
|
||||
];
|
||||
|
||||
YesNtAssert.ContainsTerminationMessage(lines, "No matching end_if found");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MissingEndWhileFailsTest()
|
||||
{
|
||||
List<string> lines =
|
||||
[
|
||||
"let i = 0",
|
||||
"while ${i} > 1:",
|
||||
"let i = ${i} + 1 calc"
|
||||
];
|
||||
|
||||
YesNtAssert.ContainsTerminationMessage(lines, "No matching end_while found");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void EndWhileWithoutWhileFailsTest()
|
||||
{
|
||||
List<string> lines =
|
||||
[
|
||||
"end_while"
|
||||
];
|
||||
|
||||
YesNtAssert.ContainsTerminationMessage(lines, "No matching while found");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user