Skip to content

Commit 39edec9

Browse files
committed
Fix compat function
1 parent 763d9b5 commit 39edec9

File tree

2 files changed

+23
-25
lines changed

2 files changed

+23
-25
lines changed

queue/compat.lua

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ local function split(self, sep)
1212
return fields
1313
end
1414

15-
local function opge(l, r)
16-
l = type(l) == 'string' and tonumber(l) or l
17-
r = type(r) == 'string' and tonumber(r) or r
18-
return l >= r
15+
local function reducer(res, l, r)
16+
if res ~= nil then
17+
return res
18+
end
19+
if tonumber(l) == tonumber(r) then
20+
return nil
21+
end
22+
return tonumber(l) > tonumber(r)
1923
end
2024

2125
local function split_version(version_string)
@@ -30,7 +34,9 @@ local function check_version(expected, version)
3034
if type(version) == 'string' then
3135
version = split_version(version)
3236
end
33-
return iter(version):zip(expected):every(opge)
37+
local res = iter(version):zip(expected):reduce(reducer, nil)
38+
if res or res == nil then res = true end
39+
return res
3440
end
3541

3642
local function get_actual_numtype(version)

t/070-compat.t

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,22 @@ local qcompat = require('queue.compat')
88
test:ok(qcompat, 'queue compatibility layer exists')
99

1010
test:test('*_version', function(test)
11-
test:plan(9)
11+
test:plan(10)
1212

1313
local split_version = qcompat.split_version
1414
local check_version = qcompat.check_version
1515

16-
test:is_deeply(split_version("1.6.8-173"), {"1", "6", "8", "173"},
17-
"check split_version 1")
18-
test:is_deeply(split_version("1.7.1-0"), {"1", "7", "1", "0"},
19-
"check split_version 2")
20-
test:is_deeply(split_version("1.7.1"), {"1", "7", "1"},
21-
"check split_version 3")
22-
23-
test:ok(check_version({1, 7, 1}, "1.8.1-0"),
24-
"check supported version")
25-
test:ok(check_version({1, 7, 1}, "1.7.1-0"),
26-
"check supported version")
27-
test:ok(check_version({1, 7, 1}, "1.7.1-1"),
28-
"check supported version")
29-
test:ok(not check_version({1, 7, 1}, "1.6.9"),
30-
"check unsupported version")
31-
test:ok(not check_version({1, 7, 1}, "1.6.9-100"),
32-
"check unsupported version")
33-
test:ok(not check_version({1, 7, 1}, "1.6.9-100"),
34-
"check unsupported version")
16+
test:is_deeply(split_version("1.6.8-173"), {"1", "6", "8", "173"}, "check split_version 1")
17+
test:is_deeply(split_version("1.7.1-0"), {"1", "7", "1", "0"}, "check split_version 2")
18+
test:is_deeply(split_version("1.7.1"), {"1", "7", "1"}, "check split_version 3")
19+
20+
test:is(check_version({1, 7, 1}, "1.8.1-0"), true, "check supported version")
21+
test:is(check_version({1, 7, 1}, "1.7.1-0"), true, "check supported version")
22+
test:is(check_version({1, 7, 1}, "1.7.1-1"), true, "check supported version")
23+
test:is(check_version({1, 7, 2}, "1.8.1"), true, "check supported version")
24+
test:is(check_version({1, 7, 1}, "1.6.9"), false, "check unsupported version")
25+
test:is(check_version({1, 7, 1}, "1.6.9-100"), false, "check unsupported version")
26+
test:is(check_version({1, 7, 1}, "1.6.9-100"), false, "check unsupported version")
3527
end)
3628

3729
test:test("check compatibility names", function(test)

0 commit comments

Comments
 (0)