diff options
author | Philipp Janda <siffiejoe@gmx.net> | 2015-01-13 08:27:20 +0100 |
---|---|---|
committer | Philipp Janda <siffiejoe@gmx.net> | 2015-01-13 08:27:20 +0100 |
commit | 901f1bfdbadc7afa5526ca854a12bdfe8fcb88b3 (patch) | |
tree | 698870c642950c4287c7ab57c2dcab28b3efb6a6 /tests/test.lua | |
parent | 46bbf75fbea482c19c4eb50bf97ef948f611e26a (diff) | |
download | lua-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-x | tests/test.lua | 109 |
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 | |||
3 | local mod = require( "testmod" ) | ||
4 | local F | ||
5 | do | ||
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 | ||
17 | end | ||
18 | |||
19 | |||
20 | print( mod.isinteger( 1 ) ) | ||
21 | print( mod.isinteger( 0 ) ) | ||
22 | print( mod.isinteger( 1234567 ) ) | ||
23 | print( mod.isinteger( 12.3 ) ) | ||
24 | print( mod.isinteger( math.huge ) ) | ||
25 | print( mod.isinteger( math.sqrt( -1 ) ) ) | ||
26 | |||
27 | |||
28 | print( mod.rotate( 1, 1, 2, 3, 4, 5, 6 ) ) | ||
29 | print( mod.rotate(-1, 1, 2, 3, 4, 5, 6 ) ) | ||
30 | print( mod.rotate( 4, 1, 2, 3, 4, 5, 6 ) ) | ||
31 | print( mod.rotate( -4, 1, 2, 3, 4, 5, 6 ) ) | ||
32 | |||
33 | |||
34 | print( mod.strtonum( "+123" ) ) | ||
35 | print( mod.strtonum( " 123 " ) ) | ||
36 | print( mod.strtonum( "-1.23" ) ) | ||
37 | print( mod.strtonum( " 123 abc" ) ) | ||
38 | print( mod.strtonum( "jkl" ) ) | ||
39 | |||
40 | |||
41 | local a, b, c = mod.requiref() | ||
42 | print( type( a ), type( b ), type( c ), | ||
43 | a.boolean, b.boolean, c.boolean, | ||
44 | type( requiref1 ), type( requiref2 ), type( requiref3 ) ) | ||
45 | |||
46 | local proxy, backend = {}, {} | ||
47 | setmetatable( proxy, { __index = backend, __newindex = backend } ) | ||
48 | print( rawget( proxy, 1 ), rawget( backend, 1 ) ) | ||
49 | print( mod.getseti( proxy, 1 ) ) | ||
50 | print( rawget( proxy, 1 ), rawget( backend, 1 ) ) | ||
51 | print( mod.getseti( proxy, 1 ) ) | ||
52 | print( rawget( proxy, 1 ), rawget( backend, 1 ) ) | ||
53 | |||
54 | -- tests for Lua 5.1 | ||
55 | print(mod.tonumber(12)) | ||
56 | print(mod.tonumber("12")) | ||
57 | print(mod.tonumber("0")) | ||
58 | print(mod.tonumber(false)) | ||
59 | print(mod.tonumber("error")) | ||
60 | |||
61 | print(mod.tointeger(12)) | ||
62 | print(mod.tointeger("12")) | ||
63 | print(mod.tointeger("0")) | ||
64 | print( "aaa" ) | ||
65 | print(mod.tointeger(math.pi)) | ||
66 | print( "bbb" ) | ||
67 | print(mod.tointeger(false)) | ||
68 | print(mod.tointeger("error")) | ||
69 | |||
70 | print(mod.len("123")) | ||
71 | print(mod.len({ 1, 2, 3})) | ||
72 | print(pcall(mod.len, true)) | ||
73 | local ud, meta = mod.newproxy() | ||
74 | meta.__len = function() return 5 end | ||
75 | print(mod.len(ud)) | ||
76 | meta.__len = function() return true end | ||
77 | print(pcall(mod.len, ud)) | ||
78 | |||
79 | print(mod.copy(true, "string", {}, 1)) | ||
80 | |||
81 | print(mod.rawxetp()) | ||
82 | print(mod.rawxetp("I'm back")) | ||
83 | |||
84 | print(F(mod.globals()), mod.globals() == _G) | ||
85 | |||
86 | local t = {} | ||
87 | print(F(mod.subtable(t))) | ||
88 | local x, msg = mod.subtable(t) | ||
89 | print(F(x, msg, x == t.xxx)) | ||
90 | |||
91 | print(F(mod.udata())) | ||
92 | print(mod.udata("nosuchtype")) | ||
93 | |||
94 | print(F(mod.uservalue())) | ||
95 | |||
96 | print(mod.getupvalues()) | ||
97 | |||
98 | print(mod.absindex("hi", true)) | ||
99 | |||
100 | print(mod.tolstring("string")) | ||
101 | local t = setmetatable({}, { | ||
102 | __tostring = function(v) return "mytable" end | ||
103 | }) | ||
104 | print(mod.tolstring( t ) ) | ||
105 | local t = setmetatable({}, { | ||
106 | __tostring = function(v) return nil end | ||
107 | }) | ||
108 | print(pcall(mod.tolstring, t)) | ||
109 | |||