mirror of
https://github.com/Stone-Red-Code/YesNt-Interpreter.git
synced 2026-09-09 23:43:16 +02:00
Add support for block-style if/else and while loop statements with tests
This commit is contained in:
@@ -34,4 +34,106 @@ public class CodeFlowTests
|
||||
];
|
||||
YesNtAssert.IsLastLineEqual(lines, "1");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IfBlockTrueTest()
|
||||
{
|
||||
List<string> lines =
|
||||
[
|
||||
"let result = low",
|
||||
"if 6 > 5:",
|
||||
"let result = high",
|
||||
"end_if",
|
||||
"${result}"
|
||||
];
|
||||
|
||||
YesNtAssert.IsLastLineEqual(lines, "high");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IfElseFalseBranchTest()
|
||||
{
|
||||
List<string> lines =
|
||||
[
|
||||
"let result = low",
|
||||
"if 6 < 5:",
|
||||
"let result = high",
|
||||
"else:",
|
||||
"let result = medium",
|
||||
"end_if",
|
||||
"${result}"
|
||||
];
|
||||
|
||||
YesNtAssert.IsLastLineEqual(lines, "medium");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void NestedIfElseTest()
|
||||
{
|
||||
List<string> lines =
|
||||
[
|
||||
"let result = 0",
|
||||
"if 1 == 1:",
|
||||
"if 2 == 3:",
|
||||
"let result = 1",
|
||||
"else:",
|
||||
"let result = 2",
|
||||
"end_if",
|
||||
"end_if",
|
||||
"${result}"
|
||||
];
|
||||
|
||||
YesNtAssert.IsLastLineEqual(lines, "2");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WhileLoopTest()
|
||||
{
|
||||
List<string> lines =
|
||||
[
|
||||
"let i = 3",
|
||||
"while ${i} > 0:",
|
||||
"let i = ${i} - 1 calc",
|
||||
"end_while",
|
||||
"${i}"
|
||||
];
|
||||
|
||||
YesNtAssert.IsLastLineEqual(lines, "0");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WhileSkipBodyWhenFalseTest()
|
||||
{
|
||||
List<string> lines =
|
||||
[
|
||||
"let i = 0",
|
||||
"while ${i} > 0:",
|
||||
"let i = 99",
|
||||
"end_while",
|
||||
"${i}"
|
||||
];
|
||||
|
||||
YesNtAssert.IsLastLineEqual(lines, "0");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void NestedWhileLoopTest()
|
||||
{
|
||||
List<string> lines =
|
||||
[
|
||||
"let outer = 2",
|
||||
"let count = 0",
|
||||
"while ${outer} > 0:",
|
||||
"let inner = 2",
|
||||
"while ${inner} > 0:",
|
||||
"let count = ${count} + 1 calc",
|
||||
"let inner = ${inner} - 1 calc",
|
||||
"end_while",
|
||||
"let outer = ${outer} - 1 calc",
|
||||
"end_while",
|
||||
"${count}"
|
||||
];
|
||||
|
||||
YesNtAssert.IsLastLineEqual(lines, "4");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user