forked from DFHack/dfhack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblueprint.lua
More file actions
155 lines (130 loc) · 5.28 KB
/
Copy pathblueprint.lua
File metadata and controls
155 lines (130 loc) · 5.28 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
local b = require('plugins.blueprint')
-- also covers code shared between parse_gui_commandline and parse_commandline
function test.parse_gui_commandline()
local opts = {}
b.parse_gui_commandline(opts, {})
expect.table_eq({auto_phase=true, name='blueprint'}, opts)
opts = {}
b.parse_gui_commandline(opts, {'help'})
expect.table_eq({help=true}, opts)
opts = {}
b.parse_gui_commandline(opts, {'--help'})
expect.table_eq({help=true}, opts)
opts = {}
b.parse_gui_commandline(opts, {'-h'})
expect.table_eq({help=true}, opts)
opts = {}
mock.patch(dfhack.maps, 'isValidTilePos', mock.func(true),
function()
b.parse_gui_commandline(opts, {'--cursor=1,2,3'})
end)
expect.table_eq({auto_phase=true, name='blueprint', start={x=1,y=2,z=3}},
opts)
opts = {}
b.parse_gui_commandline(opts, {'imaname'})
expect.table_eq({auto_phase=true, name='imaname'}, opts)
opts = {}
expect.error_match('invalid basename',
function() b.parse_gui_commandline(opts, {''}) end)
opts = {}
b.parse_gui_commandline(opts, {'imaname', 'dig', 'query'})
expect.table_eq({auto_phase=false, name='imaname', dig=true, query=true},
opts)
opts = {}
expect.error_match('unknown phase',
function() b.parse_gui_commandline(
opts, {'imaname', 'garbagephase'}) end)
end
function test.parse_commandline()
local opts = {}
b.parse_commandline(opts, '1', '2')
expect.table_eq({auto_phase=true,name='blueprint',width=1,height=2,depth=1},
opts)
opts = {}
b.parse_commandline(opts, '1', '2', '3')
expect.table_eq({auto_phase=true,name='blueprint',width=1,height=2,depth=3},
opts)
opts = {}
b.parse_commandline(opts, '1', '2', '-3')
expect.table_eq({auto_phase=true,name='blueprint',width=1,height=2,depth=-3},
opts)
opts = {}
b.parse_commandline(opts, '1', '2', 'imaname')
expect.table_eq({auto_phase=true,name='imaname',width=1,height=2,depth=1},
opts)
opts = {}
b.parse_commandline(opts, '1', '2', '10imaname')
expect.table_eq({auto_phase=true,name='10imaname',width=1,height=2,depth=1},
opts, 'invalid depth is considered a basename')
opts = {}
b.parse_commandline(opts, '1', '2', '-10imaname')
expect.table_eq({auto_phase=true,name='-10imaname',width=1,height=2,depth=1},
opts, 'invalid negative depth is considered a basename')
opts = {}
b.parse_commandline(opts, '1', '2', '3', 'imaname')
expect.table_eq({auto_phase=true,name='imaname',width=1,height=2,depth=3},
opts)
opts = {}
expect.error_match('invalid width or height',
function() b.parse_commandline(opts) end,
'missing width')
opts = {}
expect.error_match('invalid width or height',
function() b.parse_commandline(opts, '10') end,
'missing height')
opts = {}
expect.error_match('invalid width or height',
function() b.parse_commandline(opts, '0') end,
'zero height')
opts = {}
expect.error_match('invalid width or height',
function() b.parse_commandline(opts, 'hi') end,
'invalid width')
opts = {}
expect.error_match('invalid width or height',
function() b.parse_commandline(opts, '10', 'hi') end,
'invalid height')
opts = {}
expect.error_match('invalid depth',
function() b.parse_commandline(opts, '1', '2', '0') end,
'zero depth')
end
function test.do_phase_positive_dims()
local mock_run = mock.func()
mock.patch(b, 'run', mock_run,
function()
local spos = {x=10, y=20, z=30}
local epos = {x=11, y=21, z=31}
b.query(spos, epos, 'imaname')
expect.eq(1, mock_run.call_count)
expect.table_eq({'2', '2', '2', 'imaname', 'query',
'--cursor=10,20,30'},
mock_run.call_args[1])
end)
end
function test.do_phase_negative_dims()
local mock_run = mock.func()
mock.patch(b, 'run', mock_run,
function()
local spos = {x=11, y=21, z=31}
local epos = {x=10, y=20, z=30}
b.query(spos, epos, 'imaname')
expect.eq(1, mock_run.call_count)
expect.table_eq({'2', '2', '-2', 'imaname', 'query',
'--cursor=10,20,31'},
mock_run.call_args[1])
end)
end
function test.do_phase_ensure_cursor_is_at_upper_left()
local mock_run = mock.func()
mock.patch(b, 'run', mock_run,
function()
local spos = {x=11, y=20, z=30}
local epos = {x=10, y=21, z=31}
b.query(spos, epos, 'imaname')
expect.eq(1, mock_run.call_count)
expect.table_eq({'2', '2', '2', 'imaname', 'query',
'--cursor=10,20,30'},
mock_run.call_args[1])
end)
end