added fragments
This commit is contained in:
+31
@@ -369,6 +369,37 @@ class PbsFrontendCompilerTest {
|
||||
i.kind() == p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.JMP_IF_FALSE));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldLowerForLoopIteratorBoundsAndStep() {
|
||||
final var source = """
|
||||
fn main() -> int {
|
||||
let total: int = 0;
|
||||
for i: int from 0 until 10 step 2 {
|
||||
total += i;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
""";
|
||||
|
||||
final var diagnostics = DiagnosticSink.empty();
|
||||
final var compiler = new PbsFrontendCompiler();
|
||||
final var fileBackend = compiler.compileFile(new FileId(102), source, diagnostics);
|
||||
|
||||
assertTrue(diagnostics.isEmpty(), diagnostics.stream().map(d -> d.getCode() + ":" + d.getMessage()).toList().toString());
|
||||
final var executableMain = fileBackend.executableFunctions().stream()
|
||||
.filter(fn -> fn.callableName().equals("main"))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
assertTrue(executableMain.instructions().stream().anyMatch(i ->
|
||||
i.kind() == p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.LT));
|
||||
assertTrue(executableMain.instructions().stream().anyMatch(i ->
|
||||
i.kind() == p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.ADD));
|
||||
assertTrue(executableMain.instructions().stream().anyMatch(i ->
|
||||
i.kind() == p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.SET_LOCAL));
|
||||
assertTrue(executableMain.instructions().stream().anyMatch(i ->
|
||||
i.kind() == p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.GET_LOCAL));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotLowerWhenSyntaxErrorsExist() {
|
||||
final var source = """
|
||||
|
||||
Reference in New Issue
Block a user