diff options
Diffstat (limited to '')
-rw-r--r-- | deep_test/deeptest.lua | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/deep_test/deeptest.lua b/deep_test/deeptest.lua index 3c89c3d..cbd08de 100644 --- a/deep_test/deeptest.lua +++ b/deep_test/deeptest.lua | |||
@@ -6,7 +6,8 @@ local dt = lanes.require "deep_test" | |||
6 | 6 | ||
7 | local test_deep = true | 7 | local test_deep = true |
8 | local test_clonable = true | 8 | local test_clonable = true |
9 | local test_uvtype = "function" | 9 | local test_uvtype = "string" |
10 | local nupvals = _VERSION == "Lua 5.4" and 2 or 1 | ||
10 | 11 | ||
11 | local makeUserValue = function( obj_) | 12 | local makeUserValue = function( obj_) |
12 | if test_uvtype == "string" then | 13 | if test_uvtype == "string" then |
@@ -21,14 +22,17 @@ local makeUserValue = function( obj_) | |||
21 | end | 22 | end |
22 | 23 | ||
23 | local printDeep = function( prefix_, obj_, t_) | 24 | local printDeep = function( prefix_, obj_, t_) |
24 | local uservalue = obj_:getuv( 1) | 25 | print( prefix_, obj_) |
25 | print( prefix_) | 26 | for uvi = 1, nupvals do |
26 | print ( obj_, uservalue, type( uservalue) == "function" and uservalue() or "") | 27 | local uservalue = obj_:getuv( 1) |
28 | print ( "uv #" .. uvi, uservalue, type( uservalue) == "function" and uservalue() or "") | ||
29 | end | ||
27 | if t_ then | 30 | if t_ then |
28 | for k, v in pairs( t_) do | 31 | for k, v in pairs( t_) do |
29 | print( k, v) | 32 | print( k, v) |
30 | end | 33 | end |
31 | end | 34 | end |
35 | print() | ||
32 | end | 36 | end |
33 | 37 | ||
34 | local performTest = function( obj_) | 38 | local performTest = function( obj_) |
@@ -38,12 +42,14 @@ local performTest = function( obj_) | |||
38 | -- lua 5.3 supports an arbitrary type uservalue | 42 | -- lua 5.3 supports an arbitrary type uservalue |
39 | obj_:setuv( 1, makeUserValue( obj_)) | 43 | obj_:setuv( 1, makeUserValue( obj_)) |
40 | -- lua 5.4 supports multiple uservalues of arbitrary types | 44 | -- lua 5.4 supports multiple uservalues of arbitrary types |
41 | -- obj_:setuv( 2, "ENDUV") | 45 | if nupvals > 1 then |
46 | obj_:setuv( 2, "ENDUV") | ||
47 | end | ||
42 | 48 | ||
43 | local t = | 49 | local t = |
44 | { | 50 | { |
45 | ["key"] = obj_, | 51 | ["key"] = obj_, |
46 | -- [obj_] = "val" | 52 | [obj_] = "val" -- this one won't transfer because we don't support full uservalue as keys |
47 | } | 53 | } |
48 | 54 | ||
49 | -- read back the contents of the object | 55 | -- read back the contents of the object |
@@ -76,11 +82,13 @@ local performTest = function( obj_) | |||
76 | end | 82 | end |
77 | 83 | ||
78 | if test_deep then | 84 | if test_deep then |
85 | print "================================================================" | ||
79 | print "DEEP" | 86 | print "DEEP" |
80 | performTest( dt.new_deep()) | 87 | performTest( dt.new_deep(nupvals)) |
81 | end | 88 | end |
82 | 89 | ||
83 | if test_clonable then | 90 | if test_clonable then |
91 | print "================================================================" | ||
84 | print "CLONABLE" | 92 | print "CLONABLE" |
85 | performTest( dt.new_clonable()) | 93 | performTest( dt.new_clonable(nupvals)) |
86 | end | 94 | end |