diff --git a/plugins/blueprint.cpp b/plugins/blueprint.cpp index 1e70f0879..49d0da5d2 100644 --- a/plugins/blueprint.cpp +++ b/plugins/blueprint.cpp @@ -114,7 +114,7 @@ struct tile_context { }; // 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) // without running out of memory. // if NULL is passed as the str, the cache is cleared @@ -732,7 +732,7 @@ static bool write_blueprint(color_ostream &out, 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) return; ctx.b = Buildings::findAtTile(pos); @@ -792,7 +792,7 @@ static bool do_transform(color_ostream &out, std::map output_files; for (blueprint_processor &processor : processors) { if (!write_blueprint(out, output_files, opts, processor, pretty)) - return false; + break; } for (auto &it : output_files) { @@ -800,7 +800,6 @@ static bool do_transform(color_ostream &out, it.second->close(); delete(it.second); } - output_files.clear(); return true; } diff --git a/test/plugins/blueprint.lua b/test/plugins/blueprint.lua index 4e2933cb2..76003b35b 100644 --- a/test/plugins/blueprint.lua +++ b/test/plugins/blueprint.lua @@ -4,7 +4,8 @@ local b = require('plugins.blueprint') function test.parse_gui_commandline() local 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 = {} @@ -13,38 +14,56 @@ function test.parse_gui_commandline() opts = {} b.parse_gui_commandline(opts, {'--help'}) - expect.table_eq({help=true}, opts) + expect.table_eq({help=true, format='minimal', split_strategy='none'}, opts) opts = {} b.parse_gui_commandline(opts, {'-h'}) - expect.table_eq({help=true}, opts) + expect.table_eq({help=true, format='minimal', split_strategy='none'}, 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, split_strategy='none', name='blueprint', - start={x=1,y=2,z=3}}, + expect.table_eq({auto_phase=true, format='minimal', split_strategy='none', + 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 = {} + 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 = {} 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 = {} 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 = {} - expect.error_match('unknown split strategy', + expect.error_match('unknown split_strategy', function() b.parse_gui_commandline(opts, {'-tfoo'}) end) opts = {} 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'}, opts) @@ -54,8 +73,8 @@ function test.parse_gui_commandline() opts = {} b.parse_gui_commandline(opts, {'imaname', 'dig', 'query'}) - expect.table_eq({auto_phase=false, split_strategy='none', name='imaname', - dig=true, query=true}, + expect.table_eq({auto_phase=false, format='minimal', split_strategy='none', + name='imaname', dig=true, query=true}, opts) opts = {} @@ -67,44 +86,44 @@ end function test.parse_commandline() local opts = {} b.parse_commandline(opts, '1', '2') - expect.table_eq({auto_phase=true, split_strategy='none', name='blueprint', - width=1, height=2, depth=1}, + expect.table_eq({auto_phase=true, format='minimal', split_strategy='none', + name='blueprint', width=1, height=2, depth=1}, opts) opts = {} b.parse_commandline(opts, '1', '2', '3') - expect.table_eq({auto_phase=true, split_strategy='none', name='blueprint', - width=1, height=2, depth=3}, + expect.table_eq({auto_phase=true, format='minimal', split_strategy='none', + name='blueprint', width=1, height=2, depth=3}, opts) opts = {} b.parse_commandline(opts, '1', '2', '-3') - expect.table_eq({auto_phase=true, split_strategy='none', name='blueprint', - width=1, height=2, depth=-3}, + expect.table_eq({auto_phase=true, format='minimal', split_strategy='none', + name='blueprint', width=1, height=2, depth=-3}, opts) opts = {} b.parse_commandline(opts, '1', '2', 'imaname') - expect.table_eq({auto_phase=true, split_strategy='none', name='imaname', - width=1, height=2, depth=1}, + expect.table_eq({auto_phase=true, format='minimal', split_strategy='none', + name='imaname', width=1, height=2, depth=1}, opts) opts = {} b.parse_commandline(opts, '1', '2', '10imaname') - expect.table_eq({auto_phase=true, split_strategy='none', name='10imaname', - width=1, height=2, depth=1}, + expect.table_eq({auto_phase=true, format='minimal', split_strategy='none', + 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, split_strategy='none', name='-10imaname', - width=1, height=2, depth=1}, + expect.table_eq({auto_phase=true, format='minimal', split_strategy='none', + 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, split_strategy='none', name='imaname', - width=1, height=2, depth=3}, + expect.table_eq({auto_phase=true, format='minimal', split_strategy='none', + name='imaname', width=1, height=2, depth=3}, opts) opts = {}