PageRenderTime 30ms CodeModel.GetById 14ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Lua | 81 lines | 47 code | 16 blank | 18 comment | 38 complexity | a480f39f10d7bd7394d59ecaf9cd514c MD5 | raw file
 1require("import")	-- the import fn
 2import("overload_template_fast")	-- import code
 3for k,v in pairs(overload_template_fast) do _G[k]=v end -- move to global
 4
 5-- lua has only one numeric type, so maximum(int,int) and maximum(double,double) are the same
 6-- whichever one was wrapper first will be used (which is int)
 7
 8f = foo()
 9
10a = maximum(3,4)
11
12-- mix 1
13assert(mix1("hi") == 101)
14assert(mix1(1.0, 1.0) == 102)
15assert(mix1(1.0) == 103)
16
17-- mix 2
18assert(mix2("hi") == 101)
19assert(mix2(1.0, 1.0) == 102)
20assert(mix2(1.0) == 103)
21
22-- mix 3
23assert(mix3("hi") == 101)
24assert(mix3(1.0, 1.0) == 102)
25assert(mix3(1.0) == 103)
26
27-- Combination 1
28assert(overtparams1(100) == 10)
29assert(overtparams1(100.0, 100) == 20)
30
31-- Combination 2
32assert(overtparams2(100.0, 100) == 40)
33
34-- Combination 3
35assert(overloaded() == 60)
36assert(overloaded(100.0, 100) == 70)
37
38-- Combination 4
39assert(overloadedagain("hello") == 80)
40assert(overloadedagain() == 90)
41
42-- specializations
43assert(specialization(10) == 202 or specialization(10.0) == 203) -- only one works
44assert(specialization(10, 10) == 204 or specialization(10.0, 10.0) == 205) -- ditto
45assert(specialization("hi", "hi") == 201)
46
47-- simple specialization
48xyz()
49xyz_int()
50xyz_double()
51
52-- a bit of everything
53assert(overload("hi") == 0)
54assert(overload(1) == 10)
55assert(overload(1, 1) == 20)
56assert(overload(1, "hello") == 30)
57
58k = Klass()
59assert(overload(k) == 10)
60assert(overload(k, k) == 20)
61assert(overload(k, "hello") == 30)
62-- this one is incorrect: it mactches overload(10.0, "hi") with int overload(T t, const char *c)
63--print(overload(10.0, "hi"))
64--assert(overload(10.0, "hi") == 40)
65assert(overload() == 50)
66
67-- everything put in a namespace
68assert(nsoverload("hi") == 1000,"nsoverload()")
69assert(nsoverload(1) == 1010,"nsoverload(int t)")
70assert(nsoverload(1, 1) == 1020,"nsoverload(int t, const int &)")
71assert(nsoverload(1, "hello") == 1030,"nsoverload(int t, const char *)")
72assert(nsoverload(k) == 1010,"nsoverload(Klass t)")
73assert(nsoverload(k, k) == 1020,"nsoverload(Klass t, const Klass &)")
74assert(nsoverload(k, "hello") == 1030,"nsoverload(Klass t, const char *)")
75-- again this one fails
76--assert(nsoverload(10.0, "hi") == 1040,"nsoverload(double t, const char *)")
77assert(nsoverload() == 1050,"nsoverload(const char *)")
78
79A_foo(1)
80b = B()
81b:foo(1)