2021-05-07 15:07:37 -06:00
|
|
|
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, {})
|
2021-09-10 15:44:24 -06:00
|
|
|
expect.table_eq({auto_phase=true, format='minimal', split_strategy='none',
|
|
|
|
name='blueprint'},
|
2021-09-09 01:46:33 -06:00
|
|
|
opts)
|
2021-05-07 15:07:37 -06:00
|
|
|
|
|
|
|
opts = {}
|
|
|
|
b.parse_gui_commandline(opts, {'help'})
|
|
|
|
expect.table_eq({help=true}, opts)
|
|
|
|
|
|
|
|
opts = {}
|
|
|
|
b.parse_gui_commandline(opts, {'--help'})
|
2021-09-10 15:44:24 -06:00
|
|
|
expect.table_eq({help=true, format='minimal', split_strategy='none'}, opts)
|
2021-05-07 15:07:37 -06:00
|
|
|
|
|
|
|
opts = {}
|
|
|
|
b.parse_gui_commandline(opts, {'-h'})
|
2021-09-10 15:44:24 -06:00
|
|
|
expect.table_eq({help=true, format='minimal', split_strategy='none'}, opts)
|
2021-05-07 15:07:37 -06:00
|
|
|
|
|
|
|
opts = {}
|
2021-07-05 17:01:23 -06:00
|
|
|
mock.patch(dfhack.maps, 'isValidTilePos', mock.func(true),
|
|
|
|
function()
|
|
|
|
b.parse_gui_commandline(opts, {'--cursor=1,2,3'})
|
|
|
|
end)
|
2021-09-10 15:44:24 -06:00
|
|
|
expect.table_eq({auto_phase=true, format='minimal', split_strategy='none',
|
|
|
|
name='blueprint', start={x=1,y=2,z=3}},
|
|
|
|
opts)
|
|
|
|
|
2022-04-01 12:36:19 -06:00
|
|
|
opts = {}
|
|
|
|
b.parse_gui_commandline(opts, {'-e'})
|
|
|
|
expect.table_eq({auto_phase=true, format='minimal', split_strategy='none',
|
|
|
|
name='blueprint', engrave=true,},
|
|
|
|
opts)
|
|
|
|
|
2022-10-12 11:10:53 -06:00
|
|
|
opts = {}
|
|
|
|
b.parse_gui_commandline(opts, {'--smooth'})
|
|
|
|
expect.table_eq({auto_phase=true, format='minimal', split_strategy='none',
|
|
|
|
name='blueprint', smooth=true,},
|
|
|
|
opts)
|
|
|
|
|
2022-04-01 12:36:19 -06:00
|
|
|
opts = {}
|
|
|
|
b.parse_gui_commandline(opts, {'--engrave'})
|
|
|
|
expect.table_eq({auto_phase=true, format='minimal', split_strategy='none',
|
|
|
|
name='blueprint', engrave=true,},
|
|
|
|
opts)
|
|
|
|
|
2021-09-10 15:44:24 -06:00
|
|
|
opts = {}
|
|
|
|
b.parse_gui_commandline(opts, {'-fminimal'})
|
|
|
|
expect.table_eq({auto_phase=true, format='minimal', split_strategy='none',
|
|
|
|
name='blueprint'},
|
2021-05-07 15:07:37 -06:00
|
|
|
opts)
|
|
|
|
|
2021-09-10 15:44:24 -06:00
|
|
|
opts = {}
|
|
|
|
b.parse_gui_commandline(opts, {'--format', 'pretty'})
|
|
|
|
expect.table_eq({auto_phase=true, format='pretty', split_strategy='none',
|
|
|
|
name='blueprint'},
|
|
|
|
opts)
|
|
|
|
|
|
|
|
expect.error_match('unknown format',
|
2021-09-20 15:32:25 -06:00
|
|
|
function() b.parse_gui_commandline({}, {'-ffoo'}) end)
|
2021-09-10 15:44:24 -06:00
|
|
|
|
2021-09-09 01:46:33 -06:00
|
|
|
opts = {}
|
|
|
|
b.parse_gui_commandline(opts, {'-tnone'})
|
2021-09-10 15:44:24 -06:00
|
|
|
expect.table_eq({auto_phase=true, format='minimal', split_strategy='none',
|
|
|
|
name='blueprint'},
|
2021-09-09 01:46:33 -06:00
|
|
|
opts)
|
|
|
|
|
2021-09-20 15:32:25 -06:00
|
|
|
opts = {}
|
|
|
|
b.parse_gui_commandline(opts, {'--playback-start', '2,3,imacomment'})
|
|
|
|
expect.table_eq({auto_phase=true, format='minimal', split_strategy='none',
|
|
|
|
name='blueprint', playback_start={x=2, y=3},
|
|
|
|
playback_start_comment='imacomment'},
|
|
|
|
opts)
|
|
|
|
|
|
|
|
opts = {}
|
|
|
|
b.parse_gui_commandline(opts, {'-s2,3'})
|
|
|
|
expect.table_eq({auto_phase=true, format='minimal', split_strategy='none',
|
|
|
|
name='blueprint', playback_start={x=2, y=3}},
|
|
|
|
opts)
|
|
|
|
|
|
|
|
expect.error_match('must be positive integers',
|
|
|
|
function() b.parse_gui_commandline({}, {'-s10'}) end)
|
|
|
|
expect.error_match('must be positive integers',
|
|
|
|
function() b.parse_gui_commandline({}, {'-s1,-1'}) end)
|
|
|
|
expect.error_match('must be positive integers',
|
|
|
|
function() b.parse_gui_commandline({}, {'-s-1,1'}) end)
|
|
|
|
expect.error_match('must be positive integers',
|
|
|
|
function() b.parse_gui_commandline({}, {'-s1,0'}) end)
|
|
|
|
expect.error_match('must be positive integers',
|
|
|
|
function() b.parse_gui_commandline({}, {'-s0,1'}) end)
|
|
|
|
|
2021-09-09 01:46:33 -06:00
|
|
|
opts = {}
|
|
|
|
b.parse_gui_commandline(opts, {'--splitby', 'phase'})
|
2021-09-10 15:44:24 -06:00
|
|
|
expect.table_eq({auto_phase=true, format='minimal', split_strategy='phase',
|
|
|
|
name='blueprint'},
|
2021-09-09 01:46:33 -06:00
|
|
|
opts)
|
|
|
|
|
2021-09-10 15:44:24 -06:00
|
|
|
expect.error_match('unknown split_strategy',
|
2021-09-20 15:32:25 -06:00
|
|
|
function() b.parse_gui_commandline({}, {'-tfoo'}) end)
|
2021-09-09 01:46:33 -06:00
|
|
|
|
2021-05-07 15:07:37 -06:00
|
|
|
opts = {}
|
|
|
|
b.parse_gui_commandline(opts, {'imaname'})
|
2021-09-10 15:44:24 -06:00
|
|
|
expect.table_eq({auto_phase=true, format='minimal', split_strategy='none',
|
2021-09-09 01:46:33 -06:00
|
|
|
name='imaname'},
|
|
|
|
opts)
|
2021-05-07 15:07:37 -06:00
|
|
|
|
|
|
|
expect.error_match('invalid basename',
|
2021-09-20 15:32:25 -06:00
|
|
|
function() b.parse_gui_commandline({}, {''}) end)
|
2021-05-07 15:07:37 -06:00
|
|
|
|
|
|
|
opts = {}
|
|
|
|
b.parse_gui_commandline(opts, {'imaname', 'dig', 'query'})
|
2021-09-10 15:44:24 -06:00
|
|
|
expect.table_eq({auto_phase=false, format='minimal', split_strategy='none',
|
|
|
|
name='imaname', dig=true, query=true},
|
2021-05-07 15:07:37 -06:00
|
|
|
opts)
|
|
|
|
|
2021-05-21 07:33:33 -06:00
|
|
|
expect.error_match('unknown phase',
|
|
|
|
function() b.parse_gui_commandline(
|
2021-09-20 15:32:25 -06:00
|
|
|
{}, {'imaname', 'garbagephase'}) end)
|
2021-05-07 15:07:37 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
function test.parse_commandline()
|
|
|
|
local opts = {}
|
|
|
|
b.parse_commandline(opts, '1', '2')
|
2021-09-10 15:44:24 -06:00
|
|
|
expect.table_eq({auto_phase=true, format='minimal', split_strategy='none',
|
|
|
|
name='blueprint', width=1, height=2, depth=1},
|
2021-05-07 15:07:37 -06:00
|
|
|
opts)
|
|
|
|
|
|
|
|
opts = {}
|
|
|
|
b.parse_commandline(opts, '1', '2', '3')
|
2021-09-10 15:44:24 -06:00
|
|
|
expect.table_eq({auto_phase=true, format='minimal', split_strategy='none',
|
|
|
|
name='blueprint', width=1, height=2, depth=3},
|
2021-05-07 15:07:37 -06:00
|
|
|
opts)
|
|
|
|
|
|
|
|
opts = {}
|
|
|
|
b.parse_commandline(opts, '1', '2', '-3')
|
2021-09-10 15:44:24 -06:00
|
|
|
expect.table_eq({auto_phase=true, format='minimal', split_strategy='none',
|
|
|
|
name='blueprint', width=1, height=2, depth=-3},
|
2021-05-07 15:07:37 -06:00
|
|
|
opts)
|
|
|
|
|
|
|
|
opts = {}
|
|
|
|
b.parse_commandline(opts, '1', '2', 'imaname')
|
2021-09-10 15:44:24 -06:00
|
|
|
expect.table_eq({auto_phase=true, format='minimal', split_strategy='none',
|
|
|
|
name='imaname', width=1, height=2, depth=1},
|
2021-05-07 15:07:37 -06:00
|
|
|
opts)
|
|
|
|
|
|
|
|
opts = {}
|
|
|
|
b.parse_commandline(opts, '1', '2', '10imaname')
|
2021-09-10 15:44:24 -06:00
|
|
|
expect.table_eq({auto_phase=true, format='minimal', split_strategy='none',
|
|
|
|
name='10imaname', width=1, height=2, depth=1},
|
2021-05-07 15:07:37 -06:00
|
|
|
opts, 'invalid depth is considered a basename')
|
|
|
|
|
|
|
|
opts = {}
|
|
|
|
b.parse_commandline(opts, '1', '2', '-10imaname')
|
2021-09-10 15:44:24 -06:00
|
|
|
expect.table_eq({auto_phase=true, format='minimal', split_strategy='none',
|
|
|
|
name='-10imaname', width=1, height=2, depth=1},
|
2021-05-07 15:07:37 -06:00
|
|
|
opts, 'invalid negative depth is considered a basename')
|
|
|
|
|
|
|
|
opts = {}
|
|
|
|
b.parse_commandline(opts, '1', '2', '3', 'imaname')
|
2021-09-10 15:44:24 -06:00
|
|
|
expect.table_eq({auto_phase=true, format='minimal', split_strategy='none',
|
|
|
|
name='imaname', width=1, height=2, depth=3},
|
2021-05-07 15:07:37 -06:00
|
|
|
opts)
|
|
|
|
|
|
|
|
expect.error_match('invalid width or height',
|
2021-09-20 15:32:25 -06:00
|
|
|
function() b.parse_commandline({}) end,
|
2021-05-07 15:07:37 -06:00
|
|
|
'missing width')
|
|
|
|
expect.error_match('invalid width or height',
|
2021-09-20 15:32:25 -06:00
|
|
|
function() b.parse_commandline({}, '10') end,
|
2021-05-07 15:07:37 -06:00
|
|
|
'missing height')
|
|
|
|
expect.error_match('invalid width or height',
|
2021-09-20 15:32:25 -06:00
|
|
|
function() b.parse_commandline({}, '0') end,
|
2021-05-07 15:07:37 -06:00
|
|
|
'zero height')
|
|
|
|
expect.error_match('invalid width or height',
|
2021-09-20 15:32:25 -06:00
|
|
|
function() b.parse_commandline({}, 'hi') end,
|
2021-05-07 15:07:37 -06:00
|
|
|
'invalid width')
|
|
|
|
expect.error_match('invalid width or height',
|
2021-09-20 15:32:25 -06:00
|
|
|
function() b.parse_commandline({}, '10', 'hi') end,
|
2021-05-07 15:07:37 -06:00
|
|
|
'invalid height')
|
|
|
|
expect.error_match('invalid depth',
|
2021-09-20 15:32:25 -06:00
|
|
|
function() b.parse_commandline({}, '1', '2', '0') end,
|
2021-05-07 15:07:37 -06:00
|
|
|
'zero depth')
|
2021-09-20 15:32:25 -06:00
|
|
|
|
|
|
|
expect.error_match('x offset outside width of blueprint',
|
|
|
|
function() b.parse_commandline(
|
|
|
|
{}, '3', '2', '1', '-s4,1') end)
|
|
|
|
expect.error_match('y offset outside height of blueprint',
|
|
|
|
function() b.parse_commandline(
|
|
|
|
{}, '3', '2', '1', '-s1,3') end)
|
2021-05-07 15:07:37 -06:00
|
|
|
end
|
|
|
|
|
2021-05-21 07:52:16 -06:00
|
|
|
function test.do_phase_positive_dims()
|
|
|
|
local mock_run = mock.func()
|
|
|
|
mock.patch(b, 'run', mock_run,
|
2021-05-07 15:07:37 -06:00
|
|
|
function()
|
|
|
|
local spos = {x=10, y=20, z=30}
|
|
|
|
local epos = {x=11, y=21, z=31}
|
|
|
|
b.query(spos, epos, 'imaname')
|
2021-05-21 07:52:16 -06:00
|
|
|
expect.eq(1, mock_run.call_count)
|
|
|
|
expect.table_eq({'2', '2', '2', 'imaname', 'query',
|
2021-05-07 15:07:37 -06:00
|
|
|
'--cursor=10,20,30'},
|
2021-05-21 07:52:16 -06:00
|
|
|
mock_run.call_args[1])
|
2021-05-07 15:07:37 -06:00
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2021-05-21 07:52:16 -06:00
|
|
|
function test.do_phase_negative_dims()
|
|
|
|
local mock_run = mock.func()
|
|
|
|
mock.patch(b, 'run', mock_run,
|
2021-05-07 15:07:37 -06:00
|
|
|
function()
|
|
|
|
local spos = {x=11, y=21, z=31}
|
|
|
|
local epos = {x=10, y=20, z=30}
|
|
|
|
b.query(spos, epos, 'imaname')
|
2021-05-21 07:52:16 -06:00
|
|
|
expect.eq(1, mock_run.call_count)
|
|
|
|
expect.table_eq({'2', '2', '-2', 'imaname', 'query',
|
2021-05-07 15:07:37 -06:00
|
|
|
'--cursor=10,20,31'},
|
2021-05-21 07:52:16 -06:00
|
|
|
mock_run.call_args[1])
|
2021-05-07 15:07:37 -06:00
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2021-05-21 07:52:16 -06:00
|
|
|
function test.do_phase_ensure_cursor_is_at_upper_left()
|
|
|
|
local mock_run = mock.func()
|
|
|
|
mock.patch(b, 'run', mock_run,
|
2021-05-07 15:07:37 -06:00
|
|
|
function()
|
|
|
|
local spos = {x=11, y=20, z=30}
|
|
|
|
local epos = {x=10, y=21, z=31}
|
|
|
|
b.query(spos, epos, 'imaname')
|
2021-05-21 07:52:16 -06:00
|
|
|
expect.eq(1, mock_run.call_count)
|
|
|
|
expect.table_eq({'2', '2', '2', 'imaname', 'query',
|
2021-05-07 15:07:37 -06:00
|
|
|
'--cursor=10,20,30'},
|
2021-05-21 07:52:16 -06:00
|
|
|
mock_run.call_args[1])
|
2021-05-07 15:07:37 -06:00
|
|
|
end)
|
|
|
|
end
|
2021-09-09 01:46:33 -06:00
|
|
|
|
|
|
|
function test.get_filename()
|
|
|
|
local opts = {name='a', split_strategy='none'}
|
|
|
|
expect.eq('blueprints/a.csv', b.get_filename(opts, 'dig'))
|
|
|
|
|
|
|
|
opts = {name='a/', split_strategy='none'}
|
|
|
|
expect.eq('blueprints/a/a.csv', b.get_filename(opts, 'dig'))
|
|
|
|
|
|
|
|
opts = {name='a', split_strategy='phase'}
|
|
|
|
expect.eq('blueprints/a-dig.csv', b.get_filename(opts, 'dig'))
|
|
|
|
|
|
|
|
opts = {name='a/', split_strategy='phase'}
|
|
|
|
expect.eq('blueprints/a/a-dig.csv', b.get_filename(opts, 'dig'))
|
|
|
|
|
|
|
|
expect.error_match('could not parse basename', function()
|
|
|
|
b.get_filename({name='', split_strategy='none'})
|
|
|
|
end)
|
|
|
|
end
|