forked from DFHack/dfhack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpect_unit.lua
More file actions
133 lines (111 loc) · 4.93 KB
/
Copy pathexpect_unit.lua
File metadata and controls
133 lines (111 loc) · 4.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
local expect_raw = require('test_util.expect')
function test.str_find()
expect.true_(expect_raw.str_find('a ', 'a str', 'a comment'))
local ok, comment, msg = expect_raw.str_find('ab', 'a str', 'a comment')
expect.false_(ok)
expect.eq('a comment', comment)
expect.eq('pattern "ab" not matched in "a str"', msg)
ok, _, msg = expect_raw.str_find('pattern', nil)
expect.false_(ok)
expect.eq('expected string, got nil', msg)
ok, _, msg = expect_raw.str_find('pattern', {})
expect.false_(ok)
expect.eq('expected string, got table', msg)
end
function test.table_eq()
expect.true_(expect_raw.table_eq({}, {}))
expect.true_(expect_raw.table_eq({'a'}, {'a'}))
expect.true_(expect_raw.table_eq({{'a', k='val'}, 'b'},
{{'a', k='val'}, 'b'}))
expect.false_(expect_raw.table_eq(nil, nil)) -- operands must be non-nil
expect.false_(expect_raw.table_eq({}, nil))
expect.false_(expect_raw.table_eq(nil, {}))
expect.false_(expect_raw.table_eq({}, {''}))
expect.false_(expect_raw.table_eq({''}, {}))
expect.false_(expect_raw.table_eq({'a', {}}, {'a'}))
expect.false_(expect_raw.table_eq({{'a', k='val1'}, 'b'},
{{'a', k='val2'}, 'b'}))
local tab = {a='a', b='b'}
expect.true_(expect_raw.table_eq(tab, tab))
expect.true_(expect_raw.table_eq({tab}, {tab}))
local tab1, tab2 = {'a'}, {'a'}
tab1.self, tab2.self = tab1, tab2
expect.true_(expect_raw.table_eq(tab1, tab2))
tab1.other, tab2.other = tab2, tab1
expect.true_(expect_raw.table_eq(tab1, tab2))
local tabA, tabB, tabC, tabD = {k='a'}, {k='a'}, {k='a'}, {k='a'}
tabA.next, tabB.next, tabC.next, tabD.next = tabB, tabC, tabD, tabA
expect.true_(expect_raw.table_eq(tabA, tabB))
end
function test.error_match()
expect.true_(expect_raw.error_match('err', function() error('err0r') end))
expect.false_(expect_raw.error_match('err', function() end))
expect.false_(expect_raw.error_match('00', function() error('err0r') end))
expect.true_(expect_raw.error_match(
function() return true end, function() error('err0r') end))
expect.false_(expect_raw.error_match(
function() return false end, function() error('err0r') end))
end
function test.error()
expect.true_(expect_raw.error(function() error('err0r') end))
expect.true_(expect_raw.error(function() qerror('err0r') end))
expect.false_(expect_raw.error(function() end))
end
function test.printerr_match_printerr_restored()
local prev_printerr = dfhack.printerr
expect_raw.printerr_match('.*', function() dfhack.printerr('a') end)
expect.eq(prev_printerr, dfhack.printerr)
end
function test.printerr_match()
local noprint = function() end
local oneprint = function()
dfhack.printerr('a')
end
expect.true_(expect_raw.printerr_match(nil, noprint))
expect.true_(expect_raw.printerr_match({}, noprint))
expect.false_(expect_raw.printerr_match(nil, oneprint))
expect.false_(expect_raw.printerr_match({}, oneprint))
expect.true_(expect_raw.printerr_match('a', oneprint))
expect.true_(expect_raw.printerr_match({[1]='a'}, oneprint))
expect.true_(expect_raw.printerr_match({a=1}, oneprint))
expect.true_(expect_raw.printerr_match('.', oneprint))
expect.true_(expect_raw.printerr_match({['.']=1}, oneprint))
expect.true_(expect_raw.printerr_match('.*', oneprint))
expect.true_(expect_raw.printerr_match({['.*']=1}, oneprint))
expect.false_(expect_raw.printerr_match('b', oneprint))
expect.false_(expect_raw.printerr_match({b=1}, oneprint))
expect.false_(expect_raw.printerr_match({a=1,b=1}, oneprint))
local twoprint = function()
dfhack.printerr('a')
dfhack.printerr('b')
end
expect.true_(expect_raw.printerr_match({'a','b'}, twoprint))
expect.true_(expect_raw.printerr_match({a=1,b=1}, twoprint))
expect.false_(expect_raw.printerr_match({'b','a'}, twoprint))
expect.false_(expect_raw.printerr_match({a=1}, twoprint))
expect.false_(expect_raw.printerr_match({b=1}, twoprint))
expect.false_(expect_raw.printerr_match({a=1,b=2}, twoprint))
expect.false_(expect_raw.printerr_match({a=1,b=1,c=1}, twoprint))
local threeprint = function()
dfhack.printerr('a')
dfhack.printerr('b')
dfhack.printerr('c')
end
expect.true_(expect_raw.printerr_match({a=1,b=1,c=1}, threeprint))
local multiprint = function()
dfhack.printerr('a')
dfhack.printerr('b')
dfhack.printerr('a')
end
expect.true_(expect_raw.printerr_match({a=2,b=1}, multiprint))
expect.false_(expect_raw.printerr_match({a=1,b=1}, multiprint))
local nilprint = function()
dfhack.printerr()
end
expect.true_(expect_raw.printerr_match({}, nilprint))
local nilaprint = function()
dfhack.printerr()
dfhack.printerr('a')
end
expect.true_(expect_raw.printerr_match({'a'}, nilaprint))
end