mirror of
https://github.com/zekexiao/pocketlang.git
synced 2025-02-06 12:46:53 +08:00
58 lines
1.4 KiB
Plaintext
58 lines
1.4 KiB
Plaintext
|
|
## Builtin types attributes and methods tests.
|
|
|
|
###############################################################################
|
|
## Number
|
|
###############################################################################
|
|
|
|
sum = 0
|
|
5.times fn(i)
|
|
sum += i
|
|
end
|
|
assert(sum == 0 + 1 + 2 + 3 + 4)
|
|
|
|
assert(Number("-.23e+6") == -.23e6)
|
|
assert(Number("0b10100101") == 0b10100101)
|
|
assert(Number("-0Xabcdef123") == -0xabcdef123)
|
|
|
|
###############################################################################
|
|
## 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')
|