|
1 | | -local core = require 'core.code-action' |
2 | | -local files = require 'files' |
3 | | -local lang = require 'language' |
4 | | -local catch = require 'catch' |
5 | | -local furi = require 'file-uri' |
| 1 | +local core = require 'core.code-action' |
| 2 | +local files = require 'files' |
| 3 | +local lang = require 'language' |
| 4 | +local catch = require 'catch' |
| 5 | +local furi = require 'file-uri' |
| 6 | +local compare = require 'compare' |
6 | 7 |
|
7 | 8 | rawset(_G, 'TEST', true) |
8 | 9 |
|
9 | | -local EXISTS = {} |
| 10 | +local EXISTS = compare.EXISTS |
10 | 11 |
|
11 | | -local function eq(expected, result) |
12 | | - if expected == EXISTS and result ~= nil then |
13 | | - return true |
14 | | - end |
15 | | - if result == EXISTS and expected ~= nil then |
16 | | - return true |
17 | | - end |
18 | | - local tp1, tp2 = type(expected), type(result) |
19 | | - if tp1 ~= tp2 then |
20 | | - return false, string.format(": expected type %s, got %s", tp1, tp2) |
21 | | - end |
22 | | - if tp1 == 'table' then |
23 | | - local mark = {} |
24 | | - for k in pairs(expected) do |
25 | | - local ok, err = eq(expected[k], result[k]) |
26 | | - if not ok then |
27 | | - return false, string.format(".%s%s", k, err) |
28 | | - end |
29 | | - mark[k] = true |
30 | | - end |
31 | | - for k in pairs(result) do |
32 | | - if not mark[k] then |
33 | | - return false, string.format(".%s: missing key in result", k) |
34 | | - end |
35 | | - end |
36 | | - return true |
37 | | - end |
38 | | - return expected == result, string.format(": expected %s, got %s", expected, result) |
39 | | -end |
40 | | - |
41 | | -function TEST(script) |
| 12 | +local function TEST(script) |
42 | 13 | return function (expect) |
43 | 14 | local newScript, catched = catch(script, '?') |
44 | 15 | files.setText(TESTURI, newScript) |
45 | 16 | local results = core(TESTURI, catched['?'][1][1], catched['?'][1][2]) |
46 | 17 | assert(results) |
47 | | - assert(eq(expect, results)) |
| 18 | + assert(compare.eq(expect, results)) |
48 | 19 | files.remove(TESTURI) |
49 | 20 | end |
50 | 21 | end |
@@ -72,7 +43,7 @@ local function TEST_CROSSFILE(testfiles) |
72 | 43 |
|
73 | 44 | local results = core(TESTURI, catched['?'][1][1], catched['?'][1][2]) |
74 | 45 | assert(results) |
75 | | - assert(eq(expected, results)) |
| 46 | + assert(compare.eq(expected, results)) |
76 | 47 | end |
77 | 48 | end |
78 | 49 |
|
|
0 commit comments