mirror of
https://github.com/zekexiao/pocketlang.git
synced 2025-02-06 12:46:53 +08:00
2707c1eec3
* Fix #54: Add bitwise OR operator and make it available in PKVM Like the bitwise AND, this is an implementation for pocketlang to support the bitwise OR operation. In addition, updated "value" -> "result" in other operation to correctly reflect the container's purpose. It's indeed the result after the operation, which is a value too. In addition, add tests for bitwise AND (&) and bitwise OR (|). Add a print statement in test file with message that all tests passed with no errors. * Fix typo in comment * Cleanup fixes
51 lines
1.1 KiB
Plaintext
51 lines
1.1 KiB
Plaintext
|
|
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]
|
|
assert(is_null(l1[2]))
|
|
l1[1] = true; assert(l1[1])
|
|
|
|
## Builtin functions tests.
|
|
assert(to_string(42) == '42')
|
|
|
|
## 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))
|
|
|
|
## 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)
|
|
|
|
## 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%)')
|
|
|