More tests
This commit is contained in:
parent
dfc02f306d
commit
c9279ab0e7
16 changed files with 296 additions and 0 deletions
|
|
@ -31,6 +31,10 @@ struct sealed {int i;};
|
||||||
KW(go, defer)
|
KW(go, defer)
|
||||||
KW(chan, fallthrough)
|
KW(chan, fallthrough)
|
||||||
|
|
||||||
|
/* Lua keywords */
|
||||||
|
KW(end, function)
|
||||||
|
KW(nil,local)
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
17
Examples/test-suite/lua/grouping_runme.lua
Normal file
17
Examples/test-suite/lua/grouping_runme.lua
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
require("import") -- the import fn
|
||||||
|
import("grouping") -- import lib into global
|
||||||
|
g=grouping --alias
|
||||||
|
|
||||||
|
-- catching undefined variables
|
||||||
|
local env = _ENV -- Lua 5.2
|
||||||
|
if not env then env = getfenv () end -- Lua 5.1
|
||||||
|
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
|
||||||
|
|
||||||
|
assert( g.test1(5) == 5 )
|
||||||
|
g.test2(42) -- Return value is int* packed into userdata. We can't do anything with it
|
||||||
|
|
||||||
|
assert( g.test3 == 37 )
|
||||||
|
g.test3 = 42
|
||||||
|
assert( g.test3 == 42 )
|
||||||
|
|
||||||
|
assert( g.do_unary(5, g.NEGATE) == -5 )
|
||||||
17
Examples/test-suite/lua/iadd_runme.lua
Normal file
17
Examples/test-suite/lua/iadd_runme.lua
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
require("import") -- the import fn
|
||||||
|
import("iadd") -- import lib into global
|
||||||
|
i=iadd --alias
|
||||||
|
|
||||||
|
-- catching undefined variables
|
||||||
|
local env = _ENV -- Lua 5.2
|
||||||
|
if not env then env = getfenv () end -- Lua 5.1
|
||||||
|
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
|
||||||
|
|
||||||
|
foo1 = i.Foo()
|
||||||
|
foo1_a = foo1.AsA
|
||||||
|
assert( foo1_a.x == 5 )
|
||||||
|
assert( foo1_a:get_me().x == 5 )
|
||||||
|
-- Unfortunately, in Lua operator+= can't be overloaded
|
||||||
|
|
||||||
|
foo1.AsLong = 1000
|
||||||
|
assert( foo1.AsLong == 1000 )
|
||||||
16
Examples/test-suite/lua/keyword_rename_runme.lua
Normal file
16
Examples/test-suite/lua/keyword_rename_runme.lua
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
require("import") -- the import fn
|
||||||
|
import("keyword_rename") -- import lib into global
|
||||||
|
kn=keyword_rename--alias
|
||||||
|
|
||||||
|
-- catching undefined variables
|
||||||
|
local env = _ENV -- Lua 5.2
|
||||||
|
if not env then env = getfenv () end -- Lua 5.1
|
||||||
|
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
|
||||||
|
|
||||||
|
|
||||||
|
-- assert( kn.end(5) == 5 ) -- Curretly SWIG/Lua doesn't rename keywords
|
||||||
|
-- assert( kn.nil(7) == 7 )
|
||||||
|
|
||||||
|
-- But you can always access wrongly named members using string constants
|
||||||
|
assert( kn["end"](5) == 5 )
|
||||||
|
assert( kn["nil"](7) == 7 )
|
||||||
22
Examples/test-suite/lua/overload_complicated_runme.lua
Normal file
22
Examples/test-suite/lua/overload_complicated_runme.lua
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
require("import") -- the import fn
|
||||||
|
import("overload_complicated") -- import lib into global
|
||||||
|
oc=overload_complicated --alias
|
||||||
|
|
||||||
|
-- catching undefined variables
|
||||||
|
local env = _ENV -- Lua 5.2
|
||||||
|
if not env then env = getfenv () end -- Lua 5.1
|
||||||
|
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
|
||||||
|
|
||||||
|
assert( oc.foo(1,1,"test",1) == 15 )
|
||||||
|
|
||||||
|
p1 = oc.Pop(nil)
|
||||||
|
p1 = oc.Pop(nil,false)
|
||||||
|
|
||||||
|
assert( p1:hip(true) == 701 )
|
||||||
|
assert( p1:hip(nil) == 702 )
|
||||||
|
|
||||||
|
assert( p1:hop(true) == 801 )
|
||||||
|
assert( p1:hop(nil) == 805 )
|
||||||
|
|
||||||
|
assert( oc.muzak(true) == 3001 )
|
||||||
|
assert( oc.muzak(nil) == 3002 )
|
||||||
34
Examples/test-suite/lua/smart_pointer_extend_runme.lua
Normal file
34
Examples/test-suite/lua/smart_pointer_extend_runme.lua
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
require("import") -- the import fn
|
||||||
|
import("smart_pointer_extend") -- import lib into global
|
||||||
|
spe=smart_pointer_extend --alias
|
||||||
|
|
||||||
|
-- catching undefined variables
|
||||||
|
local env = _ENV -- Lua 5.2
|
||||||
|
if not env then env = getfenv () end -- Lua 5.1
|
||||||
|
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
|
||||||
|
|
||||||
|
assert( spe.CBase.hello() == 1 )
|
||||||
|
assert( spe.CBase.z == 1 )
|
||||||
|
|
||||||
|
base1 = spe.CBase()
|
||||||
|
base1.x = 7
|
||||||
|
|
||||||
|
p1 = spe.CPtr()
|
||||||
|
|
||||||
|
assert( spe.get_hello(p1) == 1 )
|
||||||
|
assert( p1:foo() == 1 )
|
||||||
|
assert( p1:bar() == 2 )
|
||||||
|
assert( p1:boo(5) == 5 )
|
||||||
|
|
||||||
|
foo = spe.Foo()
|
||||||
|
bar = spe.Bar(foo)
|
||||||
|
|
||||||
|
assert( bar:extension(5,7) == 5 )
|
||||||
|
assert( bar:extension(7) == 7 )
|
||||||
|
assert( bar:extension() == 1 )
|
||||||
|
|
||||||
|
dfoo = spe.DFoo()
|
||||||
|
dptr = spe.DPtrFoo(dfoo)
|
||||||
|
|
||||||
|
assert( dptr:Ext() == 2 )
|
||||||
|
assert( dptr:Ext(5) == 5 )
|
||||||
18
Examples/test-suite/lua/smart_pointer_inherit_runme.lua
Normal file
18
Examples/test-suite/lua/smart_pointer_inherit_runme.lua
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
require("import") -- the import fn
|
||||||
|
import("smart_pointer_inherit") -- import lib into global
|
||||||
|
spi=smart_pointer_inherit --alias
|
||||||
|
|
||||||
|
-- catching undefined variables
|
||||||
|
local env = _ENV -- Lua 5.2
|
||||||
|
if not env then env = getfenv () end -- Lua 5.1
|
||||||
|
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
|
||||||
|
|
||||||
|
der = spi.Derived(7)
|
||||||
|
|
||||||
|
ptr = spi.SmartDerived(der)
|
||||||
|
|
||||||
|
assert( ptr.val == 7 )
|
||||||
|
assert( ptr:value() == 7 )
|
||||||
|
assert( ptr:value2() == 7 )
|
||||||
|
assert( ptr:value3() == 7 )
|
||||||
|
assert( ptr:valuehide() == -1 )
|
||||||
23
Examples/test-suite/lua/smart_pointer_multi_runme.lua
Normal file
23
Examples/test-suite/lua/smart_pointer_multi_runme.lua
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
require("import") -- the import fn
|
||||||
|
import("smart_pointer_multi") -- import lib into global
|
||||||
|
spm=smart_pointer_multi --alias
|
||||||
|
|
||||||
|
-- catching undefined variables
|
||||||
|
local env = _ENV -- Lua 5.2
|
||||||
|
if not env then env = getfenv () end -- Lua 5.1
|
||||||
|
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
|
||||||
|
|
||||||
|
foo = spm.Foo()
|
||||||
|
foo.x = 5
|
||||||
|
assert( foo:getx() == 5 )
|
||||||
|
|
||||||
|
bar = spm.Bar(foo)
|
||||||
|
spam = spm.Spam(bar)
|
||||||
|
grok = spm.Grok(bar)
|
||||||
|
|
||||||
|
assert( bar:getx() == 5 )
|
||||||
|
assert( spam:getx() == 5 )
|
||||||
|
spam.x = 7
|
||||||
|
assert( grok:getx() == 7 )
|
||||||
|
grok.x = 10
|
||||||
|
assert( foo:getx() == 10 )
|
||||||
25
Examples/test-suite/lua/smart_pointer_not_runme.lua
Normal file
25
Examples/test-suite/lua/smart_pointer_not_runme.lua
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
require("import") -- the import fn
|
||||||
|
import("smart_pointer_not") -- import lib into global
|
||||||
|
spn=smart_pointer_not --alias
|
||||||
|
|
||||||
|
-- catching undefined variables
|
||||||
|
local env = _ENV -- Lua 5.2
|
||||||
|
if not env then env = getfenv () end -- Lua 5.1
|
||||||
|
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
|
||||||
|
|
||||||
|
|
||||||
|
foo = spn.Foo()
|
||||||
|
foo.x = 7
|
||||||
|
assert( foo:getx() == 7 )
|
||||||
|
|
||||||
|
bar = spn.Bar(foo)
|
||||||
|
success = pcall(bar.getx, bar) -- Bar is not a smart pointer. Call should fail
|
||||||
|
assert( not success )
|
||||||
|
|
||||||
|
spam = spn.Spam(foo)
|
||||||
|
success = pcall(spam.getx, spam) -- Spam is not a smart pointer. Call should fail
|
||||||
|
assert( not success )
|
||||||
|
|
||||||
|
grok = spn.Grok(foo)
|
||||||
|
success = pcall(grok.getx, grok) -- Spam is not a smart pointer. Call should fail
|
||||||
|
assert( not success )
|
||||||
18
Examples/test-suite/lua/smart_pointer_rename_runme.lua
Normal file
18
Examples/test-suite/lua/smart_pointer_rename_runme.lua
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
require("import") -- the import fn
|
||||||
|
import("smart_pointer_rename") -- import lib into global
|
||||||
|
spr=smart_pointer_rename --alias
|
||||||
|
|
||||||
|
-- catching undefined variables
|
||||||
|
local env = _ENV -- Lua 5.2
|
||||||
|
if not env then env = getfenv () end -- Lua 5.1
|
||||||
|
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
|
||||||
|
|
||||||
|
|
||||||
|
foo = spr.Foo()
|
||||||
|
assert( foo:ftest1(1) == 1 )
|
||||||
|
assert( foo:ftest2(1,2) == 2 )
|
||||||
|
|
||||||
|
bar = spr.Bar(foo)
|
||||||
|
assert( bar:test() == 3 )
|
||||||
|
assert( bar:ftest1(1) == 1 )
|
||||||
|
assert( bar:ftest2(1,2) == 2 )
|
||||||
22
Examples/test-suite/lua/smart_pointer_simple_runme.lua
Normal file
22
Examples/test-suite/lua/smart_pointer_simple_runme.lua
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
require("import") -- the import fn
|
||||||
|
import("smart_pointer_simple") -- import lib into global
|
||||||
|
sps=smart_pointer_simple --alias
|
||||||
|
|
||||||
|
-- catching undefined variables
|
||||||
|
local env = _ENV -- Lua 5.2
|
||||||
|
if not env then env = getfenv () end -- Lua 5.1
|
||||||
|
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
|
||||||
|
|
||||||
|
foo1 = sps.Foo()
|
||||||
|
foo1.x = 5
|
||||||
|
assert( foo1.x == 5 )
|
||||||
|
assert( foo1:getx() == 5 )
|
||||||
|
|
||||||
|
bar1 = sps.Bar(foo1)
|
||||||
|
bar1.x = 3
|
||||||
|
assert(bar1.x == 3)
|
||||||
|
assert(bar1:getx() == 3)
|
||||||
|
|
||||||
|
bar1.x = 5
|
||||||
|
assert(bar1.x == 5)
|
||||||
|
assert(bar1:getx() == 5)
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
require("import") -- the import fn
|
||||||
|
import("smart_pointer_templatemethods") -- import lib into global
|
||||||
|
spt=smart_pointer_templatemethods --alias
|
||||||
|
|
||||||
|
-- catching undefined variables
|
||||||
|
local env = _ENV -- Lua 5.2
|
||||||
|
if not env then env = getfenv () end -- Lua 5.1
|
||||||
|
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
|
||||||
|
|
||||||
|
o1 = spt.Objct()
|
||||||
|
|
||||||
|
iid = spt.InterfaceId()
|
||||||
|
|
||||||
|
po2 = o1:QueryInterfaceObjct(iid)
|
||||||
|
-- we can't call po2:DisposeObjct, because smart pointer Ptr<T> always return 0 when dereferencing
|
||||||
|
-- (see interface file). So we only check that po2 has necessary method
|
||||||
|
assert( po2.DisposeObjct ~= nil )
|
||||||
|
assert( po2.QueryInterfaceObjct ~= nil )
|
||||||
10
Examples/test-suite/lua/template_construct_runme.lua
Normal file
10
Examples/test-suite/lua/template_construct_runme.lua
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
require("import") -- the import fn
|
||||||
|
import("template_construct") -- import lib into global
|
||||||
|
tc=template_construct --alias
|
||||||
|
|
||||||
|
-- catching undefined variables
|
||||||
|
local env = _ENV -- Lua 5.2
|
||||||
|
if not env then env = getfenv () end -- Lua 5.1
|
||||||
|
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
|
||||||
|
|
||||||
|
foo = tc.Foo_int(1)
|
||||||
14
Examples/test-suite/lua/template_extend1_runme.lua
Normal file
14
Examples/test-suite/lua/template_extend1_runme.lua
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
require("import") -- the import fn
|
||||||
|
import("template_extend1") -- import lib into global
|
||||||
|
te=template_extend1 --alias
|
||||||
|
|
||||||
|
-- catching undefined variables
|
||||||
|
local env = _ENV -- Lua 5.2
|
||||||
|
if not env then env = getfenv () end -- Lua 5.1
|
||||||
|
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
|
||||||
|
|
||||||
|
lb = te.lBaz()
|
||||||
|
assert( lb:foo() == "lBaz::foo" )
|
||||||
|
|
||||||
|
db = te.dBaz()
|
||||||
|
assert( db:foo() == "dBaz::foo" )
|
||||||
14
Examples/test-suite/lua/template_extend2_runme.lua
Normal file
14
Examples/test-suite/lua/template_extend2_runme.lua
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
require("import") -- the import fn
|
||||||
|
import("template_extend2") -- import lib into global
|
||||||
|
te=template_extend2 --alias
|
||||||
|
|
||||||
|
-- catching undefined variables
|
||||||
|
local env = _ENV -- Lua 5.2
|
||||||
|
if not env then env = getfenv () end -- Lua 5.1
|
||||||
|
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
|
||||||
|
|
||||||
|
lb = te.lBaz()
|
||||||
|
assert( lb:foo() == "lBaz::foo" )
|
||||||
|
|
||||||
|
db = te.dBaz()
|
||||||
|
assert( db:foo() == "dBaz::foo" )
|
||||||
24
Examples/test-suite/lua/template_inherit_runme.lua
Normal file
24
Examples/test-suite/lua/template_inherit_runme.lua
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
require("import") -- the import fn
|
||||||
|
import("template_inherit") -- import lib into global
|
||||||
|
ti=template_inherit --alias
|
||||||
|
|
||||||
|
-- catching undefined variables
|
||||||
|
local env = _ENV -- Lua 5.2
|
||||||
|
if not env then env = getfenv () end -- Lua 5.1
|
||||||
|
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
|
||||||
|
|
||||||
|
|
||||||
|
fi = ti.FooInt()
|
||||||
|
assert( fi:blah() == "Foo" )
|
||||||
|
assert( fi:foomethod() == "foomethod" )
|
||||||
|
|
||||||
|
bi = ti.BarInt()
|
||||||
|
assert( bi:blah() == "Bar" )
|
||||||
|
assert( bi:foomethod() == "foomethod" )
|
||||||
|
|
||||||
|
assert( ti.invoke_blah_int(fi) == "Foo" )
|
||||||
|
assert( ti.invoke_blah_int(bi) == "Bar" )
|
||||||
|
|
||||||
|
bd = ti.BarDouble()
|
||||||
|
success = pcall( ti.invoke_blah_int, bd )
|
||||||
|
assert( not success )
|
||||||
Loading…
Add table
Add a link
Reference in a new issue