mirror of
https://github.com/CPunch/Cosmo.git
synced 2024-11-05 16:20:06 +00:00
CPunch
c8cae03604
- 'var' has some weird scoping connotations with users of JS. better to change it to 'let', which will decide whether to make the variable a local or a global - 'func' looks visually appealing lol - some minor refactoring done in cparse.c
45 lines
884 B
Plaintext
45 lines
884 B
Plaintext
/*
|
|
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.rep() 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
|
|
func __init(self, x)
|
|
self.max = x
|
|
end
|
|
|
|
func __iter(self)
|
|
self.i = 0
|
|
return self
|
|
end
|
|
|
|
func __next(self)
|
|
if self.i >= self.max then
|
|
return nil // exit iterator loop
|
|
end
|
|
|
|
return self.i++
|
|
end
|
|
end
|
|
|
|
let total = 0
|
|
for i in Range(100) do
|
|
total = total + i
|
|
end
|
|
|
|
assert(total == 4950, "Iterator check failed!")
|
|
|
|
print("Testsuite passed!") |