aboutsummaryrefslogtreecommitdiff
path: root/spec/util_spec.lua
diff options
context:
space:
mode:
authorGeorge Roman <30772943+georgeroman@users.noreply.github.com>2018-06-05 23:27:07 +0300
committerHisham Muhammad <hisham@gobolinux.org>2018-06-05 17:27:07 -0300
commit526fd923282d03c89c2511f858eb1d66bdba782b (patch)
treecf78a5a86c0ea89c69121ebdf3cd34df3980e541 /spec/util_spec.lua
parenta40861645a9bc9a166c7d35ad09083919b4cec38 (diff)
downloadluarocks-526fd923282d03c89c2511f858eb1d66bdba782b.tar.gz
luarocks-526fd923282d03c89c2511f858eb1d66bdba782b.tar.bz2
luarocks-526fd923282d03c89c2511f858eb1d66bdba782b.zip
Tests: core.util.show_table (#813)
Diffstat (limited to 'spec/util_spec.lua')
-rw-r--r--spec/util_spec.lua34
1 files changed, 34 insertions, 0 deletions
diff --git a/spec/util_spec.lua b/spec/util_spec.lua
index 075a2122..28f99550 100644
--- a/spec/util_spec.lua
+++ b/spec/util_spec.lua
@@ -72,6 +72,7 @@ end)
72 72
73test_env.unload_luarocks() 73test_env.unload_luarocks()
74local util = require("luarocks.util") 74local util = require("luarocks.util")
75local core_util = require("luarocks.core.util")
75 76
76describe("Luarocks util test #unit", function() 77describe("Luarocks util test #unit", function()
77 local runner 78 local runner
@@ -135,4 +136,37 @@ describe("Luarocks util test #unit", function()
135 }, {"k3", {"k2", {"sub order"}}, "k1"}))) 136 }, {"k3", {"k2", {"sub order"}}, "k1"})))
136 end) 137 end)
137 end) 138 end)
139
140 describe("core.util.show_table", function()
141 it("returns a pretty-printed string containing the representation of the given table", function()
142 local result
143
144 local t1 = {1, 2, 3}
145 result = core_util.show_table(t1)
146 assert.truthy(result:find("[1] = 1", 1, true))
147 assert.truthy(result:find("[2] = 2", 1, true))
148 assert.truthy(result:find("[3] = 3", 1, true))
149
150 local t2 = {a = 1, b = 2, c = 3}
151 result = core_util.show_table(t2)
152 assert.truthy(result:find("[\"a\"] = 1", 1, true))
153 assert.truthy(result:find("[\"b\"] = 2", 1, true))
154 assert.truthy(result:find("[\"c\"] = 3", 1, true))
155
156 local t3 = {a = 1, b = "2", c = {3}}
157 result = core_util.show_table(t3)
158 assert.truthy(result:find("[\"a\"] = 1", 1, true))
159 assert.truthy(result:find("[\"b\"] = \"2\"", 1, true))
160 assert.truthy(result:find("[\"c\"] = {", 1, true))
161 assert.truthy(result:find("[1] = 3", 1, true))
162
163 local t4 = {a = 1, b = {c = 2, d = {e = "4"}}}
164 result = core_util.show_table(t4)
165 assert.truthy(result:find("[\"a\"] = 1", 1, true))
166 assert.truthy(result:find("[\"b\"] = {", 1, true))
167 assert.truthy(result:find("[\"c\"] = 2", 1, true))
168 assert.truthy(result:find("[\"d\"] = {", 1, true))
169 assert.truthy(result:find("[\"e\"] = \"4\"", 1, true))
170 end)
171 end)
138end) 172end)