pocketlang/tests/lang/basics.pk

51 lines
1.1 KiB
Plaintext
Raw Normal View History

2021-05-24 06:17:52 +08:00
s = "foo"; s += "bar"
assert(s == "foobar")
assert( 1 + 2 * 3 == 7)
assert((1 + 2)* 3 == 9)
assert(42 % 40.0 == 2)
assert("'\"'" == '\'"\'')
assert("testing" == "test" + "ing")
## Lists test.
l1 = [1, false, null, func print('hello') end]
2021-05-24 06:17:52 +08:00
assert(is_null(l1[2]))
l1[1] = true; assert(l1[1])
## Builtin functions tests.
2021-05-24 06:17:52 +08:00
assert(to_string(42) == '42')
2021-05-22 21:27:40 +08:00
2021-05-24 06:17:52 +08:00
## Core module test.
import math
h1 = math.hash("testing"); h2 = math.hash("test" + "ing")
assert(h1 == h2)
assert(math.ceil(1.1) == math.floor(2.9))
2021-05-22 21:27:40 +08:00
## Logical statement test
val = 0; a = false; b = true
get_true = func return true end
if a and b then assert(false) end
if a or b then val = 42 else assert(false) end assert(val == 42)
if get_true() or false then val = 12 end assert(val == 12)
2021-05-24 06:17:52 +08:00
## Recursive to_string list/map
l = [1]
list_append(l, l)
assert(to_string(l) == '[1, [...]]')
m = {}
m['m'] = m
assert(to_string(m) == '{"m":{...}}')
# Bitwise operation tests
assert((1 | 1) == 1)
assert((1 | 4) == 5)
assert((3 | 5) == 7)
assert((1 & 1) == 1)
assert((1 & 2) == 0)
assert((4 & 7) == 4)
# If we got here with no errors, then all test passed
print('All tests PASSED (100%)')
2021-05-24 06:17:52 +08:00