mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Added tables to integration tests, tweaked a lot of comments
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
//TODO: functions don't work yet
|
||||
|
||||
//example of the fibonacci sequence
|
||||
fn fib(n: int) {
|
||||
if (n < 2) return n;
|
||||
return fib(n-1) + fib(n-2);
|
||||
}
|
||||
|
||||
//NOTE: type coercion syntax hasn't been decided on yet
|
||||
//TODO: type coercion syntax hasn't been decided on yet, but it will be needed
|
||||
for (var i = 1; i <= 10; i++) {
|
||||
print i .. ":" .. fib(i);
|
||||
}
|
||||
|
||||
//Note to self: yes, the base case in 'fib()' is 'n < 2', stop second guessing yourself!
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//standard example
|
||||
//standard example, using 'while' instead of 'for', because it's not ready yet
|
||||
|
||||
var counter: int = 1;
|
||||
|
||||
while (counter <= 100) {
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
set breakpoint pending on
|
||||
|
||||
break toy_vm.c:547
|
||||
|
||||
command 1
|
||||
print opcode
|
||||
continue
|
||||
end
|
||||
|
||||
break toy_vm.c:373
|
||||
|
||||
command 2
|
||||
printf "JUMP %d %d %d\n", type, cond, param
|
||||
continue
|
||||
end
|
||||
|
||||
break toy_vm.c:375
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
//TODO: functions don't work yet
|
||||
|
||||
//find the leap years
|
||||
fn isLeapYear(n: int) {
|
||||
if (n % 400) return true;
|
||||
if (n % 100) return false;
|
||||
if (n % 400 == 0) return true;
|
||||
if (n % 100 == 0) return false;
|
||||
return n % 4 == 0;
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
{
|
||||
//if and while work together
|
||||
var count = 1;
|
||||
while (count <= 10) {
|
||||
if (count % 2 == 0) {
|
||||
print "even";
|
||||
}
|
||||
else {
|
||||
print "odd";
|
||||
}
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
//1-D table
|
||||
var a = ["alpha": 1, "beta": 2, "gamma": 3];
|
||||
a["beta"] = 6;
|
||||
|
||||
print a;
|
||||
assert a == ["alpha": 1, "beta": 6, "gamma": 3], "1-D tables failed";
|
||||
|
||||
//nested
|
||||
var b = [
|
||||
"outer": ["inner": true],
|
||||
"alpha": 1,
|
||||
"beta": 2,
|
||||
"gamma": 3
|
||||
];
|
||||
|
||||
print b;
|
||||
assert b == ["alpha": 1, "beta": 2, "gamma": 3, "outer": ["inner": true]], "nested tables failed";
|
||||
|
||||
//test empty tables
|
||||
var empty = [:];
|
||||
|
||||
print empty;
|
||||
assert empty == [:], "empty tables failed";
|
||||
|
||||
//test trailing commas
|
||||
var trailing = [
|
||||
"alpha":1,
|
||||
"beta":2,
|
||||
"gamma":3,
|
||||
];
|
||||
|
||||
print trailing;
|
||||
assert trailing == ["alpha": 1, "beta": 2, "gamma": 3], "trailing tables failed";
|
||||
@@ -1,12 +0,0 @@
|
||||
//test trailing commas
|
||||
var a = [1, 2, 3, ];
|
||||
|
||||
print a;
|
||||
|
||||
//test empty arrays
|
||||
var b = [];
|
||||
|
||||
print b;
|
||||
|
||||
|
||||
//TODO: prevent circular references
|
||||
@@ -1,5 +0,0 @@
|
||||
var barr = [
|
||||
[1, 2, 3],
|
||||
// [4, 5, 6],
|
||||
// [7, 8, 9]
|
||||
];
|
||||
Reference in New Issue
Block a user