PageRenderTime 11ms CodeModel.GetById 2ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/test-suite/lua/template_default_arg_runme.lua

#
Lua | 63 lines | 41 code | 15 blank | 7 comment | 19 complexity | 311acc30ec7610ec44e5d0101cd3c476 MD5 | raw file
 1require("import")	-- the import fn
 2import("template_default_arg")	-- import code
 3--for k,v in pairs(template_default_arg) do _G[k]=v end -- move to global
 4
 5helloInt = template_default_arg.Hello_int()
 6helloInt:foo(template_default_arg.Hello_int_hi)
 7
 8x = template_default_arg.X_int()
 9assert(x:meth(20.0, 200) == 200,"X_int test 1 failed")
10assert(x:meth(20) == 20,"X_int test 2 failed")
11assert(x:meth() == 0,"X_int test 3 failed")
12
13y = template_default_arg.Y_unsigned()
14assert(y:meth(20.0, 200) == 200,"Y_unsigned test 1 failed")
15assert(y:meth(20) == 20,"Y_unsigned test 2 failed")
16assert(y:meth() == 0,"Y_unsigned test 3 failed")
17
18x = template_default_arg.X_longlong()
19x = template_default_arg.X_longlong(20.0)
20x = template_default_arg.X_longlong(20.0, 200) -- note: long longs just treated as another number
21
22x = template_default_arg.X_int()
23x = template_default_arg.X_int(20.0)
24x = template_default_arg.X_int(20.0, 200)
25
26x = template_default_arg.X_hello_unsigned()
27x = template_default_arg.X_hello_unsigned(20.0)
28x = template_default_arg.X_hello_unsigned(20.0, template_default_arg.Hello_int())
29
30y = template_default_arg.Y_hello_unsigned()
31y:meth(20.0, template_default_arg.Hello_int())
32y:meth(template_default_arg.Hello_int())
33y:meth()
34
35fz = template_default_arg.Foo_Z_8()
36x = template_default_arg.X_Foo_Z_8()
37fzc = x:meth(fz)
38
39-- Templated functions
40
41-- plain function: int ott(Foo<int>)
42assert(template_default_arg.ott(template_default_arg.Foo_int()) == 30,"ott test 1 failed")
43
44-- %template(ott) ott<int, int>
45assert(template_default_arg.ott() == 10,"ott test 2 failed")
46assert(template_default_arg.ott(1) == 10,"ott test 3 failed")
47assert(template_default_arg.ott(1, 1) == 10,"ott test 4 failed")
48
49assert(template_default_arg.ott("hi") == 20,"ott test 5 failed")
50assert(template_default_arg.ott("hi", 1) == 20,"ott test 6 failed")
51assert(template_default_arg.ott("hi", 1, 1) == 20,"ott test 7 failed")
52 
53-- %template(ott) ott<const char *>
54assert(template_default_arg.ottstring(template_default_arg.Hello_int(), "hi") == 40,"ott test 8 failed")
55assert(template_default_arg.ottstring(template_default_arg.Hello_int()) == 40,"ott test 9 failed")
56
57-- %template(ott) ott<int>
58assert(template_default_arg.ottint(template_default_arg.Hello_int(), 1) == 50,"ott test 10 failed")
59assert(template_default_arg.ottint(template_default_arg.Hello_int()) == 50,"ott test 11 failed")
60
61-- %template(ott) ott<double>
62assert(template_default_arg.ott(template_default_arg.Hello_int(), 1.0) == 60,"ott test 12 failed")
63assert(template_default_arg.ott(template_default_arg.Hello_int()) == 60,"ott test 13 failed")