mirror of
https://github.com/zekexiao/pocketlang.git
synced 2025-02-06 12:46:53 +08:00
51 lines
1.1 KiB
Plaintext
51 lines
1.1 KiB
Plaintext
|
|
## TODO: this dummy module is just to test different aspects of the
|
|
## native module interface and will be removed once it become stable
|
|
## and we have enough tests on other native interfaces.
|
|
|
|
import dummy
|
|
from dummy import Dummy
|
|
|
|
d = Dummy(0)
|
|
print(d)
|
|
|
|
assert(d.val == 0) ## @getter
|
|
d.val = 3.14 ## @setter
|
|
assert(d.val == 3.14)
|
|
|
|
assert(d == 3.14) ## == overload
|
|
assert(d > 3) ## > overload
|
|
assert(d >= 3) ## > overload
|
|
assert(d >= 3.14) ## > and == overload
|
|
|
|
assert(d.a_method(12, 34) == 408) ## method
|
|
|
|
d1 = Dummy(12)
|
|
d2 = Dummy(23)
|
|
d3 = d1 + d2
|
|
assert(d3 is Dummy)
|
|
assert(d3.val == d1.val + d2.val)
|
|
|
|
assert(dummy.afunc("foo", "bar") == "barfoo")
|
|
|
|
## Test pkCallFunction()
|
|
bar = dummy.call_native fn (a1, a2, a3)
|
|
print('a1 = $a1, a2 = $a2, a3 = $a3')
|
|
return "bar"
|
|
end
|
|
assert(bar == "bar")
|
|
|
|
## Test pkCallMethod()
|
|
class A
|
|
def do_something(a1, a2)
|
|
return [a2, a1]
|
|
end
|
|
end
|
|
inst = A()
|
|
a1 = 1..2; a2 = 34
|
|
ret = dummy.call_method(inst, 'do_something', a1, a2)
|
|
assert(ret == [a2, a1])
|
|
|
|
# If we got here, that means all test were passed.
|
|
print('All TESTS PASSED')
|