update unit tests

develop
myk002 2021-09-10 14:44:24 -07:00 committed by Myk
parent 42e04fc6ec
commit 44a93fcb28
2 changed files with 47 additions and 29 deletions

@ -114,7 +114,7 @@ struct tile_context {
}; };
// the number of different strings we use is very small so we use a string cache // the number of different strings we use is very small so we use a string cache
// to limit the number of memory allocations we make. this significantly speeds // to limit the number of string instances we store. this significantly speeds
// up processing and allows us to handle very large maps (e.g. 16x16 embarks) // up processing and allows us to handle very large maps (e.g. 16x16 embarks)
// without running out of memory. // without running out of memory.
// if NULL is passed as the str, the cache is cleared // if NULL is passed as the str, the cache is cleared
@ -732,7 +732,7 @@ static bool write_blueprint(color_ostream &out,
return true; return true;
} }
void ensure_building(const df::coord &pos, tile_context &ctx) { static void ensure_building(const df::coord &pos, tile_context &ctx) {
if (ctx.b) if (ctx.b)
return; return;
ctx.b = Buildings::findAtTile(pos); ctx.b = Buildings::findAtTile(pos);
@ -792,7 +792,7 @@ static bool do_transform(color_ostream &out,
std::map<string, ofstream*> output_files; std::map<string, ofstream*> output_files;
for (blueprint_processor &processor : processors) { for (blueprint_processor &processor : processors) {
if (!write_blueprint(out, output_files, opts, processor, pretty)) if (!write_blueprint(out, output_files, opts, processor, pretty))
return false; break;
} }
for (auto &it : output_files) { for (auto &it : output_files) {
@ -800,7 +800,6 @@ static bool do_transform(color_ostream &out,
it.second->close(); it.second->close();
delete(it.second); delete(it.second);
} }
output_files.clear();
return true; return true;
} }

@ -4,7 +4,8 @@ local b = require('plugins.blueprint')
function test.parse_gui_commandline() function test.parse_gui_commandline()
local opts = {} local opts = {}
b.parse_gui_commandline(opts, {}) b.parse_gui_commandline(opts, {})
expect.table_eq({auto_phase=true, split_strategy='none', name='blueprint'}, expect.table_eq({auto_phase=true, format='minimal', split_strategy='none',
name='blueprint'},
opts) opts)
opts = {} opts = {}
@ -13,38 +14,56 @@ function test.parse_gui_commandline()
opts = {} opts = {}
b.parse_gui_commandline(opts, {'--help'}) b.parse_gui_commandline(opts, {'--help'})
expect.table_eq({help=true}, opts) expect.table_eq({help=true, format='minimal', split_strategy='none'}, opts)
opts = {} opts = {}
b.parse_gui_commandline(opts, {'-h'}) b.parse_gui_commandline(opts, {'-h'})
expect.table_eq({help=true}, opts) expect.table_eq({help=true, format='minimal', split_strategy='none'}, opts)
opts = {} opts = {}
mock.patch(dfhack.maps, 'isValidTilePos', mock.func(true), mock.patch(dfhack.maps, 'isValidTilePos', mock.func(true),
function() function()
b.parse_gui_commandline(opts, {'--cursor=1,2,3'}) b.parse_gui_commandline(opts, {'--cursor=1,2,3'})
end) end)
expect.table_eq({auto_phase=true, split_strategy='none', name='blueprint', expect.table_eq({auto_phase=true, format='minimal', split_strategy='none',
start={x=1,y=2,z=3}}, name='blueprint', start={x=1,y=2,z=3}},
opts)
opts = {}
b.parse_gui_commandline(opts, {'-fminimal'})
expect.table_eq({auto_phase=true, format='minimal', split_strategy='none',
name='blueprint'},
opts) opts)
opts = {}
b.parse_gui_commandline(opts, {'--format', 'pretty'})
expect.table_eq({auto_phase=true, format='pretty', split_strategy='none',
name='blueprint'},
opts)
opts = {}
expect.error_match('unknown format',
function() b.parse_gui_commandline(opts, {'-ffoo'}) end)
opts = {} opts = {}
b.parse_gui_commandline(opts, {'-tnone'}) b.parse_gui_commandline(opts, {'-tnone'})
expect.table_eq({auto_phase=true, split_strategy='none', name='blueprint'}, expect.table_eq({auto_phase=true, format='minimal', split_strategy='none',
name='blueprint'},
opts) opts)
opts = {} opts = {}
b.parse_gui_commandline(opts, {'--splitby', 'phase'}) b.parse_gui_commandline(opts, {'--splitby', 'phase'})
expect.table_eq({auto_phase=true, split_strategy='phase', name='blueprint'}, expect.table_eq({auto_phase=true, format='minimal', split_strategy='phase',
name='blueprint'},
opts) opts)
opts = {} opts = {}
expect.error_match('unknown split strategy', expect.error_match('unknown split_strategy',
function() b.parse_gui_commandline(opts, {'-tfoo'}) end) function() b.parse_gui_commandline(opts, {'-tfoo'}) end)
opts = {} opts = {}
b.parse_gui_commandline(opts, {'imaname'}) b.parse_gui_commandline(opts, {'imaname'})
expect.table_eq({auto_phase=true, split_strategy='none', expect.table_eq({auto_phase=true, format='minimal', split_strategy='none',
name='imaname'}, name='imaname'},
opts) opts)
@ -54,8 +73,8 @@ function test.parse_gui_commandline()
opts = {} opts = {}
b.parse_gui_commandline(opts, {'imaname', 'dig', 'query'}) b.parse_gui_commandline(opts, {'imaname', 'dig', 'query'})
expect.table_eq({auto_phase=false, split_strategy='none', name='imaname', expect.table_eq({auto_phase=false, format='minimal', split_strategy='none',
dig=true, query=true}, name='imaname', dig=true, query=true},
opts) opts)
opts = {} opts = {}
@ -67,44 +86,44 @@ end
function test.parse_commandline() function test.parse_commandline()
local opts = {} local opts = {}
b.parse_commandline(opts, '1', '2') b.parse_commandline(opts, '1', '2')
expect.table_eq({auto_phase=true, split_strategy='none', name='blueprint', expect.table_eq({auto_phase=true, format='minimal', split_strategy='none',
width=1, height=2, depth=1}, name='blueprint', width=1, height=2, depth=1},
opts) opts)
opts = {} opts = {}
b.parse_commandline(opts, '1', '2', '3') b.parse_commandline(opts, '1', '2', '3')
expect.table_eq({auto_phase=true, split_strategy='none', name='blueprint', expect.table_eq({auto_phase=true, format='minimal', split_strategy='none',
width=1, height=2, depth=3}, name='blueprint', width=1, height=2, depth=3},
opts) opts)
opts = {} opts = {}
b.parse_commandline(opts, '1', '2', '-3') b.parse_commandline(opts, '1', '2', '-3')
expect.table_eq({auto_phase=true, split_strategy='none', name='blueprint', expect.table_eq({auto_phase=true, format='minimal', split_strategy='none',
width=1, height=2, depth=-3}, name='blueprint', width=1, height=2, depth=-3},
opts) opts)
opts = {} opts = {}
b.parse_commandline(opts, '1', '2', 'imaname') b.parse_commandline(opts, '1', '2', 'imaname')
expect.table_eq({auto_phase=true, split_strategy='none', name='imaname', expect.table_eq({auto_phase=true, format='minimal', split_strategy='none',
width=1, height=2, depth=1}, name='imaname', width=1, height=2, depth=1},
opts) opts)
opts = {} opts = {}
b.parse_commandline(opts, '1', '2', '10imaname') b.parse_commandline(opts, '1', '2', '10imaname')
expect.table_eq({auto_phase=true, split_strategy='none', name='10imaname', expect.table_eq({auto_phase=true, format='minimal', split_strategy='none',
width=1, height=2, depth=1}, name='10imaname', width=1, height=2, depth=1},
opts, 'invalid depth is considered a basename') opts, 'invalid depth is considered a basename')
opts = {} opts = {}
b.parse_commandline(opts, '1', '2', '-10imaname') b.parse_commandline(opts, '1', '2', '-10imaname')
expect.table_eq({auto_phase=true, split_strategy='none', name='-10imaname', expect.table_eq({auto_phase=true, format='minimal', split_strategy='none',
width=1, height=2, depth=1}, name='-10imaname', width=1, height=2, depth=1},
opts, 'invalid negative depth is considered a basename') opts, 'invalid negative depth is considered a basename')
opts = {} opts = {}
b.parse_commandline(opts, '1', '2', '3', 'imaname') b.parse_commandline(opts, '1', '2', '3', 'imaname')
expect.table_eq({auto_phase=true, split_strategy='none', name='imaname', expect.table_eq({auto_phase=true, format='minimal', split_strategy='none',
width=1, height=2, depth=3}, name='imaname', width=1, height=2, depth=3},
opts) opts)
opts = {} opts = {}