aboutsummaryrefslogtreecommitdiff
path: root/tests/test.lua
diff options
context:
space:
mode:
authorPhilipp Janda <siffiejoe@gmx.net>2015-01-13 08:27:20 +0100
committerPhilipp Janda <siffiejoe@gmx.net>2015-01-13 08:27:20 +0100
commit901f1bfdbadc7afa5526ca854a12bdfe8fcb88b3 (patch)
tree698870c642950c4287c7ab57c2dcab28b3efb6a6 /tests/test.lua
parent46bbf75fbea482c19c4eb50bf97ef948f611e26a (diff)
downloadlua-compat-5.3-901f1bfdbadc7afa5526ca854a12bdfe8fcb88b3.tar.gz
lua-compat-5.3-901f1bfdbadc7afa5526ca854a12bdfe8fcb88b3.tar.bz2
lua-compat-5.3-901f1bfdbadc7afa5526ca854a12bdfe8fcb88b3.zip
add initial implementation of c-api and license
Diffstat (limited to 'tests/test.lua')
-rwxr-xr-xtests/test.lua109
1 files changed, 109 insertions, 0 deletions
diff --git a/tests/test.lua b/tests/test.lua
new file mode 100755
index 0000000..cc07ee8
--- /dev/null
+++ b/tests/test.lua
@@ -0,0 +1,109 @@
1#!/usr/bin/env lua
2
3local mod = require( "testmod" )
4local F
5do
6 local type, unpack = type, table.unpack or unpack
7 function F( ... )
8 local args, n = { ... }, select( '#', ... )
9 for i = 1, n do
10 local t = type( args[ i ] )
11 if t ~= "string" and t ~= "number" and t ~= "boolean" then
12 args[ i ] = t
13 end
14 end
15 return unpack( args, 1, n )
16 end
17end
18
19
20print( mod.isinteger( 1 ) )
21print( mod.isinteger( 0 ) )
22print( mod.isinteger( 1234567 ) )
23print( mod.isinteger( 12.3 ) )
24print( mod.isinteger( math.huge ) )
25print( mod.isinteger( math.sqrt( -1 ) ) )
26
27
28print( mod.rotate( 1, 1, 2, 3, 4, 5, 6 ) )
29print( mod.rotate(-1, 1, 2, 3, 4, 5, 6 ) )
30print( mod.rotate( 4, 1, 2, 3, 4, 5, 6 ) )
31print( mod.rotate( -4, 1, 2, 3, 4, 5, 6 ) )
32
33
34print( mod.strtonum( "+123" ) )
35print( mod.strtonum( " 123 " ) )
36print( mod.strtonum( "-1.23" ) )
37print( mod.strtonum( " 123 abc" ) )
38print( mod.strtonum( "jkl" ) )
39
40
41local a, b, c = mod.requiref()
42print( type( a ), type( b ), type( c ),
43 a.boolean, b.boolean, c.boolean,
44 type( requiref1 ), type( requiref2 ), type( requiref3 ) )
45
46local proxy, backend = {}, {}
47setmetatable( proxy, { __index = backend, __newindex = backend } )
48print( rawget( proxy, 1 ), rawget( backend, 1 ) )
49print( mod.getseti( proxy, 1 ) )
50print( rawget( proxy, 1 ), rawget( backend, 1 ) )
51print( mod.getseti( proxy, 1 ) )
52print( rawget( proxy, 1 ), rawget( backend, 1 ) )
53
54-- tests for Lua 5.1
55print(mod.tonumber(12))
56print(mod.tonumber("12"))
57print(mod.tonumber("0"))
58print(mod.tonumber(false))
59print(mod.tonumber("error"))
60
61print(mod.tointeger(12))
62print(mod.tointeger("12"))
63print(mod.tointeger("0"))
64print( "aaa" )
65print(mod.tointeger(math.pi))
66print( "bbb" )
67print(mod.tointeger(false))
68print(mod.tointeger("error"))
69
70print(mod.len("123"))
71print(mod.len({ 1, 2, 3}))
72print(pcall(mod.len, true))
73local ud, meta = mod.newproxy()
74meta.__len = function() return 5 end
75print(mod.len(ud))
76meta.__len = function() return true end
77print(pcall(mod.len, ud))
78
79print(mod.copy(true, "string", {}, 1))
80
81print(mod.rawxetp())
82print(mod.rawxetp("I'm back"))
83
84print(F(mod.globals()), mod.globals() == _G)
85
86local t = {}
87print(F(mod.subtable(t)))
88local x, msg = mod.subtable(t)
89print(F(x, msg, x == t.xxx))
90
91print(F(mod.udata()))
92print(mod.udata("nosuchtype"))
93
94print(F(mod.uservalue()))
95
96print(mod.getupvalues())
97
98print(mod.absindex("hi", true))
99
100print(mod.tolstring("string"))
101local t = setmetatable({}, {
102 __tostring = function(v) return "mytable" end
103})
104print(mod.tolstring( t ) )
105local t = setmetatable({}, {
106 __tostring = function(v) return nil end
107})
108print(pcall(mod.tolstring, t))
109