3 function table_tostring (tt
)
4 if type(tt
) == "table" then
7 table.insert(sb
, "{ ");
8 for key
, value
in pairs (tt
) do
9 if first
then first
= false else table.insert(sb
, ", ") end
10 if "number" == type (key
) then
11 table.insert(sb
, table_tostring (value
))
15 table.insert(sb
, table_tostring (value
))
18 table.insert(sb
, " }");
19 return table.concat(sb
)
20 elseif type (tt
) == "number" then
23 return '"' .. tostring(tt
) .. '"'
27 function print_tables(str
,t
)
29 for key
, value
in ipairs(t
) do
30 print(" " .. key
.. ": " .. table_tostring(value
))
37 -- Second table tree may contain some indices that the first does not contain.
39 function table_compare(table, super
)
40 if not ( type(table) == type(super
) ) then
43 if not ( type(table) == "table" ) then
46 for key
, value
in pairs(table) do
47 if not table_compare(value
, super
[key
]) then return false end
53 -- {{{ mock notion context
55 load_module
= function() return 1 end,
56 rootwin
= function() return nil end,
57 screens_updated
= function(root
) return 1 end
63 _G
["mod_xinerama"] = {
64 query_screens
= function() end
69 -- load xinerama module lua code
70 dofile('mod_xinerama.lua')
72 function do_test(fn_name
, input
, output
)
73 print("\nTesting:" .. fn_name
)
74 print_tables("Input", input
)
75 local ret
= mod_xinerama
[fn_name
](input
)
76 print_tables("Output", ret
)
77 assert(table_compare(output
, ret
))
80 -- now perform some tests:
82 -- {{{ merge_contained_screens
84 do_test("merge_contained_screens",{
90 do_test("merge_contained_screens",{
91 {x
=0,y
=0,w
=800,h
=600},
92 {x
=0,y
=0,w
=800,h
=600},
97 do_test("merge_contained_screens",{
98 {x
=0,y
=0,w
=800,h
=600},
99 {x
=100,y
=100,w
=600,h
=400},
101 {x
=0,y
=0,w
=800,h
=600}
104 do_test("merge_contained_screens",{
105 {x
=0,y
=0,w
=800,h
=600},
106 {x
=100,y
=100,w
=800,h
=600},
108 {x
=0,y
=0,w
=800,h
=600},
109 {x
=100,y
=100,w
=800,h
=600},
114 -- {{{ merge_overlapping_screens
116 do_test("merge_overlapping_screens",{
117 {x
=0,y
=0,w
=800,h
=600}
119 {x
=0,y
=0,w
=800,h
=600}
122 do_test("merge_overlapping_screens",{
123 {x
=0,y
=0,w
=800,h
=600},
124 {x
=0,y
=0,w
=800,h
=600},
126 {x
=0,y
=0,w
=800,h
=600}
129 do_test("merge_overlapping_screens",{
130 {x
=0,y
=0,w
=800,h
=600},
131 {x
=100,y
=100,w
=600,h
=400},
133 {x
=0,y
=0,w
=800,h
=600}
136 do_test("merge_overlapping_screens",{
137 {x
=0,y
=0,w
=800,h
=600},
138 {x
=100,y
=100,w
=800,h
=600},
140 {x
=0,y
=0,w
=900,h
=700}
145 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
146 0 ____________________
158 do_test("merge_overlapping_screens",{
159 {x
=0,y
=0,w
=800,h
=600},
160 {x
=400,y
=400,w
=800,h
=600},
161 {x
=500,y
=0,w
=500,h
=300}
163 {x
=0,y
=0,w
=1200,h
=1000}
168 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
169 0 ________________ ______
181 do_test("merge_overlapping_screens",{
182 {x
=0,y
=0,w
=800,h
=600},
183 {x
=900,y
=100,w
=300,h
=300},
184 {x
=400,y
=400,w
=800,h
=600}
186 {x
=0,y
=0,w
=1200,h
=1000}
189 do_test("merge_overlapping_screens_alternative",{
190 {x
=0,y
=0,w
=800,h
=600},
191 {x
=400,y
=400,w
=800,h
=600},
192 {x
=900,y
=100,w
=300,h
=300}
194 {x
=0,y
=0,w
=1200,h
=1000},
195 {x
=900,y
=100,w
=300,h
=300}