fix: Make tests pass again

This commit is contained in:
TJ DeVries
2020-09-17 21:51:14 -04:00
parent 93369e1488
commit f3fc1ca8c1
3 changed files with 31 additions and 32 deletions

View File

@@ -671,8 +671,6 @@ pickers.entry_manager = function(max_results, set_entry)
return setmetatable({ return setmetatable({
add_entry = function(self, score, entry) add_entry = function(self, score, entry)
assert(type(entry) == "table", "entry must be a table by the time it reaches here")
score = score or 0 score = score or 0
for index, item in ipairs(entry_state) do for index, item in ipairs(entry_state) do
@@ -727,6 +725,10 @@ pickers.entry_manager = function(max_results, set_entry)
return (entry_state[index] or {}).entry return (entry_state[index] or {}).entry
end, end,
get_score = function(_, index)
return (entry_state[index] or {}).score
end,
find_entry = function(_, entry) find_entry = function(_, entry)
if entry == nil then if entry == nil then
return nil return nil

View File

@@ -55,7 +55,6 @@ sorters.get_ngram_sorter = function()
return score return score
end) end)
print(prompt, line, result)
return ok and result or 1 return ok and result or 1
end end
} }
@@ -209,13 +208,6 @@ sorters.get_fuzzy_file = function(opts)
} }
end end
sorters.get_norcalli_sorter = function()
vim.api.nvim_err_writeln(
"get_norcalli_sorter() is changed to get_generic_fuzzy_sorter()"
)
return sorters.get_generic_fuzzy_sorter()
end
sorters.get_generic_fuzzy_sorter = function() sorters.get_generic_fuzzy_sorter = function()
local ngramlen = 2 local ngramlen = 2

View File

@@ -1,5 +1,7 @@
require('plenary.test_harness'):setup_busted() require('plenary.test_harness'):setup_busted()
local assert = require('luassert')
local log = require('telescope.log') local log = require('telescope.log')
log.level = 'info' log.level = 'info'
-- log.use_console = false -- log.use_console = false
@@ -24,7 +26,7 @@ describe('Picker', function()
manager:add_entry(1, "hello") manager:add_entry(1, "hello")
assert.are.same(1, manager:_get_state()[1].score) assert.are.same(1, manager:get_score(1))
end) end)
it('works with two entries', function() it('works with two entries', function()
@@ -33,8 +35,8 @@ describe('Picker', function()
manager:add_entry(1, "hello") manager:add_entry(1, "hello")
manager:add_entry(2, "later") manager:add_entry(2, "later")
assert.are.same("hello", manager:get_ordinal(1)) assert.are.same("hello", manager:get_entry(1))
assert.are.same("later", manager:get_ordinal(2)) assert.are.same("later", manager:get_entry(2))
end) end)
it('calls functions when inserting', function() it('calls functions when inserting', function()
@@ -62,8 +64,8 @@ describe('Picker', function()
manager:add_entry(5, "worse result") manager:add_entry(5, "worse result")
manager:add_entry(2, "better result") manager:add_entry(2, "better result")
assert.are.same("better result", manager:get_ordinal(1)) assert.are.same("better result", manager:get_entry(1))
assert.are.same("worse result", manager:get_ordinal(2)) assert.are.same("worse result", manager:get_entry(2))
-- once to insert "worse" -- once to insert "worse"
-- once to insert "better" -- once to insert "better"
@@ -77,7 +79,7 @@ describe('Picker', function()
manager:add_entry(2, "better result") manager:add_entry(2, "better result")
manager:add_entry(5, "worse result") manager:add_entry(5, "worse result")
assert.are.same("better result", manager:get_ordinal(1)) assert.are.same("better result", manager:get_entry(1))
-- once to insert "worse" -- once to insert "worse"
-- once to insert "better" -- once to insert "better"
@@ -210,21 +212,21 @@ describe('Picker', function()
end) end)
describe('Sorters', function() describe('Sorters', function()
describe('norcalli_sorter', function() describe('generic_fuzzy_sorter', function()
it('sort matches well', function() it('sort matches well', function()
local sorter = require('telescope.sorters').get_norcalli_sorter() local sorter = require('telescope.sorters').get_generic_fuzzy_sorter()
local exact_match = sorter:score('hello', 'hello') local exact_match = sorter:score('hello', 'hello')
local no_match = sorter:score('abcdef', 'ghijkl') local no_match = sorter:score('abcdef', 'ghijkl')
local ok_match = sorter:score('abcdef', 'ab') local ok_match = sorter:score('abcdef', 'ab')
assert(exact_match < no_match) assert(exact_match < no_match, "exact match better than no match")
assert(exact_match < ok_match) assert(exact_match < ok_match, "exact match better than ok match")
assert(ok_match < no_match) assert(ok_match < no_match, "ok match better than no match")
end) end)
it('sorts multiple finds better', function() it('sorts multiple finds better', function()
local sorter = require('telescope.sorters').get_norcalli_sorter() local sorter = require('telescope.sorters').get_generic_fuzzy_sorter()
local multi_match = sorter:score('generics', 'exercises/generics/generics2.rs') local multi_match = sorter:score('generics', 'exercises/generics/generics2.rs')
local one_match = sorter:score('abcdef', 'exercises/generics/README.md') local one_match = sorter:score('abcdef', 'exercises/generics/README.md')
@@ -245,27 +247,30 @@ describe('Sorters', function()
exact_match < no_match, exact_match < no_match,
string.format("Exact match better than no match: %s %s", exact_match, no_match) string.format("Exact match better than no match: %s %s", exact_match, no_match)
) )
assert(exact_match < ok_match, "Exact match better than OK match") assert(
exact_match < ok_match,
string.format("Exact match better than OK match: %s %s", exact_match, ok_match)
)
assert(ok_match < no_match, "OK match better than no match") assert(ok_match < no_match, "OK match better than no match")
end) end)
it('sorts matches after last os sep better', function() it('sorts matches after last os sep better', function()
local sorter = require('telescope.sorters').get_fuzzy_file() local sorter = require('telescope.sorters').get_fuzzy_file()
local exact_match = sorter:score('aaa/bbb', 'aaa') local better_match = sorter:score('aaa', 'bbb/aaa')
local ok_match = sorter:score('bbb/aaa', 'aaa') local worse_match = sorter:score('aaa', 'aaa/bbb')
assert(exact_match < ok_match, "Exact match better than OK match") assert(better_match < worse_match, "Final match should be stronger")
end) end)
-- it('sorts multiple finds better', function() it('sorts multiple finds better', function()
-- local sorter = require('telescope.sorters').get_fuzzy_file() local sorter = require('telescope.sorters').get_fuzzy_file()
-- local multi_match = sorter:score('generics', 'exercises/generics/generics2.rs') local multi_match = sorter:score('generics', 'exercises/generics/generics2.rs')
-- local one_match = sorter:score('abcdef', 'exercises/generics/README.md') local one_match = sorter:score('abcdef', 'exercises/generics/README.md')
-- assert(multi_match < one_match) assert(multi_match < one_match)
-- end) end)
end) end)
end) end)