This commit is contained in:
shadowscion 2022-07-19 13:19:28 -05:00
parent 64cb23da4b
commit 3d12a2ff31
2 changed files with 94 additions and 3 deletions

View File

@ -232,7 +232,7 @@ do
@RETURN:
either a function or a coroutine that will build the mesh
--]]
function addon.construct.generate( construct, name, param, threaded, physics )
function addon.construct.generate( construct, param, threaded, physics )
if SERVER then threaded = nil end
-- Non-existant construct, error model CODE 1
@ -240,7 +240,8 @@ do
return true, errorModel( 1, name )
end
name = construct.data.name or "NO_NAME"
construct.data.name = construct.data.name or "NO_NAME"
local name = construct.data.name
-- Expected yield: true, true, table
if threaded and construct.data.canThread then
@ -269,7 +270,7 @@ do
either a function or a coroutine that will build the mesh
--]]
function addon.construct.get( name, param, threaded, physics )
return addon.construct.generate( construct_types[name], name, param, threaded, physics )
return addon.construct.generate( construct_types[name], param, threaded, physics )
end
end

View File

@ -0,0 +1,90 @@
return {
groupName = "construct",
cases = {
{
name = "Should return a valid (error model) construct if invalid parameters are given",
func = function()
local succ, result = Primitive.construct.get( "i_do_not_exist" )
expect( succ ).to.beTrue()
expect( result ).to.beA( "table" )
expect( result.error ).to.exist()
expect( result.error ).to.beA( "table" )
expect( result.convexes ).to.exist()
expect( result.convexes ).to.beA( "table" )
expect( table.IsSequential( result.convexes ) ).to.beTrue()
end
},
{
name = "Should return a valid (error model) construct if invalid return from factory function",
func = function()
local fake = {
data = { name = "fake_name_for_test" },
factory = function( param, data, threaded, physics )
local model = {}
return model
end,
}
local succ, result = Primitive.construct.generate( fake, {}, false, true )
expect( succ ).to.beTrue()
expect( result ).to.beA( "table" )
expect( result.error ).to.exist()
expect( result.error ).to.beA( "table" )
expect( result.convexes ).to.exist()
expect( result.convexes ).to.beA( "table" )
expect( table.IsSequential( result.convexes ) ).to.beTrue()
end
},
{
name = "Should return a valid (error model) construct if error in factory function",
func = function()
local fake = {
data = { name = "fake_name_for_test" },
factory = function( param, data, threaded, physics )
local model = {}
error( "test_fake_error" )
return model
end,
}
local succ, result = Primitive.construct.generate( fake, {}, false, true )
expect( succ ).to.beTrue()
expect( result ).to.beA( "table" )
expect( result.error ).to.exist()
expect( result.error ).to.beA( "table" )
expect( result.convexes ).to.exist()
expect( result.convexes ).to.beA( "table" )
expect( table.IsSequential( result.convexes ) ).to.beTrue()
end
},
}
}