diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2016-10-06 11:53:43 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-06 11:53:43 -0300 |
commit | 2c95d93a7d02b5b3278de1841d5717a56e6ccdfe (patch) | |
tree | 49c3e583567c40a5173a603dff941dcb6e415992 /spec | |
parent | 5f3b2b79bbba5de0a571188c08b42a213aac772f (diff) | |
parent | eb7427676a2f09556f9d5f19a1a6392fd945e8bc (diff) | |
download | luarocks-2c95d93a7d02b5b3278de1841d5717a56e6ccdfe.tar.gz luarocks-2c95d93a7d02b5b3278de1841d5717a56e6ccdfe.tar.bz2 luarocks-2c95d93a7d02b5b3278de1841d5717a56e6ccdfe.zip |
Merge pull request #624 from mpeterv/coroutineless-sortedpairs
Don't use coroutines in util.sortedpairs
Diffstat (limited to 'spec')
-rw-r--r-- | spec/util_spec.lua | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/spec/util_spec.lua b/spec/util_spec.lua index e6776e4b..2779b1ce 100644 --- a/spec/util_spec.lua +++ b/spec/util_spec.lua | |||
@@ -116,3 +116,59 @@ describe("Basic tests #blackbox #b_util", function() | |||
116 | end) | 116 | end) |
117 | end) | 117 | end) |
118 | end) | 118 | end) |
119 | |||
120 | test_env.unload_luarocks() | ||
121 | local util = require("luarocks.util") | ||
122 | |||
123 | describe("Luarocks util test #whitebox #w_util", function() | ||
124 | describe("util.sortedpairs", function() | ||
125 | local function collect(iter, state, var) | ||
126 | local collected = {} | ||
127 | |||
128 | while true do | ||
129 | local returns = {iter(state, var)} | ||
130 | |||
131 | if returns[1] == nil then | ||
132 | return collected | ||
133 | else | ||
134 | table.insert(collected, returns) | ||
135 | var = returns[1] | ||
136 | end | ||
137 | end | ||
138 | end | ||
139 | |||
140 | it("default sort", function() | ||
141 | assert.are.same({}, collect(util.sortedpairs({}))) | ||
142 | assert.are.same({ | ||
143 | {1, "v1"}, | ||
144 | {2, "v2"}, | ||
145 | {3, "v3"}, | ||
146 | {"bar", "v5"}, | ||
147 | {"foo", "v4"} | ||
148 | }, collect(util.sortedpairs({"v1", "v2", "v3", foo = "v4", bar = "v5"}))) | ||
149 | end) | ||
150 | |||
151 | it("sort by function", function() | ||
152 | local function compare(a, b) return a > b end | ||
153 | assert.are.same({}, collect(util.sortedpairs({}, compare))) | ||
154 | assert.are.same({ | ||
155 | {3, "v3"}, | ||
156 | {2, "v2"}, | ||
157 | {1, "v1"} | ||
158 | }, collect(util.sortedpairs({"v1", "v2", "v3"}, compare))) | ||
159 | end) | ||
160 | |||
161 | it("sort by priority table", function() | ||
162 | assert.are.same({}, collect(util.sortedpairs({}, {"k1", "k2"}))) | ||
163 | assert.are.same({ | ||
164 | {"k3", "v3"}, | ||
165 | {"k2", "v2", {"sub order"}}, | ||
166 | {"k1", "v1"}, | ||
167 | {"k4", "v4"}, | ||
168 | {"k5", "v5"}, | ||
169 | }, collect(util.sortedpairs({ | ||
170 | k1 = "v1", k2 = "v2", k3 = "v3", k4 = "v4", k5 = "v5" | ||
171 | }, {"k3", {"k2", {"sub order"}}, "k1"}))) | ||
172 | end) | ||
173 | end) | ||
174 | end) | ||