diff --git a/lua/gopher/alternate.lua b/lua/gopher/alternate.lua index 8965d8d..c489377 100644 --- a/lua/gopher/alternate.lua +++ b/lua/gopher/alternate.lua @@ -1,6 +1,4 @@ -local alt = {} - -function alt.is_test_file() +local function is_test_file() local file = vim.fn.expand "%" if #file <= 1 then @@ -14,8 +12,8 @@ function alt.is_test_file() return file, (not is_test and is_source), is_test end -function alt.alternate() - local file, is_source, is_test = alt.is_test_file() +local function alternate() + local file, is_source, is_test = is_test_file() if not file then return nil end @@ -33,10 +31,12 @@ function alt.alternate() return alt_file end +local alt = {} + function alt.switch(cmd) cmd = cmd or "" - local alt_file = alt.alternate() + local alt_file = alternate() if #cmd <= 1 then local ocmd = "e " .. alt_file diff --git a/spec/integration/alternate_test.lua b/spec/integration/alternate_test.lua index 2607968..8fdc704 100644 --- a/spec/integration/alternate_test.lua +++ b/spec/integration/alternate_test.lua @@ -44,7 +44,7 @@ T["GoAlt"]["creates/opens sibling from source"] = function() local rs, alt = do_the_test("source", "GoAlt") t.eq(child.fn.expand "%:p", alt) - t.eq(child.fn.filereadable(alt), 0) + t.eq(child.fn.filereadable(alt), 1) t.cleanup(rs) t.deletefile(alt) @@ -54,7 +54,7 @@ T["GoAlt"]["toggles back when invoked on test file"] = function() local rs, src = do_the_test("test", "GoAlt") t.eq(child.fn.expand "%:p", src) - t.eq(child.fn.filereadable(src), 0) + t.eq(child.fn.filereadable(src), 1) t.cleanup(rs) t.deletefile(src)