Skip to content

Commit

Permalink
test: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
delphinus committed Aug 6, 2023
1 parent 6084b95 commit 19aa0b1
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 162 deletions.
2 changes: 1 addition & 1 deletion lua/frecency/async_finder.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local a = require "plenary.async"
local log = require "plenary.log"

---@class AsyncFinder: TelescopeFinder
---@class AsyncFinder
---@field closed boolean
---@field entries FrecencyEntry[]
---@field rx { recv: fun(): table }
Expand Down
1 change: 1 addition & 0 deletions lua/frecency/entry_maker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ end

---@class FrecencyEntry
---@field filename string
---@field index integer
---@field ordinal string
---@field name string
---@field score number
Expand Down
84 changes: 84 additions & 0 deletions lua/frecency/tests/async_finder_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---@diagnostic disable: invisible
local AsyncFinder = require "frecency.async_finder"
local FS = require "frecency.fs"
local EntryMaker = require "frecency.entry_maker"
local WebDevicons = require "frecency.web_devicons"
local util = require "frecency.tests.util"

---@param files string[]
---@param initial_results string[]
---@param callback fun(async_finder: AsyncFinder, dir: PlenaryPath): nil
local function with_files(files, initial_results, callback)
local dir, close = util.make_tree(files)
local fs = FS.new { ignore_patterns = {} }
local web_devicons = WebDevicons.new(true)
local function filepath_formatter()
return function(name)
return name
end
end
local entry_maker = EntryMaker.new(fs, web_devicons, { show_filter_column = false, show_scores = false })
:create(filepath_formatter, dir:absolute())
local async_finder = AsyncFinder.new(fs, dir:absolute(), entry_maker, initial_results)
callback(async_finder, dir)
close()
end

describe("async_finder", function()
---@diagnostic disable-next-line: param-type-mismatch
if vim.version.eq(vim.version(), "0.9.0") then
it("skips these tests for v0.9.0", function()
assert.are.same(true, true)
end)
return
end

describe("with no initial_results", function()
local files = { "hoge1.txt", "hoge2.txt" }
with_files(files, {}, function(async_finder, dir)
local count = { process_result = 0, process_complete = 0 }
local results
local function run()
results = {}
async_finder("", function(result)
count.process_result = count.process_result + 1
table.insert(results, result.filename)
end, function()
count.process_complete = count.process_complete + 1
end)
end

describe("when run at the first time", function()
run()
it("called process_result() at 2 times", function()
assert.are.same(2, count.process_result)
end)
it("called process_complete() at 1 time", function()
assert.are.same(1, count.process_complete)
end)
it("returns the whole results", function()
assert.are.same({
dir:joinpath("hoge1.txt").filename,
dir:joinpath("hoge2.txt").filename,
}, results)
end)
end)

describe("when run again", function()
run()
it("called process_result() at 4 times", function()
assert.are.same(4, count.process_result)
end)
it("called process_complete() at 1 time", function()
assert.are.same(2, count.process_complete)
end)
it("returns the same results", function()
assert.are.same({
dir:joinpath("hoge1.txt").filename,
dir:joinpath("hoge2.txt").filename,
}, results)
end)
end)
end)
end)
end)
161 changes: 0 additions & 161 deletions lua/frecency/tests/finder_spec.lua

This file was deleted.

0 comments on commit 19aa0b1

Please sign in to comment.