pocketlang/tests/lang/builtin_ty.pk
Thakee Nathees f5e2f15d23 negative index, range slice and more
... string concat with .. operator
    exponent operator with ** operator
2022-05-08 23:19:33 +05:30

54 lines
1.2 KiB
Plaintext

## Builtin types attributes and methods tests.
###############################################################################
## INTEGER
###############################################################################
sum = 0
5.times fn(i)
sum += i
end
assert(sum == 0 + 1 + 2 + 3 + 4)
###############################################################################
## STRING
###############################################################################
s = "foobar"
assert(s[-3] == 'b')
assert("foo" .. 42 == "foo42")
assert("" .. 1 .. 2 .. 3 == "123")
assert("abcd"[1..1] == "b")
assert("abcd"[-1..0] == "dcba")
assert("abcd"[-3..3] == "bcd")
assert("abcd"[-1..-3] == "dcb")
assert(""[0..-1] == "")
assert(""[-1..0] == "")
###############################################################################
## LIST
###############################################################################
l = [1, 2, 3, 4]
assert (l[2] == 3)
assert (l[-1] == 4)
l[-2] = 42
assert (l[2] == 42)
l = [1, 2, 3, 4]
assert(l[1..1] == [2])
assert(l[-1..0] == [4, 3, 2, 1])
assert(l[-3..3] == [2, 3, 4])
assert(l[-1..-3] == [4, 3, 2])
assert([][0..0] == [])
assert([][-1..-1] == [])
## If we got here, that means all test were passed.
print('All TESTS PASSED')