From 126443a9acb00f3612cb6bed26d5a1462b896c32 Mon Sep 17 00:00:00 2001 From: Alistair-Afton Date: Wed, 16 Sep 2026 03:50:09 +0200 Subject: [PATCH] quickfort: remove dead code for retired query/config modes The query and config blueprint modes were retired in the v50 quickfort rewrite: parse_modeline() maps their modelines to "ignore", so the query.lua, config.lua, aliases.lua, and keycodes.lua modules have been unreachable ever since. aliases.lua still tried to load data/quickfort/aliases-common.txt, a file that no longer exists in installations (dfhack#5755). Also update the dormant unit tests that still exercised the removed modules and settings. --- changelog.txt | 1 + internal/quickfort/aliases.lua | 162 --------------------------- internal/quickfort/config.lua | 164 ---------------------------- internal/quickfort/keycodes.lua | 85 -------------- internal/quickfort/query.lua | 115 ------------------- quickfort.lua | 2 - test/quickfort/aliases_unit.lua | 115 ------------------- test/quickfort/keycodes_unit.lua | 67 ------------ test/quickfort/list_integration.lua | 14 +-- test/quickfort/quickfort_unit.lua | 6 +- test/quickfort/set_unit.lua | 96 +++------------- 11 files changed, 23 insertions(+), 804 deletions(-) delete mode 100644 internal/quickfort/aliases.lua delete mode 100644 internal/quickfort/config.lua delete mode 100644 internal/quickfort/keycodes.lua delete mode 100644 internal/quickfort/query.lua delete mode 100644 test/quickfort/aliases_unit.lua delete mode 100644 test/quickfort/keycodes_unit.lua diff --git a/changelog.txt b/changelog.txt index 1ed30ae501..9810be2ca0 100644 --- a/changelog.txt +++ b/changelog.txt @@ -43,6 +43,7 @@ Template for new versions: ## Removed - `confirm`: removed the ``squad-disband`` and ``hotkey-reset`` confirmations; the game asks for both itself now ("Really disband?" and "Really overwrite") +- `quickfort`: removed unreachable code left over from the retired query/config blueprint modes, including the reference to the nonexistent `data/quickfort/aliases-common.txt` file # 53.15-r2 diff --git a/internal/quickfort/aliases.lua b/internal/quickfort/aliases.lua deleted file mode 100644 index 27f63d11e7..0000000000 --- a/internal/quickfort/aliases.lua +++ /dev/null @@ -1,162 +0,0 @@ --- alias expansion logic for the quickfort script query module ---@ module = true - -if not dfhack_flags.module then - qerror('this script cannot be called directly') -end - -local quickfort_common = reqscript('internal/quickfort/common') -local quickfort_parse = reqscript('internal/quickfort/parse') -local quickfort_reader = reqscript('internal/quickfort/reader') - -local log = quickfort_common.log - -common_aliases_filename = dfhack.getHackPath()..'/data/quickfort/aliases-common.txt' -user_aliases_filename = 'dfhack-config/quickfort/aliases.txt' - --- special keycode shortcuts inherited from python quickfort. -local special_keys = { - ['&']={'Enter'}, - ['!']={'Ctrl'}, - ['~']={'Alt'}, - ['@']={'Shift','Enter'}, - ['^']={'ESC'}, - ['%']={'Wait'}, -} -local special_aliases = { - ExitMenu={'ESC'}, - ['r+']={'r','+','Enter'}, -} - --- pushes a collection of aliases on the stack. aliases are resolved with the --- definition nearest the top of the stack. --- note: this function overwrites the metatable of the passed-in aliases map -local function push_aliases(alias_ctx, aliases) - local prev = alias_ctx.stack - setmetatable(aliases, {prev=prev, - __index=function(_, key) return prev[key] end}) - alias_ctx.stack = aliases -end - -local function pop_aliases(alias_ctx) - alias_ctx.stack = getmetatable(alias_ctx.stack).prev -end - -local function push_aliases_reader(alias_ctx, reader) - local aliases, num_aliases = {}, 0 - local line = reader:get_next_row() - while line do - if quickfort_parse.parse_alias_combined(line, aliases) then - num_aliases = num_aliases + 1 - end - line = reader:get_next_row() - end - push_aliases(alias_ctx, aliases) - return num_aliases -end - -local function push_aliases_file(alias_ctx, filepath) - local num_aliases = push_aliases_reader(alias_ctx, - quickfort_reader.TextReader{filepath=filepath}) - log('read in %d aliases from "%s"', num_aliases, filepath) -end - -local function init_alias_ctx_base() - return {stack={}} -end - --- initializes a new alias_ctx with all aliases within scope -function init_alias_ctx(ctx) - local alias_ctx = init_alias_ctx_base() - push_aliases_file(alias_ctx, common_aliases_filename) - push_aliases_file(alias_ctx, user_aliases_filename) - if not ctx or not ctx.aliases then return end - local num_file_aliases = 0 - for _ in pairs(ctx.aliases) do num_file_aliases = num_file_aliases + 1 end - if num_file_aliases > 0 then - push_aliases(alias_ctx, ctx.aliases) - log('read in %d aliases from "%s"', - num_file_aliases, ctx.blueprint_name) - end - return alias_ctx -end - -local function process_text(alias_ctx, text, tokens, depth) - depth = depth or 1 - if depth > 50 then - qerror(string.format('alias maximum recursion depth exceeded (%d)', - depth)) - end - local alias_stack = alias_ctx.stack - local i = 1 - while i <= #text do - local next_char = text:sub(i, i) - local expansion, repetitions = {}, 1 - if next_char ~= '{' then - -- token is a special key or a key literal - expansion[1] = special_keys[next_char] or next_char - else - local etoken, params, reps, next_pos = - quickfort_parse.parse_extended_token(text, i) - if not special_aliases[etoken] and alias_stack[etoken] then - push_aliases(alias_ctx, params) - process_text(alias_ctx, alias_stack[etoken], expansion, depth+1) - pop_aliases(alias_ctx) - else - expansion[1] = special_aliases[etoken] or etoken - end - repetitions, i = reps, next_pos - 1 - end - for j=1,repetitions do - for k=1, #expansion do - if type(expansion[k]) == "string" then - tokens[#tokens+1] = expansion[k] - else - for _, token in ipairs(expansion[k]) do - tokens[#tokens+1] = token - end - end - end - end - i = i + 1 - end -end - --- expands aliases in a string and returns the individual key tokens. --- if the entirety of text matches an alias, expands the entire text as an alias --- otherwise, if the text contains a substring like '{alias}', matches the alias --- between the curly brackets and replaces the substring. Aliases themselves --- can contain other aliases, but must use the {} format if they do. Literal --- key names can also appear in curly brackets to allow the parser to recognize --- multi-character keys, such as '{F10}'. Anything in curly brackets can be --- followed by a number to indicate repetition. For example, '{Down 5}' --- indicates 'Down' 5 times. 'Numpad' is treated specially so that '{Numpad 8}' --- doesn't get expanded to 'Numpad' 8 times, but rather 'Numpad 8' once. You can --- repeat Numpad keys like this: '{Numpad 8 5}'. --- returns an array of character key tokens -function expand_aliases(alias_ctx, text) - local tokens, alias_stack = {}, alias_ctx.stack - if special_aliases[text] then - tokens = special_aliases[text] - elseif alias_stack[text] then - process_text(alias_ctx, alias_stack[text], tokens) - else - process_text(alias_ctx, text, tokens) - end - local expanded_text = table.concat(tokens, '') - if text ~= expanded_text then - log('expanded keys to: "%s"', table.concat(tokens, ' ')) - end - return tokens -end - -if dfhack.internal.IN_TEST then - unit_test_hooks = { - init_alias_ctx_base=init_alias_ctx_base, - push_aliases=push_aliases, - pop_aliases=pop_aliases, - push_aliases_reader=push_aliases_reader, - process_text=process_text, - expand_aliases=expand_aliases, - } -end diff --git a/internal/quickfort/config.lua b/internal/quickfort/config.lua deleted file mode 100644 index e56a19f094..0000000000 --- a/internal/quickfort/config.lua +++ /dev/null @@ -1,164 +0,0 @@ --- config mode-related logic for the quickfort script ---@ module = true - -if not dfhack_flags.module then - qerror('this script cannot be called directly') -end - -local gui = require('gui') -local guidm = require('gui.dwarfmode') -local quickfort_common = reqscript('internal/quickfort/common') -local quickfort_aliases = reqscript('internal/quickfort/aliases') -local quickfort_keycodes = reqscript('internal/quickfort/keycodes') -local quickfort_map = reqscript('internal/quickfort/map') -local quickfort_preview = reqscript('internal/quickfort/preview') -local quickfort_transform = reqscript('internal/quickfort/transform') - -local log = quickfort_common.log - -local dir_map = { - Up=quickfort_transform.unit_vectors.north, - Right=quickfort_transform.unit_vectors.east, - Down=quickfort_transform.unit_vectors.south, - Left=quickfort_transform.unit_vectors.west -} -local dir_revmap = { - [quickfort_transform.unit_vectors_revmap.north]='Up', - [quickfort_transform.unit_vectors_revmap.east]='Right', - [quickfort_transform.unit_vectors_revmap.south]='Down', - [quickfort_transform.unit_vectors_revmap.west]='Left' -} - -local function handle_modifiers(token, modifiers) - local token_lower = token:lower() - if token_lower == 'shift' or - token_lower == 'ctrl' or - token_lower == 'alt' then - modifiers[token_lower] = true - return true - end - if token_lower == 'wait' then - -- accepted for compatibility with Python Quickfort, but waiting has no - -- effect in DFHack quickfort. - return true - end - return false -end - -local function transform_token(ctx, token, transformable_dirs) - -- don't transform if the token is not a direction key or if we're not on - -- a map screen. note this is only a heuristic. there are dwarfmode screens - -- that can't move a cursor anyway. there are also dwarfmode screens where - -- the arrow keys change settings instead of move a cursor. however, these - -- screens (e.g. the hospital zone settings screen) are very unlikely to be - -- visited by a query or config blueprint. we can make this heuristic more - -- complicated if the above statement is proven incorrect. - if not transformable_dirs[token] or - not dfhack.gui.getCurFocus(true):startswith('dwarfmode') then - return token - end - local translated_dir = quickfort_transform.resolve_transformed_vector( - ctx, dir_map[token], dir_revmap) - if token ~= translated_dir then - log(('transforming cursor movement on map screen: %s -> %s') - :format(token, translated_dir)) - end - return translated_dir -end - -function do_query_config_blueprint(zlevel, grid, ctx, sidebar_mode, - pre_tile_fn, post_tile_fn, post_blueprint_fn) - local stats = ctx.stats - stats.query_config_keystrokes = stats.query_config_keystrokes or - {label='Keystrokes sent', value=0, always=true} - - quickfort_keycodes.init_keycodes() - local alias_ctx = quickfort_aliases.init_alias_ctx(ctx) - - local dry_run = ctx.dry_run - local saved_mode = df.global.plotinfo.main.mode - if not dry_run and saved_mode ~= sidebar_mode then - guidm.enterSidebarMode(sidebar_mode) - end - - -- record which direction keys are potentially transformed so we only - -- look up whether we need to transform when we absolutely have to - local transformable_dirs = {} - for k,v in pairs(dir_map) do - if k ~= quickfort_transform.resolve_transformed_vector(ctx, v, - dir_revmap) then - transformable_dirs[k] = true - end - end - - for y, row in pairs(grid) do - for x, cell_and_text in pairs(row) do - local tile_ctx = {pos=xyz2pos(x, y, zlevel)} - tile_ctx.cell,tile_ctx.text = cell_and_text.cell,cell_and_text.text - local is_valid_tile = not pre_tile_fn or pre_tile_fn(ctx, tile_ctx) - quickfort_preview.set_preview_tile(ctx, tile_ctx.pos, is_valid_tile) - if not is_valid_tile then goto continue end - local modifiers = {} -- tracks ctrl, shift, and alt modifiers - local tokens = quickfort_aliases.expand_aliases(alias_ctx, - tile_ctx.text) - for _,token in ipairs(tokens) do - if handle_modifiers(token, modifiers) then goto continue2 end - token = transform_token(ctx, token, transformable_dirs) - local kcodes = quickfort_keycodes.get_keycodes(token, modifiers) - if not kcodes then - qerror(string.format( - 'unknown alias or keycode: "%s"', token)) - end - if not dry_run then - gui.simulateInput(dfhack.gui.getCurViewscreen(true), kcodes) - end - modifiers = {} - stats.query_config_keystrokes.value = - stats.query_config_keystrokes.value + 1 - ::continue2:: - end - if post_tile_fn then post_tile_fn(ctx, tile_ctx) end - ::continue:: - end - end - - if not dry_run then - if saved_mode ~= sidebar_mode - and guidm.SIDEBAR_MODE_KEYS[saved_mode] then - guidm.enterSidebarMode(saved_mode) - end - if post_blueprint_fn then post_blueprint_fn(ctx) end - end -end - -local function config_pre_tile_fn(ctx, tile_ctx) - log('applying spreadsheet cell %s with text "%s"', - tile_ctx.cell, tile_ctx.text) - return true -end - -local function config_post_tile_fn(ctx, tile_ctx) - if ctx.dry_run then return end - if df.global.plotinfo.main.mode ~= df.ui_sidebar_mode.Default then - qerror(string.format( - 'expected to be at map screen, but we seem to be in mode "%s"; ' .. - 'there is likely a problem with the blueprint text in ' .. - 'cell %s: "%s" (do you need a "^" at the end to get back to the ' .. - 'main map?)', - df.ui_sidebar_mode[df.global.plotinfo.main.mode], - tile_ctx.cell, tile_ctx.text)) - end -end - -function do_run(zlevel, grid, ctx) - do_query_config_blueprint(zlevel, grid, ctx, df.ui_sidebar_mode.Default, - config_pre_tile_fn, config_post_tile_fn) -end - -function do_orders() - log('nothing to do for blueprints in mode: config') -end - -function do_undo() - log('cannot undo blueprints for mode: config') -end diff --git a/internal/quickfort/keycodes.lua b/internal/quickfort/keycodes.lua deleted file mode 100644 index ad9dcdfdf1..0000000000 --- a/internal/quickfort/keycodes.lua +++ /dev/null @@ -1,85 +0,0 @@ --- keycode conversion logic for the quickfort script query module ---@ module = true - -if not dfhack_flags.module then - qerror('this script cannot be called directly') -end - -local quickfort_common = reqscript('internal/quickfort/common') -local quickfort_reader = reqscript('internal/quickfort/reader') -local log = quickfort_common.log - -local keycodes_file = 'data/init/interface.txt' - -local interface_txt_mtime, keycodes = nil, nil - --- number keys (but not numpad number keys) can appear as either "SYM:0:%d" or --- "KEY:%d". we arbitrarily choose to standardize on the "KEY" format so we know --- how to find the mappings later. -local function canonicalize_keyspec(keyspec) - local _, _, number = string.find(keyspec, '^%[SYM:0:(%d)%]') - if not number then return keyspec end - return ('[KEY:%d]'):format(number) -end - -local function reload_keycodes(reader) - -- add "Empty" pseudo-keycode that expands to a 0-length list - keycodes = {['[SYM:0:Empty]']={}} - local num_keycodes, cur_binding, line = 0, nil, reader:get_next_row() - while line do - local _, _, binding = string.find(line, '^%[BIND:([0-9_A-Z]+):.*') - if binding then - cur_binding = binding - elseif cur_binding and #line > 0 then - -- it's a keycode definition - line = canonicalize_keyspec(line) - if not keycodes[line] then keycodes[line] = {} end - table.insert(keycodes[line], cur_binding) - num_keycodes = num_keycodes + 1 - end - line = reader:get_next_row() - end - return num_keycodes -end - -function init_keycodes() - local mtime = dfhack.filesystem.mtime(keycodes_file) - if interface_txt_mtime == mtime then return end - local num_keycodes = - reload_keycodes(quickfort_reader.TextReader{filepath=keycodes_file}) - log('successfully read in %d keycodes from "%s"', - num_keycodes, keycodes_file) - interface_txt_mtime = mtime -end - --- code is an interface key name from the keycodes_file, like 'a' or 'Down', --- with shift, ctrl, or alt modifiers recorded in the modifiers table. --- returns a list of all the keycodes that the input could translate to -function get_keycodes(code, modifiers) - if not code then return nil end - local mod = 0 - if modifiers['shift'] then - mod = 1 - end - if modifiers['ctrl'] then - mod = mod + 2 - end - if modifiers['alt'] then - mod = mod + 4 - end - local key = nil - if mod == 0 and #code == 1 then - key = string.format('[KEY:%s]', code) - else - key = string.format('[SYM:%d:%s]', mod, code) - end - return keycodes[key] -end - -if dfhack.internal.IN_TEST then - unit_test_hooks = { - canonicalize_keyspec=canonicalize_keyspec, - reload_keycodes=reload_keycodes, - get_keycodes=get_keycodes, - } -end diff --git a/internal/quickfort/query.lua b/internal/quickfort/query.lua deleted file mode 100644 index 2e1e63b637..0000000000 --- a/internal/quickfort/query.lua +++ /dev/null @@ -1,115 +0,0 @@ --- query mode-related logic for the quickfort script ---@ module = true - -if not dfhack_flags.module then - qerror('this script cannot be called directly') -end - -local guidm = require('gui.dwarfmode') -local utils = require('utils') -local quickfort_common = reqscript('internal/quickfort/common') -local quickfort_config = reqscript('internal/quickfort/config') -local quickfort_map = reqscript('internal/quickfort/map') -local quickfort_set = reqscript('internal/quickfort/set') - -local log = quickfort_common.log - -local function is_queryable_tile(pos) - local flags, occupancy = dfhack.maps.getTileFlags(pos) - if not flags then return false end - return not flags.hidden and - (occupancy.building ~= 0 or - dfhack.buildings.findCivzonesAt(pos)) -end - -local function query_pre_tile_fn(ctx, tile_ctx) - local pos = tile_ctx.pos - if not quickfort_set.get_setting('query_unsafe') and - not is_queryable_tile(pos) then - if not ctx.quiet then - dfhack.printerr(string.format( - 'no building at coordinates (%d, %d, %d); skipping ' .. - 'text in spreadsheet cell %s: "%s"', - pos.x, pos.y, pos.z, tile_ctx.cell, tile_ctx.text)) - end - ctx.stats.query_skipped_tiles.value = - ctx.stats.query_skipped_tiles.value + 1 - return false - end - if not ctx.dry_run then - quickfort_map.move_cursor(pos) - tile_ctx.focus_string = dfhack.gui.getCurFocus(true) - end - log('applying spreadsheet cell %s with text "%s" to map ' .. - 'coordinates (%d, %d, %d)', - tile_ctx.cell, tile_ctx.text, pos.x, pos.y, pos.z) - return true -end - --- If a tile starts or ends with one of these focus strings, the start and end --- focus strings can differ without us flagging it as an error. -local exempt_focus_strings = utils.invert({ - 'dwarfmode/QueryBuilding/Destroying', - }) - -local function query_post_tile_fn(ctx, tile_ctx) - ctx.stats.query_tiles.value = ctx.stats.query_tiles.value + 1 - if ctx.dry_run or quickfort_set.get_setting('query_unsafe') then - return - end - local pos, focus_string = tile_ctx.pos, tile_ctx.focus_string - local cursor = guidm.getCursorPos() - if not cursor then - qerror(string.format( - 'expected to be at cursor position (%d, %d, %d) on ' .. - 'screen "%s" but there is no active cursor; there ' .. - 'is likely a problem with the blueprint text in ' .. - 'cell %s: "%s" (do you need a "q" at the end to get ' .. - 'back into query mode?)', - pos.x, pos.y, pos.z, focus_string, tile_ctx.cell, tile_ctx.text)) - elseif not same_xyz(pos, cursor) then - qerror(string.format( - 'expected to be at cursor position (%d, %d, %d) on ' .. - 'screen "%s" but cursor is at (%d, %d, %d); there ' .. - 'is likely a problem with the blueprint text in ' .. - 'cell %s: "%s"', pos.x, pos.y, pos.z, focus_string, - cursor.x, cursor.y, cursor.z, tile_ctx.cell, tile_ctx.text)) - end - local new_focus_string = dfhack.gui.getCurFocus(true) - local is_exempt = exempt_focus_strings[focus_string] or - exempt_focus_strings[new_focus_string] - if not is_exempt and focus_string ~= new_focus_string then - qerror(string.format( - 'expected to be at cursor position (%d, %d, %d) on ' .. - 'screen "%s" but screen is "%s"; there is likely a ' .. - 'problem with the blueprint text in cell %s: "%s" ' .. - '(do you need a "^" at the end to escape back to ' .. - 'the map screen?)', pos.x, pos.y, pos.z, focus_string, - new_focus_string, tile_ctx.cell, tile_ctx.text)) - end -end - -local function query_post_blueprint_fn(ctx) - quickfort_map.move_cursor(ctx.cursor) -end - -function do_run(zlevel, grid, ctx) - local stats = ctx.stats - stats.query_tiles = stats.query_tiles or {label='Tiles configured', value=0} - stats.query_skipped_tiles = stats.query_skipped_tiles - or {label='Tiles not configured due to missing buildings', value=0} - - quickfort_config.do_query_config_blueprint(zlevel, grid, ctx, - df.ui_sidebar_mode.QueryBuilding, - query_pre_tile_fn, - query_post_tile_fn, - query_post_blueprint_fn) -end - -function do_orders() - log('nothing to do for blueprints in mode: query') -end - -function do_undo() - log('cannot undo blueprints for mode: query') -end diff --git a/quickfort.lua b/quickfort.lua index 5930b565f2..3082bcab10 100644 --- a/quickfort.lua +++ b/quickfort.lua @@ -15,7 +15,6 @@ function refresh_scripts() -- reqscript all internal files here, even if they're not directly used by this -- top-level file. this ensures modified transitive dependencies are properly -- reloaded when this script is run. - reqscript('internal/quickfort/aliases') reqscript('internal/quickfort/api') reqscript('internal/quickfort/build') reqscript('internal/quickfort/building') @@ -23,7 +22,6 @@ function refresh_scripts() reqscript('internal/quickfort/command') reqscript('internal/quickfort/common') reqscript('internal/quickfort/dig') - reqscript('internal/quickfort/keycodes') reqscript('internal/quickfort/list') reqscript('internal/quickfort/map') reqscript('internal/quickfort/meta') diff --git a/test/quickfort/aliases_unit.lua b/test/quickfort/aliases_unit.lua deleted file mode 100644 index c01bf52f4d..0000000000 --- a/test/quickfort/aliases_unit.lua +++ /dev/null @@ -1,115 +0,0 @@ -local a = reqscript('internal/quickfort/aliases').unit_test_hooks -local quickfort_reader = reqscript('internal/quickfort/reader') - -function test.module() - expect.error_match( - 'this script cannot be called directly', - function() dfhack.run_script('internal/quickfort/aliases') end) -end - -function test.push_pop() - local alias_ctx = a.init_alias_ctx_base() - - expect.table_eq({'a','a'}, a.expand_aliases(alias_ctx, 'aa')) - a.push_aliases(alias_ctx, {aa='zz'}) - expect.table_eq({'z','z'}, a.expand_aliases(alias_ctx, 'aa')) - expect.table_eq({'b','b'}, a.expand_aliases(alias_ctx, 'bb')) - a.push_aliases(alias_ctx, {aa='yy', bb='ww'}) - expect.table_eq({'y','y'}, a.expand_aliases(alias_ctx, 'aa')) - expect.table_eq({'w','w'}, a.expand_aliases(alias_ctx, 'bb')) - expect.table_eq({'c','c'}, a.expand_aliases(alias_ctx, 'cc')) - a.pop_aliases(alias_ctx) - expect.table_eq({'z','z'}, a.expand_aliases(alias_ctx, 'aa')) - expect.table_eq({'b','b'}, a.expand_aliases(alias_ctx, 'bb')) - a.push_aliases(alias_ctx, {cc='xx'}) - expect.table_eq({'x','x'}, a.expand_aliases(alias_ctx, 'cc')) -end - -MockFile = defclass(MockFile, nil) -MockFile.ATTRS{i=0, lines={}} -function MockFile:close() end -function MockFile:reset(lines) self.lines, self.i = lines, 0 end -function MockFile:read() - self.i = self.i + 1 - return self.lines[self.i] -end - -local function mock_open() - return MockFile{} -end - -function test.push_aliases_reader() - local mock_reader = - quickfort_reader.TextReader{filepath='f', open_fn=mock_open} - local mock_file = mock_reader.source - local alias_ctx = a.init_alias_ctx_base() - - expect.eq(0, a.push_aliases_reader(alias_ctx, mock_reader)) - - mock_file:reset({'# comment', '#comment: withcolon', 'aa: zz'}) - expect.eq(1, a.push_aliases_reader(alias_ctx, mock_reader)) - expect.table_eq({'z','z'}, a.expand_aliases(alias_ctx, 'aa')) -end - -function test.process_text() - local alias_ctx = a.init_alias_ctx_base() - - expect.error(function() a.process_text(alias_ctx, 'text', {}, 51) end) - - a.push_aliases(alias_ctx, {aa='{bb}',bb='{aa}'}) - expect.error_match( - 'recursion', - function() a.process_text(alias_ctx, '{aa}', {}) end) - - alias_ctx = a.init_alias_ctx_base() - a.push_aliases(alias_ctx, {aa='{bb}', bb='x{cc}x', cc='o'}) - - local tokens = {} - a.process_text(alias_ctx, 'send!&', tokens) - expect.table_eq({'s','e','n','d','Ctrl','Enter'}, tokens) - - tokens = {} - a.process_text(alias_ctx, '!n@', tokens) - expect.table_eq({'Ctrl','n','Shift','Enter'}, tokens) - - tokens = {} - a.process_text(alias_ctx, '{Enter 3}{ExitMenu}', tokens) - expect.table_eq({'Enter','Enter','Enter','ESC'}, tokens) - - tokens = {} - a.process_text(alias_ctx, '{q 3}{cc 2}{za 2}', tokens) - expect.table_eq({'q','q','q','o','o','za','za'}, tokens) - - tokens = {} - a.process_text(alias_ctx, 'i{aa 3}', tokens) - expect.table_eq({'i','x','o','x','x','o','x','x','o','x'}, tokens) - - tokens = {} - a.process_text(alias_ctx, '{aa bb=q 3}', tokens) - expect.table_eq({'q','q','q'}, tokens) - - tokens = {} - a.process_text(alias_ctx, '{aa cc=q 3}', tokens) - expect.table_eq({'x','q','x','x','q','x','x','q','x'}, tokens) - - tokens = {} - a.process_text(alias_ctx, '{aa bb=q}{aa cc=u}', tokens) - expect.table_eq({'q','x','u','x'}, tokens) - - tokens = {} - a.process_text(alias_ctx, '{aa cc={dd} dd=v}', tokens) - expect.table_eq({'x','v','x'}, tokens) -end - -function test.expand_aliases() - local alias_ctx = a.init_alias_ctx_base() - - expect.table_eq({'r','+','Enter'}, a.expand_aliases(alias_ctx, 'r+')) - expect.table_eq({'r','+','Enter'}, a.expand_aliases(alias_ctx, '{r+}')) - - a.push_aliases(alias_ctx, {aa='{bb}', bb='x{cc}x', cc='o'}) - expect.table_eq({'o'}, a.expand_aliases(alias_ctx, 'cc')) - expect.table_eq({'x','o','x'}, a.expand_aliases(alias_ctx, 'aa')) - - expect.table_eq({'l','i','t'}, a.expand_aliases(alias_ctx, 'lit')) -end diff --git a/test/quickfort/keycodes_unit.lua b/test/quickfort/keycodes_unit.lua deleted file mode 100644 index e030dc4f95..0000000000 --- a/test/quickfort/keycodes_unit.lua +++ /dev/null @@ -1,67 +0,0 @@ -local k = reqscript('internal/quickfort/keycodes').unit_test_hooks -local quickfort_reader = reqscript('internal/quickfort/reader') - -function test.module() - expect.error_match( - 'this script cannot be called directly', - function() dfhack.run_script('internal/quickfort/keycodes') end) -end - -MockFile = defclass(MockFile, nil) -MockFile.ATTRS{i=0, lines={}} -function MockFile:close() end -function MockFile:reset(lines) self.lines, self.i = lines, 0 end -function MockFile:read() - self.i = self.i + 1 - return self.lines[self.i] -end - -local function mock_open() - return MockFile{} -end - -function test.canonicalize_keyspec() - expect.eq('somethingrandom', k.canonicalize_keyspec('somethingrandom')) - expect.eq('[KEY:a]', k.canonicalize_keyspec('[KEY:a]')) - expect.eq('[KEY:5]', k.canonicalize_keyspec('[KEY:5]')) - expect.eq('[KEY:5]', k.canonicalize_keyspec('[SYM:0:5]')) - expect.eq('[SYM:1:5]', k.canonicalize_keyspec('[SYM:1:5]')) -end - -function test.reload_and_get_keycodes() - local reader = quickfort_reader.TextReader{open_fn=mock_open} - - expect.eq(0, k.reload_keycodes(reader), 'empty keycode input') - expect.nil_(k.get_keycodes()) - expect.nil_(k.get_keycodes('a', {})) - - reader.source:reset( - { - '[BIND:A_KEY:IGNORE]', - '[KEY:a]', - '[BIND:B_KEY:IGNORE]', - '[KEY:b]', - '[KEY:B]', - '[SYM:0:5]', - '[BIND:C_KEY:IGNORE]', - '[KEY:5]', - '[BIND:D_KEY:IGNORE]', - '[SYM:1:d]', - '[BIND:E_KEY:IGNORE]', - '[SYM:2:d]', - '[BIND:F_KEY:IGNORE]', - '[SYM:4:d]', - '[BIND:G_KEY:IGNORE]', - '[SYM:6:d]', - }) - expect.eq(9, k.reload_keycodes(reader), 'full keycode input') - expect.nil_(k.get_keycodes('A', {})) - expect.table_eq({'A_KEY'}, k.get_keycodes('a', {})) - expect.table_eq({'B_KEY'}, k.get_keycodes('b', {})) - expect.table_eq({'B_KEY'}, k.get_keycodes('B', {})) - expect.table_eq({'B_KEY', 'C_KEY'}, k.get_keycodes('5', {})) - expect.table_eq({'D_KEY'}, k.get_keycodes('d', {shift=true})) - expect.table_eq({'E_KEY'}, k.get_keycodes('d', {ctrl=true})) - expect.table_eq({'F_KEY'}, k.get_keycodes('d', {alt=true})) - expect.table_eq({'G_KEY'}, k.get_keycodes('d', {ctrl=true, alt=true})) -end diff --git a/test/quickfort/list_integration.lua b/test/quickfort/list_integration.lua index 61d809d552..caad8cf740 100644 --- a/test/quickfort/list_integration.lua +++ b/test/quickfort/list_integration.lua @@ -53,10 +53,8 @@ function test.all_modes() build='/2', place='/3', zone='/4', - query='/5', - config='/6', - meta='/7', - notes='/8', + meta='/5', + notes='/6', } test_modes(fname, modes_and_labels) end @@ -68,8 +66,6 @@ function test.all_modes_separate_sheets() build='build_sheet', place='place_sheet', zone='zone_sheet', - query='query_sheet', - config='config_sheet', meta='meta_sheet', notes='notes_sheet', } @@ -83,10 +79,8 @@ function test.all_modes_single_sheet() build='Sheet1/2', place='Sheet1/3', zone='Sheet1/4', - query='Sheet1/5', - config='Sheet1/6', - meta='Sheet1/7', - notes='Sheet1/8', + meta='Sheet1/5', + notes='Sheet1/6', } test_modes(fname, modes_and_labels) end diff --git a/test/quickfort/quickfort_unit.lua b/test/quickfort/quickfort_unit.lua index 3b3e5dabd3..dcce1e5242 100644 --- a/test/quickfort/quickfort_unit.lua +++ b/test/quickfort/quickfort_unit.lua @@ -47,19 +47,19 @@ function test.apply_blueprint_all_ctx_params() aliases={somealias='ab{analias}'}, dry_run=true, quiet=false, preserve_engravings=df.item_quality.Masterful}) - q.apply_blueprint{mode='query', data=data, command='undo', + q.apply_blueprint{mode='dig', data=data, command='undo', pos={x=2, y=1, z=-1}, aliases={somealias='ab{analias}'}, dry_run=true, verbose=true} expect.eq(2, mock_do_command_raw.call_count) local args = mock_do_command_raw.call_args[1] - expect.eq(args[1], 'query') + expect.eq(args[1], 'dig') expect.eq(args[2], 1) expect.table_eq(args[3], {[21]={[10]={cell='8,20,2', text='somekeys'}}}) expect.table_eq(args[4], expected_ctx) args = mock_do_command_raw.call_args[2] - expect.eq(args[1], 'query') + expect.eq(args[1], 'dig') expect.eq(args[2], 2) expect.table_eq(args[3], {[10]={[22]={cell='20,9,3', text='somealias'}}}) expect.table_eq(args[4], expected_ctx) diff --git a/test/quickfort/set_unit.lua b/test/quickfort/set_unit.lua index b055ee2a23..d03e94f01c 100644 --- a/test/quickfort/set_unit.lua +++ b/test/quickfort/set_unit.lua @@ -1,4 +1,3 @@ -local quickfort_reader = reqscript('internal/quickfort/reader') local quickfort_set = reqscript('internal/quickfort/set') local s = quickfort_set.unit_test_hooks @@ -15,14 +14,14 @@ function test.settings_have_defaults() end function test.get_setting() - expect.eq('blueprints', s.get_setting('blueprints_dir')) - s.set_setting('blueprints_dir', '/tmp') - expect.eq('/tmp', s.get_setting('blueprints_dir')) + expect.eq('dfhack-config/blueprints', s.get_setting('blueprints_user_dir')) + s.set_setting('blueprints_user_dir', '/tmp') + expect.eq('/tmp', s.get_setting('blueprints_user_dir')) s.reset_to_defaults() - expect.false_(s.get_setting('query_unsafe')) - s.set_setting('query_unsafe', 'true') - expect.true_(s.get_setting('query_unsafe')) + expect.false_(s.get_setting('force_marker_mode')) + s.set_setting('force_marker_mode', 'true') + expect.true_(s.get_setting('force_marker_mode')) expect.error_match('invalid setting', function() s.get_setting('unknown_setting') end) @@ -33,11 +32,11 @@ function test.set_setting() function() s.set_setting('unknown_setting', '-') end) expect.error_match('invalid boolean', - function() s.set_setting('query_unsafe', '-') end) - s.set_setting('query_unsafe', 'true') - expect.true_(s.get_setting('query_unsafe')) - s.set_setting('query_unsafe', 'false') - expect.false_(s.get_setting('query_unsafe')) + function() s.set_setting('force_marker_mode', '-') end) + s.set_setting('force_marker_mode', 'true') + expect.true_(s.get_setting('force_marker_mode')) + s.set_setting('force_marker_mode', 'false') + expect.false_(s.get_setting('force_marker_mode')) expect.error_match('invalid integer', function() s.set_setting('stockpiles_max_bins', '-') end) @@ -46,48 +45,10 @@ function test.set_setting() s.set_setting('stockpiles_max_bins', '11.999') expect.eq(11, s.get_setting('stockpiles_max_bins')) - s.set_setting('blueprints_dir', '.') - expect.eq('.', s.get_setting('blueprints_dir')) - s.set_setting('blueprints_dir', '/tmp') - expect.eq('/tmp', s.get_setting('blueprints_dir')) -end - -MockFile = defclass(MockFile, nil) -MockFile.ATTRS{i=0, lines={}} -function MockFile:close() end -function MockFile:reset(lines) self.lines, self.i = lines, 0 end -function MockFile:read() - self.i = self.i + 1 - return self.lines[self.i] -end - -local function mock_open() - return MockFile{} -end - -function test.read_settings() - local mock_reader = - quickfort_reader.TextReader{filepath='f', open_fn=mock_open} - local mock_file = mock_reader.source - - local mock_print = mock.func() - mock.patch(quickfort_set, 'print', mock_print, - function() - s.reset_to_defaults() - mock_file:reset{'#comment', - 'query_unsafe=true', - 'blueprints_dir = a dir'} - s.read_settings(mock_reader) - expect.true_(s.get_setting('query_unsafe')) - expect.eq('a dir', s.get_setting('blueprints_dir')) - end) - - mock.patch(quickfort_set, 'print', mock_print, - function() - mock_file:reset{'bad_var=something'} - expect.error_match('invalid setting', - function() s.read_settings(mock_reader) end) - end) + s.set_setting('blueprints_user_dir', '.') + expect.eq('.', s.get_setting('blueprints_user_dir')) + s.set_setting('blueprints_user_dir', '/tmp') + expect.eq('/tmp', s.get_setting('blueprints_user_dir')) end function test.reset_to_defaults() @@ -96,30 +57,3 @@ function test.reset_to_defaults() s.reset_to_defaults() expect.eq(-1, s.get_setting('stockpiles_max_bins')) end - -function test.reset_settings() - local mock_reader = - quickfort_reader.TextReader{filepath='f', open_fn=mock_open} - local mock_file = mock_reader.source - - local mock_print = mock.func() - mock.patch(quickfort_set, 'print', mock_print, - function() - mock_file:reset{'query_unsafe=true'} - s.reset_to_defaults() - expect.false_(s.get_setting('query_unsafe')) - s.set_setting('blueprints_dir', '.') - s.reset_settings(function() return mock_reader end) - expect.true_(s.get_setting('query_unsafe')) - expect.eq('blueprints', s.get_setting('blueprints_dir')) - end) - - mock_print = mock.func() - mock.patch(quickfort_set, 'print', mock_print, - function() - s.reset_settings(function() qerror('err') end) - expect.eq(1, mock_print.call_count) - expect.eq('err; using internal defaults', - mock_print.call_args[1][1]) - end) -end