mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Fixed jumps in functions issue
This commit is contained in:
@@ -1,8 +1,19 @@
|
||||
fn capture(count: int) {
|
||||
print count;
|
||||
print capture;
|
||||
|
||||
if (count < 5) {
|
||||
return count;
|
||||
}
|
||||
|
||||
print count;
|
||||
print capture;
|
||||
|
||||
fn foo() {
|
||||
//
|
||||
count++;
|
||||
count++;
|
||||
|
||||
// return capture(count + 1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
foo();
|
||||
print capture(52);
|
||||
|
||||
87
scripts/test/jumps-in-functions.toy
Normal file
87
scripts/test/jumps-in-functions.toy
Normal file
@@ -0,0 +1,87 @@
|
||||
fn sanity() {
|
||||
//test true jump
|
||||
if (true) {
|
||||
assert true, "if-then failed (1)";
|
||||
}
|
||||
else {
|
||||
assert false, "if-then failed (2)";
|
||||
}
|
||||
|
||||
|
||||
//test false jump
|
||||
if (false) {
|
||||
assert false, "if-then failed (3)";
|
||||
}
|
||||
else {
|
||||
assert true, "if-then failed (4)";
|
||||
}
|
||||
|
||||
|
||||
//test while loop
|
||||
var whileCounter = 0;
|
||||
while (whileCounter < 10) {
|
||||
whileCounter = whileCounter + 1;
|
||||
}
|
||||
|
||||
assert whileCounter == 10, "while-loop failed";
|
||||
|
||||
|
||||
//test for loop
|
||||
var forCache = 0;
|
||||
for (var i = 0; i < 20; i++) {
|
||||
forCache = i;
|
||||
}
|
||||
|
||||
assert forCache == 19, "for-loop failed";
|
||||
|
||||
|
||||
//test break - while
|
||||
var breakWhileCache = 0;
|
||||
while(true) {
|
||||
breakWhileCache = breakWhileCache + 1;
|
||||
|
||||
if (breakWhileCache >= 7) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert breakWhileCache == 7, "break-while failed";
|
||||
|
||||
|
||||
//test continue - while
|
||||
var continueWhileCache = 0;
|
||||
while (continueWhileCache < 10) {
|
||||
continueWhileCache = continueWhileCache + 1;
|
||||
|
||||
if (continueWhileCache >= 7) {
|
||||
continue;
|
||||
}
|
||||
|
||||
assert continueWhileCache < 7, "continue-while failed";
|
||||
}
|
||||
|
||||
|
||||
//test break - for
|
||||
for (var i = 0; i < 10; i++) {
|
||||
if (i >= 7) {
|
||||
break;
|
||||
}
|
||||
|
||||
assert i < 7, "break-for failed";
|
||||
}
|
||||
|
||||
|
||||
//test break - continue
|
||||
for (var i = 0; i < 10; i++) {
|
||||
if (i >= 7) {
|
||||
continue;
|
||||
}
|
||||
|
||||
assert i < 7, "continue-for failed";
|
||||
}
|
||||
|
||||
print "All good";
|
||||
}
|
||||
|
||||
//invoke the test
|
||||
sanity();
|
||||
Reference in New Issue
Block a user