diff --git a/lua/fzfx/cfg/file_explorer.lua b/lua/fzfx/cfg/file_explorer.lua index 0818b3cbf..5807635a8 100644 --- a/lua/fzfx/cfg/file_explorer.lua +++ b/lua/fzfx/cfg/file_explorer.lua @@ -2,7 +2,7 @@ local str = require("fzfx.commons.str") local path = require("fzfx.commons.path") local fileio = require("fzfx.commons.fileio") -local constants = require("fzfx.lib.constants") +local consts = require("fzfx.lib.constants") local shells = require("fzfx.lib.shells") local log = require("fzfx.lib.log") local LogLevels = require("fzfx.lib.log").LogLevels @@ -81,137 +81,241 @@ M.variants = { }, } ---- @param ls_args "-lh"|"-lha" +--- @param opts {include_hidden:boolean?}? +--- @return "-lh"|"-lha" +M._parse_opts = function(opts) + opts = opts or {} + local include_hidden = opts.include_hidden or false + return include_hidden and "-lha" or "-lh" +end + +--- @param opts {include_hidden:boolean?}? --- @return fun(query:string, context:fzfx.FileExplorerPipelineContext):string? -M._make_file_explorer_provider = function(ls_args) +M._make_provider_lsd = function(opts) + local args = M._parse_opts(opts) + --- @param query string --- @param context fzfx.FileExplorerPipelineContext --- @return string? local function impl(query, context) - local cwd = fileio.readfile(context.cwd) - if constants.HAS_LSD then - return constants.HAS_ECHO - and string.format( - "echo %s && lsd %s --color=always --header -- %s", - shells.shellescape(cwd --[[@as string]]), - ls_args, - shells.shellescape(cwd --[[@as string]]) - ) - or string.format( - "lsd %s --color=always --header -- %s", - ls_args, - shells.shellescape(cwd --[[@as string]]) + local cwd = fileio.readfile(context.cwd) --[[@as string]] + return consts.HAS_ECHO + and string.format( + "echo %s && %s %s --color=always --header -- %s", + shells.shellescape(cwd), + consts.LSD, + args, + shells.shellescape(cwd) ) - elseif constants.HAS_EZA then - if str.endswith(ls_args, "a") then - ls_args = ls_args .. "a" - end - return constants.HAS_ECHO - and string.format( - "echo %s && %s --color=always %s -- %s", - shells.shellescape(cwd --[[@as string]]), - constants.EZA, - ls_args, - shells.shellescape(cwd --[[@as string]]) - ) - or string.format( - "%s --color=always %s -- %s", - constants.EZA, - ls_args, - shells.shellescape(cwd --[[@as string]]) + or string.format( + "%s %s --color=always --header -- %s", + consts.LSD, + args, + shells.shellescape(cwd) + ) + end + + return impl +end + +--- @param opts {include_hidden:boolean?}? +--- @return fun(query:string, context:fzfx.FileExplorerPipelineContext):string? +M._make_provider_eza = function(opts) + local args = M._parse_opts(opts) + + --- @param query string + --- @param context fzfx.FileExplorerPipelineContext + --- @return string? + local function impl(query, context) + local cwd = fileio.readfile(context.cwd) --[[@as string]] + if str.endswith(args, "a") then + -- eza need double 'a' to show '.' and '..' directories + args = args .. "a" + end + return consts.HAS_ECHO + and string.format( + "echo %s && %s --color=always %s -- %s", + shells.shellescape(cwd), + consts.EZA, + args, + shells.shellescape(cwd) ) - elseif constants.HAS_LS then - return constants.HAS_ECHO - and string.format( - "echo %s && ls --color=always %s %s", - shells.shellescape(cwd --[[@as string]]), - ls_args, - shells.shellescape(cwd --[[@as string]]) - ) - or string.format( - "ls --color=always %s %s", - ls_args, - shells.shellescape(cwd --[[@as string]]) + or string.format("%s --color=always %s -- %s", consts.EZA, args, shells.shellescape(cwd)) + end + + return impl +end + +--- @param opts {include_hidden:boolean?}? +--- @return fun(query:string, context:fzfx.FileExplorerPipelineContext):string? +M._make_provider_ls = function(opts) + local args = M._parse_opts(opts) + + --- @param query string + --- @param context fzfx.FileExplorerPipelineContext + --- @return string? + local function impl(query, context) + local cwd = fileio.readfile(context.cwd) --[[@as string]] + return consts.HAS_ECHO + and string.format( + "echo %s && %s --color=always %s %s", + shells.shellescape(cwd), + consts.LS, + args, + shells.shellescape(cwd) ) - else - log.echo(LogLevels.INFO, "no ls/eza/exa command found.") - return nil - end + or string.format("%s --color=always %s %s", consts.LS, args, shells.shellescape(cwd)) end return impl end +--- @return fun(query:string, context:fzfx.FileExplorerPipelineContext):string? +M._make_provider_dummy = function() + --- @param query string + --- @param context fzfx.FileExplorerPipelineContext + --- @return string? + local function impl(query, context) + log.echo(LogLevels.INFO, "no ls/eza/exa command found.") + return nil + end + + return impl +end + +--- @param opts {include_hidden:boolean?}? +--- @return fun(query:string, context:fzfx.FileExplorerPipelineContext):string? +M._make_provider = function(opts) + if consts.HAS_LSD then + return M._make_provider_lsd(opts) + elseif consts.HAS_EZA then + return M._make_provider_eza(opts) + elseif consts.HAS_LS then + return M._make_provider_ls(opts) + else + return M._make_provider_dummy() + end +end + M.providers = { filter_hidden = { key = "ctrl-r", - provider = M._make_file_explorer_provider("-lh"), + provider = M._make_provider(), provider_type = ProviderTypeEnum.COMMAND, }, include_hidden = { key = "ctrl-u", - provider = M._make_file_explorer_provider("-lha"), + provider = M._make_provider({ include_hidden = true }), provider_type = ProviderTypeEnum.COMMAND, }, } +M._DIRECTORY_PREVIEWER_LSD = { + consts.LSD, + "--color=always", + "-lha", + "--header", + "--", +} + +M._DIRECTORY_PREVIEWER_EZA = { + consts.EZA, + "--color=always", + "-lha", + "--", +} + +M._DIRECTORY_PREVIEWER_LS = { + consts.LS, + "--color=always", + "-lha", + "--", +} + +--- @param opts {lsd:boolean?,eza:boolean?,ls:boolean?}? +--- @return fun(filename:string):string[] +M._make_directory_previewer = function(opts) + opts = opts or {} + + local args + if opts.lsd then + args = vim.deepcopy(M._DIRECTORY_PREVIEWER_LSD) + elseif opts.eza then + args = vim.deepcopy(M._DIRECTORY_PREVIEWER_EZA) + elseif opts.ls then + args = vim.deepcopy(M._DIRECTORY_PREVIEWER_LS) + end + + --- @param filename string + --- @return string[] + local function impl(filename) + table.insert(args, filename) + return args + end + + return impl +end + --- @param filename string --- @return string[]|nil M._directory_previewer = function(filename) - if constants.HAS_LSD then - return { - "lsd", - "--color=always", - "-lha", - "--header", - "--", - filename, - } - elseif constants.HAS_EZA then - return { - constants.EZA, - "--color=always", - "-lha", - "--", - filename, - } - elseif vim.fn.executable("ls") > 0 then - return { "ls", "--color=always", "-lha", "--", filename } + local f + + if consts.HAS_LSD then + f = M._make_directory_previewer({ lsd = true }) + elseif consts.HAS_EZA then + f = M._make_directory_previewer({ eza = true }) + elseif consts.HAS_LS then + f = M._make_directory_previewer({ ls = true }) else log.echo(LogLevels.INFO, "no ls/eza/exa command found.") return nil end + + return f(filename) +end + +local parser +if consts.HAS_LSD then + parser = parsers_helper.parse_lsd +elseif consts.HAS_EZA then + parser = parsers_helper.parse_eza +else + parser = parsers_helper.parse_ls end --- @param line string --- @param context fzfx.FileExplorerPipelineContext --- @return string[]|nil -M._file_explorer_previewer = function(line, context) - local parsed = constants.HAS_LSD and parsers_helper.parse_lsd(line, context) - or ( - constants.HAS_EZA and parsers_helper.parse_eza(line, context) - or parsers_helper.parse_ls(line, context) - ) - if vim.fn.filereadable(parsed.filename) > 0 then +M._previewer = function(line, context) + local parsed = parser(line, context) + + if path.isfile(parsed.filename) then return previewers_helper.preview_files(parsed.filename) - elseif vim.fn.isdirectory(parsed.filename) > 0 then + elseif path.isdir(parsed.filename) then return M._directory_previewer(parsed.filename) else return nil end end -local previewer_label = constants.HAS_LSD and labels_helper.label_lsd - or (constants.HAS_EZA and labels_helper.label_eza or labels_helper.label_ls) +local previewer_label +if consts.HAS_LSD then + previewer_label = labels_helper.label_lsd +elseif consts.HAS_EZA then + previewer_label = labels_helper.label_eza +else + previewer_label = labels_helper.label_ls +end M.previewers = { filter_hidden = { - previewer = M._file_explorer_previewer, + previewer = M._previewer, previewer_type = PreviewerTypeEnum.COMMAND_LIST, previewer_label = previewer_label, }, include_hidden = { - previewer = M._file_explorer_previewer, + previewer = M._previewer, previewer_type = PreviewerTypeEnum.COMMAND_LIST, previewer_label = previewer_label, }, @@ -220,12 +324,9 @@ M.previewers = { --- @param line string --- @param context fzfx.FileExplorerPipelineContext M._cd_file_explorer = function(line, context) - local parsed = constants.HAS_LSD and parsers_helper.parse_lsd(line, context) - or ( - constants.HAS_EZA and parsers_helper.parse_eza(line, context) - or parsers_helper.parse_ls(line, context) - ) - if vim.fn.isdirectory(parsed.filename) > 0 then + local parsed = parser(line, context) + + if path.isdir(parsed.filename) then fileio.writefile(context.cwd, parsed.filename) end end @@ -233,21 +334,21 @@ end --- @param line string --- @param context fzfx.FileExplorerPipelineContext M._upper_file_explorer = function(line, context) - log.debug( - string.format( - "|_upper_file_explorer| line:%s, context:%s", - vim.inspect(line), - vim.inspect(context) - ) - ) + -- log.debug( + -- string.format( + -- "|_upper_file_explorer| line:%s, context:%s", + -- vim.inspect(line), + -- vim.inspect(context) + -- ) + -- ) local cwd = fileio.readfile(context.cwd) --[[@as string]] - log.debug("|_upper_file_explorer| cwd:" .. vim.inspect(cwd)) + -- log.debug("|_upper_file_explorer| cwd:" .. vim.inspect(cwd)) local target = vim.fn.fnamemodify(cwd, ":h") --[[@as string]] - log.debug("|_upper_file_explorer| target:" .. vim.inspect(target)) + -- log.debug("|_upper_file_explorer| target:" .. vim.inspect(target)) -- Windows root folder: `C:\` -- Unix/linux root folder: `/` - local root_len = constants.IS_WINDOWS and 3 or 1 - if vim.fn.isdirectory(target) > 0 and string.len(target) > root_len then + local root_dir_len = consts.IS_WINDOWS and 3 or 1 + if path.isdir(target) and string.len(target) > root_dir_len then fileio.writefile(context.cwd, target) end end @@ -276,10 +377,10 @@ M.fzf_opts = { { "--prompt", path.shorten() .. " > " }, function() local n = 0 - if constants.HAS_ECHO then + if consts.HAS_ECHO then n = n + 1 end - if constants.HAS_LSD or constants.HAS_EZA or constants.HAS_LS then + if consts.HAS_LSD or consts.HAS_EZA or consts.HAS_LS then n = n + 1 end return n > 0 and string.format("--header-lines=%d", n) or nil @@ -288,7 +389,7 @@ M.fzf_opts = { --- @alias fzfx.FileExplorerPipelineContext {bufnr:integer,winnr:integer,tabnr:integer,cwd:string} --- @return fzfx.FileExplorerPipelineContext -M._file_explorer_context_maker = function() +M._context_maker = function() local temp = vim.fn.tempname() fileio.writefile(temp --[[@as string]], vim.fn.getcwd() --[[@as string]]) local context = { @@ -301,7 +402,7 @@ M._file_explorer_context_maker = function() end M.other_opts = { - context_maker = M._file_explorer_context_maker, + context_maker = M._context_maker, } return M diff --git a/spec/cfg/file_explorer_spec.lua b/spec/cfg/file_explorer_spec.lua index 9413c8f2b..0174f2433 100644 --- a/spec/cfg/file_explorer_spec.lua +++ b/spec/cfg/file_explorer_spec.lua @@ -17,7 +17,7 @@ describe("fzfx.cfg.file_explorer", function() local str = require("fzfx.commons.str") local path = require("fzfx.commons.path") - local constants = require("fzfx.lib.constants") + local consts = require("fzfx.lib.constants") local contexts = require("fzfx.helper.contexts") local fzf_helpers = require("fzfx.detail.fzf_helpers") @@ -50,51 +50,172 @@ describe("fzfx.cfg.file_explorer", function() ".rw-r--r-- 28k linrongbin 8 Oct 11:37 README.md", "drwxr-xr-x - linrongbin 8 Oct 11:44 test", } - it("_file_explorer_context_maker", function() - local ctx = file_explorer_cfg._file_explorer_context_maker() - -- print(string.format("file explorer context:%s\n", vim.inspect(ctx))) + it("_context_maker", function() + local ctx = file_explorer_cfg._context_maker() assert_eq(type(ctx), "table") assert_true(ctx.bufnr > 0) assert_true(ctx.winnr > 0) assert_true(ctx.tabnr > 0) assert_true(vim.fn.filereadable(ctx.cwd) > 0) end) - it("_make_file_explorer_provider", function() - local ctx = file_explorer_cfg._file_explorer_context_maker() - local f1 = file_explorer_cfg._make_file_explorer_provider("-lh") + it("_parse_opts", function() + local actual1 = file_explorer_cfg._parse_opts() + assert_true(actual1 == "-lh") + local actual2 = file_explorer_cfg._parse_opts({}) + assert_true(actual2 == "-lh") + local actual3 = file_explorer_cfg._parse_opts({ include_hidden = false }) + assert_true(actual3 == "-lh") + local actual4 = file_explorer_cfg._parse_opts({ include_hidden = true }) + assert_true(actual4 == "-lha") + end) + it("_make_provider_lsd case-1", function() + local ctx = file_explorer_cfg._context_maker() + local f = file_explorer_cfg._make_provider_lsd() + assert_eq(type(f), "function") + local actual = f("", ctx) + print(string.format("_make_provider_lsd-1:%s\n", vim.inspect(actual))) + assert_eq(type(actual), "string") + assert_true(str.find(actual, "echo") > 0) + assert_true(str.find(actual, consts.LSD) > 0) + assert_true(str.find(actual, "-lh") > 0) + assert_true(str.find(actual, "-lha") == nil) + assert_true( + str.find( + actual, + path.normalize(vim.fn.getcwd(), { double_backslash = true, expand = true }) + ) > 0 + ) + end) + it("_make_provider_lsd case-2", function() + local ctx = file_explorer_cfg._context_maker() + local f = file_explorer_cfg._make_provider_lsd({ include_hidden = true }) + assert_eq(type(f), "function") + local actual2 = f("", ctx) + print(string.format("_make_provider_lsd-2:%s\n", vim.inspect(actual2))) + assert_eq(type(actual2), "string") + assert_true(str.find(actual2, "echo") > 0) + assert_true(str.find(actual2, consts.LSD) > 0) + assert_true(str.find(actual2, "-lha") > 0) + assert_true( + str.find( + actual2, + path.normalize(vim.fn.getcwd(), { double_backslash = true, expand = true }) + ) > 0 + ) + end) + it("_make_provider_eza case-1", function() + local ctx = file_explorer_cfg._context_maker() + local f = file_explorer_cfg._make_provider_eza() + assert_eq(type(f), "function") + local actual = f("", ctx) + print(string.format("_make_provider_eza-1:%s\n", vim.inspect(actual))) + assert_eq(type(actual), "string") + assert_true(str.find(actual, "echo") > 0) + assert_true(str.find(actual, consts.EZA) > 0) + assert_true(str.find(actual, "-lh") > 0) + assert_true(str.find(actual, "-lha") == nil) + assert_true( + str.find( + actual, + path.normalize(vim.fn.getcwd(), { double_backslash = true, expand = true }) + ) > 0 + ) + end) + it("_make_provider_eza case-2", function() + local ctx = file_explorer_cfg._context_maker() + local f = file_explorer_cfg._make_provider_eza({ include_hidden = true }) + assert_eq(type(f), "function") + local actual = f("", ctx) + print(string.format("_make_provider_eza-2:%s\n", vim.inspect(actual))) + assert_eq(type(actual), "string") + assert_true(str.find(actual, "echo") > 0) + assert_true(str.find(actual, consts.EZA) > 0) + assert_true(str.find(actual, "-lhaa") > 0) + assert_true( + str.find( + actual, + path.normalize(vim.fn.getcwd(), { double_backslash = true, expand = true }) + ) > 0 + ) + end) + it("_make_provider_ls case-1", function() + local ctx = file_explorer_cfg._context_maker() + local f = file_explorer_cfg._make_provider_ls() + assert_eq(type(f), "function") + local actual = f("", ctx) + print(string.format("_make_provider_ls-1:%s\n", vim.inspect(actual))) + assert_eq(type(actual), "string") + assert_true(str.find(actual, "echo") > 0) + assert_true(str.find(actual, consts.LS) > 0) + assert_true(str.find(actual, "-lh") > 0) + assert_true(str.find(actual, "-lha") == nil) + assert_true( + str.find( + actual, + path.normalize(vim.fn.getcwd(), { double_backslash = true, expand = true }) + ) > 0 + ) + end) + it("_make_provider_ls case-2", function() + local ctx = file_explorer_cfg._context_maker() + local f = file_explorer_cfg._make_provider_ls({ include_hidden = true }) + assert_eq(type(f), "function") + local actual = f("", ctx) + print(string.format("_make_provider_ls-2:%s\n", vim.inspect(actual))) + assert_eq(type(actual), "string") + assert_true(str.find(actual, "echo") > 0) + assert_true(str.find(actual, consts.LS) > 0) + assert_true(str.find(actual, "-lha") > 0) + assert_true( + str.find( + actual, + path.normalize(vim.fn.getcwd(), { double_backslash = true, expand = true }) + ) > 0 + ) + end) + it("_make_provider_dummy", function() + local ctx = file_explorer_cfg._context_maker() + local f = file_explorer_cfg._make_provider_dummy() + assert_eq(type(f), "function") + local actual = f("", ctx) + print(string.format("_make_provider_dummy-1:%s\n", vim.inspect(actual))) + assert_true(actual == nil) + end) + it("_make_provider", function() + local ctx = file_explorer_cfg._context_maker() + local f1 = file_explorer_cfg._make_provider() assert_eq(type(f1), "function") local actual1 = f1("", ctx) - -- print( - -- string.format( - -- "file explorer provider1:%s\n", - -- vim.inspect(actual1) - -- ) - -- ) + print(string.format("_make_provider-1:%s\n", vim.inspect(actual1))) assert_eq(type(actual1), "string") assert_true(str.find(actual1, "echo") > 0) - assert_true( - type(str.find(actual1, "eza")) == "number" or type(str.find(actual1, "ls")) == "number" - ) + if consts.HAS_LSD then + assert_true(str.find(actual1, consts.LSD) > 0) + elseif consts.HAS_EZA then + assert_true(str.find(actual1, consts.EZA) > 0) + else + assert_true(str.find(actual1, consts.LS) > 0) + end assert_true( str.find( actual1, path.normalize(vim.fn.getcwd(), { double_backslash = true, expand = true }) ) > 0 ) - local f2 = file_explorer_cfg._make_file_explorer_provider("-lha") + + local f2 = file_explorer_cfg._make_provider({ include_hidden = true }) assert_eq(type(f2), "function") local actual2 = f2("", ctx) - -- print( - -- string.format( - -- "file explorer provider2:%s\n", - -- vim.inspect(actual2) - -- ) - -- ) + print(string.format("_make_provider-2:%s\n", vim.inspect(actual1))) assert_eq(type(actual2), "string") assert_true(str.find(actual2, "echo") > 0) - assert_true( - type(str.find(actual2, "eza")) == "number" or type(str.find(actual2, "ls")) == "number" - ) + if consts.HAS_LSD then + assert_true(str.find(actual2, consts.LSD) > 0) + elseif consts.HAS_EZA then + assert_true(str.find(actual2, consts.EZA) > 0) + else + assert_true(str.find(actual2, consts.LS) > 0) + end assert_true( str.find( actual2, @@ -102,91 +223,124 @@ describe("fzfx.cfg.file_explorer", function() ) > 0 ) end) + it("_make_directory_previewer with lsd", function() + local input = "lua/fzfx/config.lua" + local f = file_explorer_cfg._make_directory_previewer({ lsd = true }) + local actual = f(input) + assert_eq(type(actual), "table") + local n = #file_explorer_cfg._DIRECTORY_PREVIEWER_LSD + for i = 1, n do + assert_eq(actual[i], file_explorer_cfg._DIRECTORY_PREVIEWER_LSD[i]) + end + assert_eq(actual[#actual], input) + end) + it("_make_directory_previewer with eza", function() + local input = "lua/fzfx/config.lua" + local f = file_explorer_cfg._make_directory_previewer({ eza = true }) + local actual = f(input) + assert_eq(type(actual), "table") + local n = #file_explorer_cfg._DIRECTORY_PREVIEWER_EZA + for i = 1, n do + assert_eq(actual[i], file_explorer_cfg._DIRECTORY_PREVIEWER_EZA[i]) + end + assert_eq(actual[#actual], input) + end) + it("_make_directory_previewer with ls", function() + local input = "lua/fzfx/config.lua" + local f = file_explorer_cfg._make_directory_previewer({ ls = true }) + local actual = f(input) + assert_eq(type(actual), "table") + local n = #file_explorer_cfg._DIRECTORY_PREVIEWER_LS + for i = 1, n do + assert_eq(actual[i], file_explorer_cfg._DIRECTORY_PREVIEWER_LS[i]) + end + assert_eq(actual[#actual], input) + end) it("_directory_previewer", function() - local actual = file_explorer_cfg._directory_previewer("lua/fzfx/config.lua") + local input = "lua/fzfx/config.lua" + local actual = file_explorer_cfg._directory_previewer(input) assert_eq(type(actual), "table") - if actual[1] == "lsd" then - assert_eq(actual[1], "lsd") - assert_eq(actual[2], "--color=always") - assert_eq(actual[3], "-lha") - assert_eq(actual[4], "--header") - assert_eq(actual[5], "--") - assert_eq(actual[6], "lua/fzfx/config.lua") + if consts.HAS_LSD then + local n = #file_explorer_cfg._DIRECTORY_PREVIEWER_LSD + for i = 1, n do + assert_eq(actual[i], file_explorer_cfg._DIRECTORY_PREVIEWER_LSD[i]) + end + assert_eq(actual[#actual], input) + elseif consts.HAS_EZA then + local n = #file_explorer_cfg._DIRECTORY_PREVIEWER_EZA + for i = 1, n do + assert_eq(actual[i], file_explorer_cfg._DIRECTORY_PREVIEWER_EZA[i]) + end + assert_eq(actual[#actual], input) else - assert_true(actual[1] == "eza" or actual[1] == "ls") - assert_eq(actual[2], "--color=always") - assert_eq(actual[3], "-lha") - assert_eq(actual[4], "--") - assert_eq(actual[5], "lua/fzfx/config.lua") + local n = #file_explorer_cfg._DIRECTORY_PREVIEWER_LS + for i = 1, n do + assert_eq(actual[i], file_explorer_cfg._DIRECTORY_PREVIEWER_LS[i]) + end + assert_eq(actual[#actual], input) end end) - it("_file_explorer_previewer", function() - local ctx = file_explorer_cfg._file_explorer_context_maker() - if constants.HAS_LSD then + it("_previewer", function() + local ctx = file_explorer_cfg._context_maker() + if consts.HAS_LSD then for _, line in ipairs(LSD_LINES) do - local actual = file_explorer_cfg._file_explorer_previewer(line, ctx) + local actual = file_explorer_cfg._previewer(line, ctx) if actual ~= nil then assert_eq(type(actual), "table") - assert_true(actual[1] == constants.BAT or actual[1] == "cat" or actual[1] == "lsd") + assert_true(actual[1] == consts.BAT or actual[1] == "cat" or actual[1] == "lsd") end end - elseif constants.HAS_EZA then + elseif consts.HAS_EZA then for _, line in ipairs(EZA_LINES) do - local actual = file_explorer_cfg._file_explorer_previewer(line, ctx) + local actual = file_explorer_cfg._previewer(line, ctx) if actual ~= nil then assert_eq(type(actual), "table") - assert_true( - actual[1] == constants.BAT or actual[1] == "cat" or actual[1] == constants.EZA - ) + assert_true(actual[1] == consts.BAT or actual[1] == "cat" or actual[1] == consts.EZA) end end else for _, line in ipairs(LS_LINES) do - local actual = file_explorer_cfg._file_explorer_previewer(line, ctx) + local actual = file_explorer_cfg._previewer(line, ctx) if actual ~= nil then assert_eq(type(actual), "table") - assert_true(actual[1] == constants.BAT or actual[1] == "cat" or actual[1] == "ls") + assert_true(actual[1] == consts.BAT or actual[1] == "cat" or actual[1] == "ls") end end end end) it("_cd_file_explorer", function() - local ctx = file_explorer_cfg._file_explorer_context_maker() - if constants.HAS_LSD then + local ctx = file_explorer_cfg._context_maker() + if consts.HAS_LSD then for _, line in ipairs(LSD_LINES) do - local actual = file_explorer_cfg._cd_file_explorer(line, ctx) - assert_true(actual == nil) + file_explorer_cfg._cd_file_explorer(line, ctx) end - elseif constants.HAS_EZA then + elseif consts.HAS_EZA then for _, line in ipairs(EZA_LINES) do - local actual = file_explorer_cfg._cd_file_explorer(line, ctx) - assert_true(actual == nil) + file_explorer_cfg._cd_file_explorer(line, ctx) end else for _, line in ipairs(LS_LINES) do - local actual = file_explorer_cfg._cd_file_explorer(line, ctx) - assert_true(actual == nil) + file_explorer_cfg._cd_file_explorer(line, ctx) end end + assert_true(true) end) it("_upper_file_explorer", function() - local ctx = file_explorer_cfg._file_explorer_context_maker() - if constants.HAS_LSD then + local ctx = file_explorer_cfg._context_maker() + if consts.HAS_LSD then for _, line in ipairs(LSD_LINES) do - local actual = file_explorer_cfg._upper_file_explorer(line, ctx) - assert_true(actual == nil) + file_explorer_cfg._upper_file_explorer(line, ctx) end - elseif constants.HAS_EZA then + elseif consts.HAS_EZA then for _, line in ipairs(EZA_LINES) do - local actual = file_explorer_cfg._upper_file_explorer(line, ctx) - assert_true(actual == nil) + file_explorer_cfg._upper_file_explorer(line, ctx) end else for _, line in ipairs(LS_LINES) do - local actual = file_explorer_cfg._upper_file_explorer(line, ctx) - assert_true(actual == nil) + file_explorer_cfg._upper_file_explorer(line, ctx) end end + assert_true(true) end) end) end)