mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Fix conformance tests to work with 3 and 4 component vectors.
This commit is contained in:
parent
d9c0977734
commit
83e6a28d4c
2 changed files with 37 additions and 5 deletions
|
@ -64,7 +64,12 @@ static int lua_vector(lua_State* L)
|
|||
double y = luaL_checknumber(L, 2);
|
||||
double z = luaL_checknumber(L, 3);
|
||||
|
||||
#if LUA_VECTOR_SIZE == 4
|
||||
double w = luaL_optnumber(L, 4, 0.0);
|
||||
lua_pushvector(L, float(x), float(y), float(z), float(w));
|
||||
#else
|
||||
lua_pushvector(L, float(x), float(y), float(z));
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -366,11 +371,17 @@ TEST_CASE("Pack")
|
|||
|
||||
TEST_CASE("Vector")
|
||||
{
|
||||
ScopedFastFlag sff{"LuauIfElseExpressionBaseSupport", true};
|
||||
|
||||
runConformance("vector.lua", [](lua_State* L) {
|
||||
lua_pushcfunction(L, lua_vector);
|
||||
lua_setglobal(L, "vector");
|
||||
|
||||
#if LUA_VECTOR_SIZE == 4
|
||||
lua_pushvector(L, 0.0f, 0.0f, 0.0f, 0.0f);
|
||||
#else
|
||||
lua_pushvector(L, 0.0f, 0.0f, 0.0f);
|
||||
#endif
|
||||
luaL_newmetatable(L, "vector");
|
||||
|
||||
lua_pushstring(L, "__index");
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
-- This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
||||
print('testing vectors')
|
||||
|
||||
-- detect vector size
|
||||
local vector_size = if pcall(function() return vector(0, 0, 0).w end) then 4 else 3
|
||||
|
||||
-- equality
|
||||
assert(vector(1, 2, 3) == vector(1, 2, 3))
|
||||
assert(vector(0, 1, 2) == vector(-0, 1, 2))
|
||||
|
@ -13,8 +16,14 @@ assert(not rawequal(vector(1, 2, 3), vector(1, 2, 4)))
|
|||
|
||||
-- type & tostring
|
||||
assert(type(vector(1, 2, 3)) == "vector")
|
||||
assert(tostring(vector(1, 2, 3)) == "1, 2, 3")
|
||||
assert(tostring(vector(-1, 2, 0.5)) == "-1, 2, 0.5")
|
||||
|
||||
if vector_size == 4 then
|
||||
assert(tostring(vector(1, 2, 3, 4)) == "1, 2, 3, 4")
|
||||
assert(tostring(vector(-1, 2, 0.5, 0)) == "-1, 2, 0.5, 0")
|
||||
else
|
||||
assert(tostring(vector(1, 2, 3)) == "1, 2, 3")
|
||||
assert(tostring(vector(-1, 2, 0.5)) == "-1, 2, 0.5")
|
||||
end
|
||||
|
||||
local t = {}
|
||||
|
||||
|
@ -42,12 +51,19 @@ assert(8 * vector(8, 16, 24) == vector(64, 128, 192));
|
|||
assert(vector(1, 2, 4) * '8' == vector(8, 16, 32));
|
||||
assert('8' * vector(8, 16, 24) == vector(64, 128, 192));
|
||||
|
||||
assert(vector(1, 2, 4) / vector(8, 16, 24) == vector(1/8, 2/16, 4/24));
|
||||
if vector_size == 4 then
|
||||
assert(vector(1, 2, 4, 8) / vector(8, 16, 24, 32) == vector(1/8, 2/16, 4/24, 8/32));
|
||||
assert(8 / vector(8, 16, 24, 32) == vector(1, 1/2, 1/3, 1/4));
|
||||
assert('8' / vector(8, 16, 24, 32) == vector(1, 1/2, 1/3, 1/4));
|
||||
else
|
||||
assert(vector(1, 2, 4) / vector(8, 16, 24, 1) == vector(1/8, 2/16, 4/24));
|
||||
assert(8 / vector(8, 16, 24) == vector(1, 1/2, 1/3));
|
||||
assert('8' / vector(8, 16, 24) == vector(1, 1/2, 1/3));
|
||||
end
|
||||
|
||||
assert(vector(1, 2, 4) / 8 == vector(1/8, 1/4, 1/2));
|
||||
assert(vector(1, 2, 4) / (1 / val) == vector(1/8, 2/8, 4/8));
|
||||
assert(8 / vector(8, 16, 24) == vector(1, 1/2, 1/3));
|
||||
assert(vector(1, 2, 4) / '8' == vector(1/8, 1/4, 1/2));
|
||||
assert('8' / vector(8, 16, 24) == vector(1, 1/2, 1/3));
|
||||
|
||||
assert(-vector(1, 2, 4) == vector(-1, -2, -4));
|
||||
|
||||
|
@ -71,4 +87,9 @@ assert(pcall(function() local t = {} rawset(t, vector(0/0, 2, 3), 1) end) == fal
|
|||
-- make sure we cover both builtin and C impl
|
||||
assert(vector(1, 2, 4) == vector("1", "2", "4"))
|
||||
|
||||
-- additional checks for 4-component vectors
|
||||
if vector_size == 4 then
|
||||
assert(vector(1, 2, 3, 4).w == 4)
|
||||
end
|
||||
|
||||
return 'OK'
|
||||
|
|
Loading…
Add table
Reference in a new issue