Added minimal testsuite for IC

- main.c will now report errors for passed scripts
This commit is contained in:
2021-03-19 22:23:04 -05:00
parent 471589d379
commit 1813bbeb1b
2 changed files with 57 additions and 4 deletions

45
examples/testsuite.cosmo Normal file
View File

@@ -0,0 +1,45 @@
/*
This script tests cosmo and makes sure everything still runs correctly. Pretty minimal for now
*/
print("starting Testsuite...")
// tests the string.* library
assert("Hello world!":sub(6) == "world!", "string.sub() failed!")
assert("A":rep(6) == "AAAAAA", "string.red() failed!")
// tests some basic PEMDAS arithmetic
assert(2 * (2 + 6) == 16, "PEMDAS check #1 failed!")
assert(2 / 5 + 3 / 5 == 1, "PEMDAS check #2 failed!")
// iterator test
proto Range
function __init(self, x)
self.max = x
end
function __iter(self)
self.i = 0
return self
end
function __next(self)
if self.i >= self.max then
return nil // exit iterator loop
end
return self.i++
end
end
var total = 0
for i in Range(100) do
total = total + i
end
assert(total == 4950, "Iterator check failed!")
print("Testsuite passed!")