X7ROOT File Manager
Current Path:
/opt/alt/tests/alt-php82-pecl-luasandbox_4.1.2-2.el8/tests
opt
/
alt
/
tests
/
alt-php82-pecl-luasandbox_4.1.2-2.el8
/
tests
/
ðŸ“
..
📄
LuaSandboxFunction_construct.phpt
(253 B)
📄
array-key-conversion.phpt
(3.11 KB)
📄
call.phpt
(5.1 KB)
📄
callback_exception.phpt
(392 B)
📄
datatypes-unsupported.phpt
(2.78 KB)
📄
datatypes.phpt
(2.43 KB)
📄
dump_loadBinary_call.phpt
(393 B)
📄
errors-at-call-boundaries.phpt
(1.98 KB)
📄
extending-LuaSandbox.phpt
(845 B)
📄
ipairs.phpt
(1.53 KB)
📄
loadString.phpt
(334 B)
📄
lua_catches_php_exception.phpt
(1.34 KB)
📄
pairs.phpt
(3.31 KB)
📄
pcall.phpt
(1.27 KB)
📄
profiler-sorting.phpt
(1.18 KB)
📄
profiler.phpt
(1.54 KB)
📄
reentrant.phpt
(1.1 KB)
📄
xpcall.phpt
(2.6 KB)
Editing: pairs.phpt
--TEST-- pairs() and __pairs --FILE-- <?php $lua = <<<LUA function pairs_test1() local t = { a = 1 } local f, s, var = pairs( t ) if type( f ) == 'function' and s == t and var == nil then local k, v = f(t, var) if k == 'a' and v == 1 then return "Ok" else return "Fail: First call returned " .. k .. "\\t" .. v end else return "Fail:\\n" .. tostring(f) .. '\\t' .. tostring(s) .. '\\t' .. tostring(var) .. '\\n' .. tostring(next) .. '\\t' .. tostring(t) .. '\\tnil' end end function pairs_test2() local t = { a = 1 } setmetatable( t, { __pairs = function () return 1, 2, 3 end } ) local f, s, var = pairs( t ) if f == 1 and s == 2 and var == 3 then return "Ok" else return "Fail:\\n" .. tostring(f) .. '\\t' .. tostring(s) .. '\\t' .. tostring(var) .. '\\n' .. '1\\t2\\t3' end end function pairs_test3() pairs() return "Fail: Should have thrown an error" end function pairs_return() local data = { a = 1, b = 2 } local t = {} setmetatable( t, { __pairs = function () return pairs( data ) end } ) return t end function pairs_error() local t = {} setmetatable( t, { __pairs = function () error( "Error from __pairs function" ) end } ) pairs( t ) return "Fail: Should have thrown an error" end function pairs_return_error() local t = {} setmetatable( t, { __pairs = function () error( "Error from __pairs function" ) end } ) return t end function pairs_next_error() local t = {} setmetatable( t, { __pairs = function () return function() error( "Error from next function" ) end end } ) for k, v in pairs( t ) do end return "Fail: Should have thrown an error" end function pairs_return_next_error() local t = {} setmetatable( t, { __pairs = function () return function() error( "Error from next function" ) end end } ) return t end LUA; $tests = array( 'Normal' => 'pairs_test1', 'With __pairs' => 'pairs_test2', 'No argument' => 'pairs_test3', 'With __pairs throwing an error' => 'pairs_error', 'With next func throwing an error' => 'pairs_next_error', 'Table with __pairs returned to PHP' => 'pairs_return', 'Table with __pairs throwing an error returned to PHP' => 'pairs_return_error', 'Table with next func throwing an error returned to PHP' => 'pairs_return_next_error', ); foreach ( $tests as $desc => $func ) { echo "$desc: "; $sandbox = new LuaSandbox; $sandbox->loadString( $lua )->call(); $sandbox->setCPULimit( 0.25 ); $sandbox->setMemoryLimit( 100000 ); try { print var_export( $sandbox->callFunction( $func ), 1 ) . "\n"; } catch ( LuaSandboxError $e ) { echo "LuaSandboxError: " . $e->getMessage() . "\n"; } } --EXPECT-- Normal: array ( 0 => 'Ok', ) With __pairs: array ( 0 => 'Ok', ) No argument: LuaSandboxError: [string ""]:32: bad argument #1 to 'pairs' (table expected, got no value) With __pairs throwing an error: LuaSandboxError: [string ""]:45: Error from __pairs function With next func throwing an error: LuaSandboxError: [string ""]:60: Error from next function Table with __pairs returned to PHP: array ( 0 => array ( 'a' => 1, 'b' => 2, ), ) Table with __pairs throwing an error returned to PHP: LuaSandboxError: [string ""]:52: Error from __pairs function Table with next func throwing an error returned to PHP: LuaSandboxError: [string ""]:71: Error from next function
Upload File
Create Folder