Implement string.dump

This commit is contained in:
James Roseborough
2008-07-22 22:32:28 +00:00
parent 89c38d00cc
commit ef48f8cd12
6 changed files with 113 additions and 45 deletions

View File

@@ -1,7 +1,6 @@
package.path = "?.lua;src/test/errors/?.lua"
require 'args'
-- arg types for basic library functions
-- assert
@@ -17,7 +16,8 @@ checkallerrors('collectgarbage',{notanil},'bad argument #1')
-- dofile
banner('dofile')
checkallpass('dofile', {{nil,'src/test/errors/args.lua'}})
checkallpass('dofile', {})
checkallpass('dofile', {{'src/test/errors/args.lua'}})
checkallerrors('dofile', {{'args.lua'}}, 'cannot open args.lua')
checkallerrors('dofile', {nonstring}, 'bad argument #1')
@@ -50,11 +50,17 @@ checkallerrors('load', {somefunction,{afunction,atable}}, 'bad argument #2')
-- loadfile
banner('loadfile')
checkallpass('loadfile', {})
checkallpass('loadfile', {{'bogus'}})
checkallpass('loadfile', {{'src/test/errors/args.lua'}})
checkallpass('loadfile', {{'args.lua'}})
checkallerrors('loadfile', {nonstring}, 'bad argument #1')
-- loadstring
banner('loadstring')
checkallpass('loadstring', {{'return'},{nil,astring}})
checkallpass('loadstring', {{'return'}})
checkallpass('loadstring', {{'return'},{'mychunk'}})
checkallpass('loadstring', {{'return a ... b'},{'mychunk'}})
checkallerrors('loadstring', {{'return a ... b'},{'mychunk'}},'hello')
checkallerrors('loadstring', {notastring,{nil,astring,anumber}}, 'bad argument #1')
checkallerrors('loadstring', {{'return'},{afunction,atable}}, 'bad argument #2')

View File

@@ -5,13 +5,13 @@ require 'args'
-- require
banner('require')
checkallpass('require',{{'math'}})
checkallpass('require',{{'math','coroutine','package','string','table'}},true)
checkallerrors('require',{{anumber}},'not found')
checkallerrors('require',{{anil,aboolean,afunction,atable}},'bad argument')
-- package.loadlib
banner('package.loadlib')
checkallpass('package.loadlib',{{'foo'},{'bar'}})
checkallpass('package.loadlib',{{'foo'},{'bar'}},true)
checkallerrors('package.loadlib',{notastring},'bad argument')
-- package.seeall
@@ -20,11 +20,30 @@ checkallpass('package.seeall',{sometable})
checkallerrors('package.seeall',{notatable},'bad argument')
-- module (last because it pretty much breaks this chunk)
-- module tests - require special rigging
banner('module')
print( pcall( function()
banner('module')
checkallpass('module',{somenumber,{package.seeall},{nil,afunction}})
checkallerrors('module',{{aboolean,atable,afunction}},'bad argument')
checkallerrors('module',{{aboolean,atable,afunction},{package.seeall}},'bad argument')
checkallerrors('module',{somestring,{astring,anumber,aboolean,atable}},'attempt to call a')
checkallpass('module',{{20001}})
end ) )
print( pcall( function()
checkallpass('module',{{20002},{package.seeall}})
end ) )
print( pcall( function()
checkallpass('module',{{20003},{package.seeall},{function() end}})
end ) )
print( pcall( function()
checkallerrors('module',{{aboolean,atable,function() end}},'bad argument')
checkallerrors('module',{{aboolean,atable,function() end},{package.seeall}},'bad argument')
end ) )
print( pcall( function()
checkallerrors('module',{{'testmodule1'},{'pqrs'}},'attempt to call')
end ) )
print( pcall( function()
checkallerrors('module',{{'testmodule2'},{aboolean}},'attempt to call')
end ) )
print( pcall( function()
checkallerrors('module',{{'testmodule3'},{athread}},'attempt to call')
end ) )
print( pcall( function()
checkallerrors('module',{{'testmodule4'},{atable}},'attempt to call')
end ) )

View File

@@ -12,17 +12,27 @@ checkallerrors('string.byte',{somestring,{astring,afunction,atable}},'bad argume
checkallerrors('string.byte',{notastring,{nil,111}},'bad argument')
-- string.char
banner('string.char')
checkallpass('string.char',{{nil,0,1,40,127,128,255,'0','1','255','1.2',1.2}})
checkallpass('string.char',{{0,127,255},{0,127,255}})
checkallpass('string.char',{})
checkallerrors('string.char',{{-1,256}},'bad argument #1')
checkallerrors('string.char',{notanumber,{23,'45',6.7}},'bad argument #1')
checkallerrors('string.char',{{23,'45',6.7},nonnumber},'bad argument #2')
function string_char(...)
return string.byte( string.char( ... ) )
end
banner('string_char')
checkallpass('string.char',{{60}})
checkallpass('string.char',{{60},{70}})
checkallpass('string.char',{{60},{70},{80}})
checkallpass('string_char',{{nil,0,9,40,127,128,255,'0','9','255','9.2',9.2}})
checkallpass('string_char',{{0,127,255},{0,127,255}})
checkallpass('string_char',{})
checkallerrors('string_char',{},'bad argument #1')
checkallerrors('string_char',{{-1,256}},'bad argument #1')
checkallerrors('string_char',{notanumber,{23,'45',6.7}},'bad argument #1')
checkallerrors('string_char',{{23,'45',6.7},nonnumber},'bad argument #2')
-- string.dump
banner('string.dump')
checkallpass('string.dump',{{afunction}})
local someupval = 435
local function funcwithupvals() return someupval end
checkallpass('string.dump',{{function() return 123 end}})
checkallpass('string.dump',{{funcwithupvals}})
checkallerrors('string.dump',{notafunction},'bad argument')
-- string.find

View File

@@ -27,11 +27,7 @@ public class ScriptDrivenTest extends TestCase {
InterruptedException {
// set platform relative to directory
Platform.setInstance(new J2sePlatform() {
public InputStream openFile(String fileName) {
return super.openFile(basedir+"/"+fileName);
}
});
Platform.setInstance(new J2sePlatform());
// new lua state
LuaState state = Platform.newLuaState();