diff options
author | George Roman <30772943+georgeroman@users.noreply.github.com> | 2018-06-05 23:27:07 +0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-06-05 17:27:07 -0300 |
commit | 526fd923282d03c89c2511f858eb1d66bdba782b (patch) | |
tree | cf78a5a86c0ea89c69121ebdf3cd34df3980e541 /spec/util_spec.lua | |
parent | a40861645a9bc9a166c7d35ad09083919b4cec38 (diff) | |
download | luarocks-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.lua | 34 |
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 | ||
73 | test_env.unload_luarocks() | 73 | test_env.unload_luarocks() |
74 | local util = require("luarocks.util") | 74 | local util = require("luarocks.util") |
75 | local core_util = require("luarocks.core.util") | ||
75 | 76 | ||
76 | describe("Luarocks util test #unit", function() | 77 | describe("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) | ||
138 | end) | 172 | end) |