2012-12-19 20:10:01 +00:00
|
|
|
local testframework = require( 'Module:TestFramework' )
|
2012-04-19 07:40:56 +00:00
|
|
|
|
2012-12-19 20:10:01 +00:00
|
|
|
local function setfenv1()
|
|
|
|
local ok, err = pcall( function()
|
|
|
|
setfenv( 2, {} )
|
|
|
|
end )
|
|
|
|
if not ok then
|
|
|
|
err = string.gsub( err, '^%S+:%d+: ', '' )
|
|
|
|
error( err )
|
|
|
|
end
|
2012-04-19 07:40:56 +00:00
|
|
|
end
|
|
|
|
|
2012-12-19 20:10:01 +00:00
|
|
|
local function getfenv1()
|
|
|
|
local env
|
|
|
|
pcall( function()
|
|
|
|
env = getfenv( 2 )
|
|
|
|
end )
|
|
|
|
return env
|
2012-04-19 07:40:56 +00:00
|
|
|
end
|
|
|
|
|
2012-12-19 20:10:01 +00:00
|
|
|
return testframework.getTestProvider( {
|
|
|
|
{ name = 'setfenv on a C function', func = setfenv1,
|
2020-10-23 15:39:12 +00:00
|
|
|
expect = "'setfenv' cannot set the requested environment, it is protected",
|
2012-12-19 20:10:01 +00:00
|
|
|
},
|
|
|
|
{ name = 'getfenv on a C function', func = getfenv1,
|
2020-10-23 15:39:12 +00:00
|
|
|
expect = { nil },
|
2012-12-19 20:10:01 +00:00
|
|
|
},
|
2013-09-24 19:07:54 +00:00
|
|
|
{ name = 'Invalid array key (table)', func = mw.var_export,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { { [{}] = 1 } },
|
|
|
|
expect = 'Cannot use table as an array key when passing data from Lua to PHP',
|
2013-09-24 19:07:54 +00:00
|
|
|
},
|
|
|
|
{ name = 'Invalid array key (boolean)', func = mw.var_export,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { { [true] = 1 } },
|
|
|
|
expect = 'Cannot use boolean as an array key when passing data from Lua to PHP',
|
2013-09-24 19:07:54 +00:00
|
|
|
},
|
|
|
|
{ name = 'Invalid array key (function)', func = mw.var_export,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { { [tostring] = 1 } },
|
|
|
|
expect = 'Cannot use function as an array key when passing data from Lua to PHP',
|
2013-09-24 19:07:54 +00:00
|
|
|
},
|
|
|
|
{ name = 'Unusual array key (float)', func = mw.var_export,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { { [1.5] = 1 } },
|
|
|
|
expect = { "array ( '1.5' => 1, )" }
|
2013-09-24 19:07:54 +00:00
|
|
|
},
|
|
|
|
{ name = 'Unusual array key (inf)', func = mw.var_export,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { { [math.huge] = 1 } },
|
|
|
|
expect = { "array ( 'inf' => 1, )" }
|
2013-09-24 19:07:54 +00:00
|
|
|
},
|
2018-02-06 21:03:11 +00:00
|
|
|
{ name = 'Unusual array key ("00")', func = mw.var_export,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { { ["00"] = "zero zero" } },
|
|
|
|
expect = { "array ( '00' => 'zero zero', )" }
|
2018-02-06 21:03:11 +00:00
|
|
|
},
|
|
|
|
{ name = 'Unusual array key ("0.0")', func = mw.var_export,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { { ["0.0"] = "zero . zero" } },
|
|
|
|
expect = { "array ( '0.0' => 'zero . zero', )" }
|
2018-02-06 21:03:11 +00:00
|
|
|
},
|
|
|
|
{ name = 'Unusual array key ("01")', func = mw.var_export,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { { ["01"] = "zero one" } },
|
|
|
|
expect = { "array ( '01' => 'zero one', )" }
|
2018-02-06 21:03:11 +00:00
|
|
|
},
|
|
|
|
{ name = 'Unusual array key ("-9223372036854775808")', func = mw.var_export,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { { ["-9223372036854775808"] = "min" } },
|
|
|
|
expect = { "array ( -9223372036854775808 => 'min', )" }
|
2018-02-06 21:03:11 +00:00
|
|
|
},
|
|
|
|
{ name = 'Unusual array key (-9223372036854775808)', func = mw.var_export,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { { [-9223372036854775808] = "min" } },
|
|
|
|
expect = { "array ( -9223372036854775808 => 'min', )" }
|
2018-02-06 21:03:11 +00:00
|
|
|
},
|
|
|
|
{ name = 'Unusual array key ("-9223372036854775809")', func = mw.var_export,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { { ["-9223372036854775809"] = "min - 1" } },
|
|
|
|
expect = { "array ( '-9223372036854775809' => 'min - 1', )" }
|
2018-02-06 21:03:11 +00:00
|
|
|
},
|
2012-12-19 20:10:01 +00:00
|
|
|
} )
|