fix: break and continue

This commit is contained in:
Matthieu Bessat 2022-05-15 23:00:16 +02:00
parent c3af6bd5ca
commit bcaf2cb3b7
4 changed files with 135 additions and 83 deletions

View file

@ -115,4 +115,38 @@ void test_line_processing()
assert(!state2->skipping);
printf("got i: %d \n", var_store_get_int(state2->varStore, "i"));
assert(9 == var_store_get_int(state2->varStore, "i"));
// test break keyword
char* lines5 = "set i to 0\n"
"while 1 do\n"
" if (i = 10) then\n"
" break\n"
" end\n"
" set i to i+1\n"
"end\n";
process_script(state2, lines5);
assert(!state2->skipping);
printf("got i: %d \n", var_store_get_int(state2->varStore, "i"));
assert(10 == var_store_get_int(state2->varStore, "i"));
// test continue keyword
char* lines6 = "set sum to 0\n"
"set i to 0\n"
"while 1 do\n"
" if (i = 5) then\n"
" set i to i+1\n"
" continue\n"
" end\n"
" if (i = 10) then\n"
" break\n"
" end\n"
" set sum to sum+1\n"
" set i to i+1\n"
"end\n";
process_script(state2, lines6);
assert(!state2->skipping);
assert(10 == var_store_get_int(state2->varStore, "i"));
assert(9 == var_store_get_int(state2->varStore, "sum"));
}