luau/tests/conformance/userdata.lua
2023-09-01 09:38:53 -07:00

51 lines
1.4 KiB
Lua

-- This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
print('testing userdata')
-- int64 is a userdata type defined in C++
-- equality
assert(int64(1) == int64(1))
assert(int64(1) ~= int64(2))
-- relational
assert(not (int64(1) < int64(1)))
assert(int64(1) < int64(2))
assert(int64(1) <= int64(1))
assert(int64(1) <= int64(2))
-- arithmetics
assert(-int64(2) == int64(-2))
assert(int64(1) + int64(2) == int64(3))
assert(int64(1) - int64(2) == int64(-1))
assert(int64(2) * int64(3) == int64(6))
assert(int64(4) / int64(2) == int64(2))
assert(int64(4) % int64(3) == int64(1))
assert(int64(2) ^ int64(3) == int64(8))
assert(int64(1) + 2 == int64(3))
assert(int64(1) - 2 == int64(-1))
assert(int64(2) * 3 == int64(6))
assert(int64(4) / 2 == int64(2))
assert(int64(4) % 3 == int64(1))
assert(int64(2) ^ 3 == int64(8))
-- / and // round in different directions in our test implementation
assert(int64(5) / int64(2) == int64(2))
assert(int64(5) // int64(2) == int64(2))
assert(int64(-5) / int64(2) == int64(-2))
assert(int64(-5) // int64(2) == int64(-3))
-- tostring
assert(tostring(int64(2)) == "2")
-- index/newindex; note, mutable userdatas aren't very idiomatic but we need to test this
do
local v = int64(42)
assert(v.value == 42)
v.value = 4
assert(v.value == 4)
assert(v == int64(4))
end
return 'OK'