chore: use stylua for formatting (#1040)
* chore: stylua job and config * reformat with stylua
This commit is contained in:
@@ -1,70 +1,92 @@
|
||||
local actions = require('telescope.actions')
|
||||
local action_set = require('telescope.actions.set')
|
||||
local actions = require "telescope.actions"
|
||||
local action_set = require "telescope.actions.set"
|
||||
|
||||
local transform_mod = require('telescope.actions.mt').transform_mod
|
||||
local transform_mod = require("telescope.actions.mt").transform_mod
|
||||
|
||||
local eq = function(a, b)
|
||||
assert.are.same(a, b)
|
||||
end
|
||||
|
||||
describe('actions', function()
|
||||
it('should allow creating custom actions', function()
|
||||
describe("actions", function()
|
||||
it("should allow creating custom actions", function()
|
||||
local a = transform_mod {
|
||||
x = function() return 5 end,
|
||||
x = function()
|
||||
return 5
|
||||
end,
|
||||
}
|
||||
|
||||
|
||||
eq(5, a.x())
|
||||
end)
|
||||
|
||||
it('allows adding actions', function()
|
||||
it("allows adding actions", function()
|
||||
local a = transform_mod {
|
||||
x = function() return "x" end,
|
||||
y = function() return "y" end,
|
||||
x = function()
|
||||
return "x"
|
||||
end,
|
||||
y = function()
|
||||
return "y"
|
||||
end,
|
||||
}
|
||||
|
||||
local x_plus_y = a.x + a.y
|
||||
|
||||
eq({"x", "y"}, {x_plus_y()})
|
||||
eq({ "x", "y" }, { x_plus_y() })
|
||||
end)
|
||||
|
||||
it('ignores nils from added actions', function()
|
||||
it("ignores nils from added actions", function()
|
||||
local a = transform_mod {
|
||||
x = function() return "x" end,
|
||||
y = function() return "y" end,
|
||||
nil_maker = function() return nil end,
|
||||
x = function()
|
||||
return "x"
|
||||
end,
|
||||
y = function()
|
||||
return "y"
|
||||
end,
|
||||
nil_maker = function()
|
||||
return nil
|
||||
end,
|
||||
}
|
||||
|
||||
local x_plus_y = a.x + a.nil_maker + a.y
|
||||
|
||||
eq({"x", "y"}, {x_plus_y()})
|
||||
eq({ "x", "y" }, { x_plus_y() })
|
||||
end)
|
||||
|
||||
it('allows overriding an action', function()
|
||||
it("allows overriding an action", function()
|
||||
local a = transform_mod {
|
||||
x = function() return "x" end,
|
||||
y = function() return "y" end,
|
||||
x = function()
|
||||
return "x"
|
||||
end,
|
||||
y = function()
|
||||
return "y"
|
||||
end,
|
||||
}
|
||||
|
||||
-- actions.file_goto_selection_edit:replace(...)
|
||||
a.x:replace(function() return "foo" end)
|
||||
a.x:replace(function()
|
||||
return "foo"
|
||||
end)
|
||||
eq("foo", a.x())
|
||||
|
||||
a._clear()
|
||||
eq("x", a.x())
|
||||
end)
|
||||
|
||||
it('allows overriding an action only in specific cases with if', function()
|
||||
it("allows overriding an action only in specific cases with if", function()
|
||||
local a = transform_mod {
|
||||
x = function(e) return e * 10 end,
|
||||
y = function() return "y" end,
|
||||
x = function(e)
|
||||
return e * 10
|
||||
end,
|
||||
y = function()
|
||||
return "y"
|
||||
end,
|
||||
}
|
||||
|
||||
-- actions.file_goto_selection_edit:replace(...)
|
||||
a.x:replace_if(
|
||||
function(e) return e > 0 end,
|
||||
function(e) return (e / 10) end
|
||||
)
|
||||
a.x:replace_if(function(e)
|
||||
return e > 0
|
||||
end, function(e)
|
||||
return (e / 10)
|
||||
end)
|
||||
eq(-100, a.x(-10))
|
||||
eq(10, a.x(100))
|
||||
eq(1, a.x(10))
|
||||
@@ -73,16 +95,28 @@ describe('actions', function()
|
||||
eq(100, a.x(10))
|
||||
end)
|
||||
|
||||
it('allows overriding an action only in specific cases with mod', function()
|
||||
it("allows overriding an action only in specific cases with mod", function()
|
||||
local a = transform_mod {
|
||||
x = function(e) return e * 10 end,
|
||||
y = function() return "y" end,
|
||||
x = function(e)
|
||||
return e * 10
|
||||
end,
|
||||
y = function()
|
||||
return "y"
|
||||
end,
|
||||
}
|
||||
|
||||
-- actions.file_goto_selection_edit:replace(...)
|
||||
a.x:replace_map {
|
||||
[function(e) return e > 0 end] = function(e) return (e / 10) end,
|
||||
[function(e) return e == 0 end] = function(e) return (e + 10) end,
|
||||
[function(e)
|
||||
return e > 0
|
||||
end] = function(e)
|
||||
return (e / 10)
|
||||
end,
|
||||
[function(e)
|
||||
return e == 0
|
||||
end] = function(e)
|
||||
return (e + 10)
|
||||
end,
|
||||
}
|
||||
|
||||
eq(-100, a.x(-10))
|
||||
@@ -94,33 +128,51 @@ describe('actions', function()
|
||||
eq(100, a.x(10))
|
||||
end)
|
||||
|
||||
it('continuous replacement', function()
|
||||
it("continuous replacement", function()
|
||||
local a = transform_mod {
|
||||
x = function() return "cleared" end,
|
||||
y = function() return "y" end,
|
||||
x = function()
|
||||
return "cleared"
|
||||
end,
|
||||
y = function()
|
||||
return "y"
|
||||
end,
|
||||
}
|
||||
|
||||
-- Replace original, which becomes new fallback
|
||||
a.x:replace(function() return "negative" end)
|
||||
a.x:replace(function()
|
||||
return "negative"
|
||||
end)
|
||||
|
||||
-- actions.file_goto_selection_edit:replace(...)
|
||||
a.x:replace_map {
|
||||
[function(e) return e > 0 end] = function(e) return "positive" end,
|
||||
[function(e) return e == 0 end] = function(e) return "zero" end,
|
||||
[function(e)
|
||||
return e > 0
|
||||
end] = function(e)
|
||||
return "positive"
|
||||
end,
|
||||
[function(e)
|
||||
return e == 0
|
||||
end] = function(e)
|
||||
return "zero"
|
||||
end,
|
||||
}
|
||||
|
||||
eq("positive", a.x(10))
|
||||
eq("zero" , a.x(0))
|
||||
eq("zero", a.x(0))
|
||||
eq("negative", a.x(-10))
|
||||
|
||||
a._clear()
|
||||
eq("cleared", a.x(10))
|
||||
end)
|
||||
|
||||
it('enhance.pre', function()
|
||||
it("enhance.pre", function()
|
||||
local a = transform_mod {
|
||||
x = function() return "x" end,
|
||||
y = function() return "y" end,
|
||||
x = function()
|
||||
return "x"
|
||||
end,
|
||||
y = function()
|
||||
return "y"
|
||||
end,
|
||||
}
|
||||
|
||||
local called_pre = false
|
||||
@@ -134,10 +186,14 @@ describe('actions', function()
|
||||
eq(true, called_pre)
|
||||
end)
|
||||
|
||||
it('enhance.post', function()
|
||||
it("enhance.post", function()
|
||||
local a = transform_mod {
|
||||
x = function() return "x" end,
|
||||
y = function() return "y" end,
|
||||
x = function()
|
||||
return "x"
|
||||
end,
|
||||
y = function()
|
||||
return "y"
|
||||
end,
|
||||
}
|
||||
|
||||
local called_post = false
|
||||
@@ -151,10 +207,14 @@ describe('actions', function()
|
||||
eq(true, called_post)
|
||||
end)
|
||||
|
||||
it('can call both', function()
|
||||
it("can call both", function()
|
||||
local a = transform_mod {
|
||||
x = function() return "x" end,
|
||||
y = function() return "y" end,
|
||||
x = function()
|
||||
return "x"
|
||||
end,
|
||||
y = function()
|
||||
return "y"
|
||||
end,
|
||||
}
|
||||
|
||||
local called_count = 0
|
||||
@@ -171,10 +231,14 @@ describe('actions', function()
|
||||
eq(2, called_count)
|
||||
end)
|
||||
|
||||
it('can call both even when combined', function()
|
||||
it("can call both even when combined", function()
|
||||
local a = transform_mod {
|
||||
x = function() return "x" end,
|
||||
y = function() return "y" end,
|
||||
x = function()
|
||||
return "x"
|
||||
end,
|
||||
y = function()
|
||||
return "y"
|
||||
end,
|
||||
}
|
||||
|
||||
local called_count = 0
|
||||
@@ -188,7 +252,7 @@ describe('actions', function()
|
||||
}
|
||||
|
||||
a.x:enhance {
|
||||
post = count_inc
|
||||
post = count_inc,
|
||||
}
|
||||
|
||||
local x_plus_y = a.x + a.y
|
||||
@@ -197,10 +261,14 @@ describe('actions', function()
|
||||
eq(3, called_count)
|
||||
end)
|
||||
|
||||
it('clears enhance', function()
|
||||
it("clears enhance", function()
|
||||
local a = transform_mod {
|
||||
x = function() return "x" end,
|
||||
y = function() return "y" end,
|
||||
x = function()
|
||||
return "x"
|
||||
end,
|
||||
y = function()
|
||||
return "y"
|
||||
end,
|
||||
}
|
||||
|
||||
local called_post = false
|
||||
@@ -217,31 +285,41 @@ describe('actions', function()
|
||||
eq(false, called_post)
|
||||
end)
|
||||
|
||||
it('handles passing arguments', function()
|
||||
it("handles passing arguments", function()
|
||||
local a = transform_mod {
|
||||
x = function(bufnr) return string.format("bufnr: %s") end,
|
||||
x = function(bufnr)
|
||||
return string.format "bufnr: %s"
|
||||
end,
|
||||
}
|
||||
|
||||
a.x:replace(function(bufnr) return string.format("modified: %s", bufnr) end)
|
||||
a.x:replace(function(bufnr)
|
||||
return string.format("modified: %s", bufnr)
|
||||
end)
|
||||
eq("modified: 5", a.x(5))
|
||||
end)
|
||||
|
||||
describe('action_set', function()
|
||||
it('can replace `action_set.edit`', function()
|
||||
action_set.edit:replace(function(_, arg) return "replaced:" .. arg end)
|
||||
describe("action_set", function()
|
||||
it("can replace `action_set.edit`", function()
|
||||
action_set.edit:replace(function(_, arg)
|
||||
return "replaced:" .. arg
|
||||
end)
|
||||
eq("replaced:edit", actions.file_edit())
|
||||
eq("replaced:vnew", actions.file_vsplit())
|
||||
end)
|
||||
|
||||
it('handles backwards compat with select and edit files', function()
|
||||
it("handles backwards compat with select and edit files", function()
|
||||
-- Reproduce steps:
|
||||
-- In config, we have { ["<CR>"] = actions.select, ... }
|
||||
-- In caller, we have actions._goto:replace(...)
|
||||
-- Person calls `select`, does not see update
|
||||
action_set.edit:replace(function(_, arg) return "default_to_edit:" .. arg end)
|
||||
action_set.edit:replace(function(_, arg)
|
||||
return "default_to_edit:" .. arg
|
||||
end)
|
||||
eq("default_to_edit:edit", actions.select_default())
|
||||
|
||||
action_set.select:replace(function(_, arg) return "override_with_select:" .. arg end)
|
||||
action_set.select:replace(function(_, arg)
|
||||
return "override_with_select:" .. arg
|
||||
end)
|
||||
eq("override_with_select:default", actions.select_default())
|
||||
|
||||
-- Sometimes you might want to change the default selection...
|
||||
|
||||
@@ -1,30 +1,32 @@
|
||||
local entry_display = require('telescope.pickers.entry_display')
|
||||
local entry_display = require "telescope.pickers.entry_display"
|
||||
|
||||
describe('truncate', function()
|
||||
for _, ambiwidth in ipairs{'single', 'double'} do
|
||||
for _, case in ipairs{
|
||||
{args = {'abcde', 6}, expected = {single = 'abcde', double = 'abcde'}},
|
||||
{args = {'abcde', 5}, expected = {single = 'abcde', double = 'abcde'}},
|
||||
{args = {'abcde', 4}, expected = {single = 'abc…', double = 'ab…'}},
|
||||
{args = {'アイウエオ', 11}, expected = {single = 'アイウエオ', double = 'アイウエオ'}},
|
||||
{args = {'アイウエオ', 10}, expected = {single = 'アイウエオ', double = 'アイウエオ'}},
|
||||
{args = {'アイウエオ', 9}, expected = {single = 'アイウエ…', double = 'アイウ…'}},
|
||||
{args = {'アイウエオ', 8}, expected = {single = 'アイウ…', double = 'アイウ…'}},
|
||||
{args = {'├─┤', 7}, expected = {single = '├─┤', double = '├─┤'}},
|
||||
{args = {'├─┤', 6}, expected = {single = '├─┤', double = '├─┤'}},
|
||||
{args = {'├─┤', 5}, expected = {single = '├─┤', double = '├…'}},
|
||||
{args = {'├─┤', 4}, expected = {single = '├─┤', double = '├…'}},
|
||||
{args = {'├─┤', 3}, expected = {single = '├─┤', double = '…'}},
|
||||
{args = {'├─┤', 2}, expected = {single = '├…', double = '…'}},
|
||||
describe("truncate", function()
|
||||
for _, ambiwidth in ipairs { "single", "double" } do
|
||||
for _, case in ipairs {
|
||||
{ args = { "abcde", 6 }, expected = { single = "abcde", double = "abcde" } },
|
||||
{ args = { "abcde", 5 }, expected = { single = "abcde", double = "abcde" } },
|
||||
{ args = { "abcde", 4 }, expected = { single = "abc…", double = "ab…" } },
|
||||
{ args = { "アイウエオ", 11 }, expected = { single = "アイウエオ", double = "アイウエオ" } },
|
||||
{ args = { "アイウエオ", 10 }, expected = { single = "アイウエオ", double = "アイウエオ" } },
|
||||
{ args = { "アイウエオ", 9 }, expected = { single = "アイウエ…", double = "アイウ…" } },
|
||||
{ args = { "アイウエオ", 8 }, expected = { single = "アイウ…", double = "アイウ…" } },
|
||||
{ args = { "├─┤", 7 }, expected = { single = "├─┤", double = "├─┤" } },
|
||||
{ args = { "├─┤", 6 }, expected = { single = "├─┤", double = "├─┤" } },
|
||||
{ args = { "├─┤", 5 }, expected = { single = "├─┤", double = "├…" } },
|
||||
{ args = { "├─┤", 4 }, expected = { single = "├─┤", double = "├…" } },
|
||||
{ args = { "├─┤", 3 }, expected = { single = "├─┤", double = "…" } },
|
||||
{ args = { "├─┤", 2 }, expected = { single = "├…", double = "…" } },
|
||||
} do
|
||||
local msg = ('can truncate: ambiwidth = %s, [%s, %d] -> %s'):format(ambiwidth, case.args[1], case.args[2], case.expected[ambiwidth])
|
||||
local msg = ("can truncate: ambiwidth = %s, [%s, %d] -> %s"):format(
|
||||
ambiwidth,
|
||||
case.args[1],
|
||||
case.args[2],
|
||||
case.expected[ambiwidth]
|
||||
)
|
||||
it(msg, function()
|
||||
local original = vim.o.ambiwidth
|
||||
vim.o.ambiwidth = ambiwidth
|
||||
assert.are.same(
|
||||
case.expected[ambiwidth],
|
||||
entry_display.truncate(case.args[1], case.args[2])
|
||||
)
|
||||
assert.are.same(case.expected[ambiwidth], entry_display.truncate(case.args[1], case.args[2]))
|
||||
vim.o.ambiwidth = original
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
local EntryManager = require('telescope.entry_manager')
|
||||
local EntryManager = require "telescope.entry_manager"
|
||||
|
||||
local eq = assert.are.same
|
||||
|
||||
describe('process_result', function()
|
||||
it('works with one entry', function()
|
||||
describe("process_result", function()
|
||||
it("works with one entry", function()
|
||||
local manager = EntryManager:new(5, nil)
|
||||
|
||||
manager:add_entry(nil, 1, "hello")
|
||||
@@ -11,7 +11,7 @@ describe('process_result', function()
|
||||
eq(1, manager:get_score(1))
|
||||
end)
|
||||
|
||||
it('works with two entries', function()
|
||||
it("works with two entries", function()
|
||||
local manager = EntryManager:new(5, nil)
|
||||
|
||||
manager:add_entry(nil, 1, "hello")
|
||||
@@ -23,18 +23,22 @@ describe('process_result', function()
|
||||
eq("later", manager:get_entry(2))
|
||||
end)
|
||||
|
||||
it('calls functions when inserting', function()
|
||||
it("calls functions when inserting", function()
|
||||
local called_count = 0
|
||||
local manager = EntryManager:new(5, function() called_count = called_count + 1 end)
|
||||
local manager = EntryManager:new(5, function()
|
||||
called_count = called_count + 1
|
||||
end)
|
||||
|
||||
assert(called_count == 0)
|
||||
manager:add_entry(nil, 1, "hello")
|
||||
assert(called_count == 1)
|
||||
end)
|
||||
|
||||
it('calls functions when inserting twice', function()
|
||||
it("calls functions when inserting twice", function()
|
||||
local called_count = 0
|
||||
local manager = EntryManager:new(5, function() called_count = called_count + 1 end)
|
||||
local manager = EntryManager:new(5, function()
|
||||
called_count = called_count + 1
|
||||
end)
|
||||
|
||||
assert(called_count == 0)
|
||||
manager:add_entry(nil, 1, "hello")
|
||||
@@ -42,9 +46,11 @@ describe('process_result', function()
|
||||
assert(called_count == 2)
|
||||
end)
|
||||
|
||||
it('correctly sorts lower scores', function()
|
||||
it("correctly sorts lower scores", function()
|
||||
local called_count = 0
|
||||
local manager = EntryManager:new(5, function() called_count = called_count + 1 end)
|
||||
local manager = EntryManager:new(5, function()
|
||||
called_count = called_count + 1
|
||||
end)
|
||||
manager:add_entry(nil, 5, "worse result")
|
||||
manager:add_entry(nil, 2, "better result")
|
||||
|
||||
@@ -54,9 +60,11 @@ describe('process_result', function()
|
||||
eq(2, called_count)
|
||||
end)
|
||||
|
||||
it('respects max results', function()
|
||||
it("respects max results", function()
|
||||
local called_count = 0
|
||||
local manager = EntryManager:new(1, function() called_count = called_count + 1 end)
|
||||
local manager = EntryManager:new(1, function()
|
||||
called_count = called_count + 1
|
||||
end)
|
||||
manager:add_entry(nil, 2, "better result")
|
||||
manager:add_entry(nil, 5, "worse result")
|
||||
|
||||
@@ -64,24 +72,28 @@ describe('process_result', function()
|
||||
eq(1, called_count)
|
||||
end)
|
||||
|
||||
it('should allow simple entries', function()
|
||||
it("should allow simple entries", function()
|
||||
local manager = EntryManager:new(5)
|
||||
|
||||
local counts_executed = 0
|
||||
manager:add_entry(nil, 1, setmetatable({}, {
|
||||
__index = function(t, k)
|
||||
local val = nil
|
||||
if k == "ordinal" then
|
||||
counts_executed = counts_executed + 1
|
||||
manager:add_entry(
|
||||
nil,
|
||||
1,
|
||||
setmetatable({}, {
|
||||
__index = function(t, k)
|
||||
local val = nil
|
||||
if k == "ordinal" then
|
||||
counts_executed = counts_executed + 1
|
||||
|
||||
-- This could be expensive, only call later
|
||||
val = "wow"
|
||||
end
|
||||
-- This could be expensive, only call later
|
||||
val = "wow"
|
||||
end
|
||||
|
||||
rawset(t, k, val)
|
||||
return val
|
||||
end,
|
||||
}))
|
||||
rawset(t, k, val)
|
||||
return val
|
||||
end,
|
||||
})
|
||||
)
|
||||
|
||||
eq("wow", manager:get_ordinal(1))
|
||||
eq("wow", manager:get_ordinal(1))
|
||||
@@ -90,7 +102,7 @@ describe('process_result', function()
|
||||
eq(1, counts_executed)
|
||||
end)
|
||||
|
||||
it('should not loop a bunch', function()
|
||||
it("should not loop a bunch", function()
|
||||
local info = {}
|
||||
local manager = EntryManager:new(5, nil, info)
|
||||
manager:add_entry(nil, 4, "better result")
|
||||
@@ -102,7 +114,7 @@ describe('process_result', function()
|
||||
eq(2, info.looped)
|
||||
end)
|
||||
|
||||
it('should not loop a bunch, part 2', function()
|
||||
it("should not loop a bunch, part 2", function()
|
||||
local info = {}
|
||||
local manager = EntryManager:new(5, nil, info)
|
||||
manager:add_entry(nil, 4, "better result")
|
||||
@@ -115,7 +127,7 @@ describe('process_result', function()
|
||||
eq(3, info.looped)
|
||||
end)
|
||||
|
||||
it('should update worst score in all append case', function()
|
||||
it("should update worst score in all append case", function()
|
||||
local manager = EntryManager:new(2, nil)
|
||||
manager:add_entry(nil, 2, "result 2")
|
||||
manager:add_entry(nil, 3, "result 3")
|
||||
@@ -124,9 +136,11 @@ describe('process_result', function()
|
||||
eq(3, manager.worst_acceptable_score)
|
||||
end)
|
||||
|
||||
it('should update worst score in all prepend case', function()
|
||||
it("should update worst score in all prepend case", function()
|
||||
local called_count = 0
|
||||
local manager = EntryManager:new(2, function() called_count = called_count + 1 end)
|
||||
local manager = EntryManager:new(2, function()
|
||||
called_count = called_count + 1
|
||||
end)
|
||||
manager:add_entry(nil, 5, "worse result")
|
||||
manager:add_entry(nil, 4, "less worse result")
|
||||
manager:add_entry(nil, 2, "better result")
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
-- local tester = require('telescope.pickers._test')
|
||||
local config = require('telescope.config')
|
||||
local resolve = require('telescope.config.resolve')
|
||||
local layout_strats = require('telescope.pickers.layout_strategies')
|
||||
local config = require "telescope.config"
|
||||
local resolve = require "telescope.config.resolve"
|
||||
local layout_strats = require "telescope.pickers.layout_strategies"
|
||||
|
||||
local validate_layout_config = layout_strats._validate_layout_config
|
||||
|
||||
local eq = assert.are.same
|
||||
|
||||
describe('layout_strategies', function()
|
||||
it('should have validator', function()
|
||||
describe("layout_strategies", function()
|
||||
it("should have validator", function()
|
||||
assert(validate_layout_config, "Has validator")
|
||||
end)
|
||||
|
||||
@@ -23,13 +23,19 @@ describe('layout_strategies', function()
|
||||
end)
|
||||
end
|
||||
|
||||
test_height('should handle numbers', 10, 10)
|
||||
test_height("should handle numbers", 10, 10)
|
||||
|
||||
test_height('should handle percentage: 100', 10, 0.1, { max_lines = 100 })
|
||||
test_height('should handle percentage: 110', 11, 0.1, { max_lines = 110 })
|
||||
test_height("should handle percentage: 100", 10, 0.1, { max_lines = 100 })
|
||||
test_height("should handle percentage: 110", 11, 0.1, { max_lines = 110 })
|
||||
|
||||
test_height('should call functions: simple', 5, function() return 5 end)
|
||||
test_height('should call functions: percentage', 15, function(_, _, lines) return 0.1 * lines end, { max_lines = 150 })
|
||||
test_height("should call functions: simple", 5, function()
|
||||
return 5
|
||||
end)
|
||||
test_height("should call functions: percentage", 15, function(_, _, lines)
|
||||
return 0.1 * lines
|
||||
end, {
|
||||
max_lines = 150,
|
||||
})
|
||||
|
||||
local test_defaults_key = function(should, key, strat, output, ours, theirs, override)
|
||||
ours = ours or {}
|
||||
@@ -38,65 +44,119 @@ describe('layout_strategies', function()
|
||||
|
||||
it(should, function()
|
||||
config.clear_defaults()
|
||||
config.set_defaults({layout_config=theirs}, {layout_config={ours,'description'}})
|
||||
config.set_defaults({ layout_config = theirs }, { layout_config = { ours, "description" } })
|
||||
local layout_config = validate_layout_config(strat, layout_strats._configurations[strat], override)
|
||||
eq(output, layout_config[key])
|
||||
end)
|
||||
end
|
||||
|
||||
test_defaults_key("should use ours if theirs and override don't give the key",
|
||||
'height','horizontal',50,
|
||||
{height=50}, {width=100}, {width=120}
|
||||
test_defaults_key(
|
||||
"should use ours if theirs and override don't give the key",
|
||||
"height",
|
||||
"horizontal",
|
||||
50,
|
||||
{ height = 50 },
|
||||
{ width = 100 },
|
||||
{ width = 120 }
|
||||
)
|
||||
|
||||
test_defaults_key("should use ours if theirs and override don't give the key for this strategy",
|
||||
'height','horizontal',50,
|
||||
{height=50}, {vertical={height=100}}, {vertical={height=120}}
|
||||
test_defaults_key(
|
||||
"should use ours if theirs and override don't give the key for this strategy",
|
||||
"height",
|
||||
"horizontal",
|
||||
50,
|
||||
{ height = 50 },
|
||||
{ vertical = { height = 100 } },
|
||||
{ vertical = { height = 120 } }
|
||||
)
|
||||
|
||||
test_defaults_key("should use theirs if override doesn't give the key",
|
||||
'height','horizontal',100,
|
||||
{height=50}, {height=100}, {width=120}
|
||||
test_defaults_key(
|
||||
"should use theirs if override doesn't give the key",
|
||||
"height",
|
||||
"horizontal",
|
||||
100,
|
||||
{ height = 50 },
|
||||
{ height = 100 },
|
||||
{ width = 120 }
|
||||
)
|
||||
|
||||
test_defaults_key("should use override if key given",
|
||||
'height','horizontal',120,
|
||||
{height=50}, {height=100}, {height=120}
|
||||
test_defaults_key(
|
||||
"should use override if key given",
|
||||
"height",
|
||||
"horizontal",
|
||||
120,
|
||||
{ height = 50 },
|
||||
{ height = 100 },
|
||||
{ height = 120 }
|
||||
)
|
||||
|
||||
test_defaults_key("should use override if key given for this strategy",
|
||||
'height','horizontal',120,
|
||||
{height=50}, {height=100}, {horizontal={height=120}}
|
||||
test_defaults_key(
|
||||
"should use override if key given for this strategy",
|
||||
"height",
|
||||
"horizontal",
|
||||
120,
|
||||
{ height = 50 },
|
||||
{ height = 100 },
|
||||
{ horizontal = { height = 120 } }
|
||||
)
|
||||
|
||||
test_defaults_key("should use theirs if override doesn't give key (even if ours has strategy specific)",
|
||||
'height','horizontal',100,
|
||||
{horizontal={height=50}}, {height=100}, {width=120}
|
||||
test_defaults_key(
|
||||
"should use theirs if override doesn't give key (even if ours has strategy specific)",
|
||||
"height",
|
||||
"horizontal",
|
||||
100,
|
||||
{ horizontal = { height = 50 } },
|
||||
{ height = 100 },
|
||||
{ width = 120 }
|
||||
)
|
||||
|
||||
test_defaults_key("should use override (even if ours has strategy specific)",
|
||||
'height','horizontal',120,
|
||||
{horizontal={height=50}}, {height=100}, {height=120}
|
||||
test_defaults_key(
|
||||
"should use override (even if ours has strategy specific)",
|
||||
"height",
|
||||
"horizontal",
|
||||
120,
|
||||
{ horizontal = { height = 50 } },
|
||||
{ height = 100 },
|
||||
{ height = 120 }
|
||||
)
|
||||
|
||||
test_defaults_key("should use override (even if theirs has strategy specific)",
|
||||
'height','horizontal',120,
|
||||
{height=50}, {horizontal={height=100}}, {height=120}
|
||||
test_defaults_key(
|
||||
"should use override (even if theirs has strategy specific)",
|
||||
"height",
|
||||
"horizontal",
|
||||
120,
|
||||
{ height = 50 },
|
||||
{ horizontal = { height = 100 } },
|
||||
{ height = 120 }
|
||||
)
|
||||
|
||||
test_defaults_key("should use override (even if ours and theirs have strategy specific)",
|
||||
'height','horizontal',120,
|
||||
{horizontal={height=50}}, {horizontal={height=100}}, {height=120}
|
||||
test_defaults_key(
|
||||
"should use override (even if ours and theirs have strategy specific)",
|
||||
"height",
|
||||
"horizontal",
|
||||
120,
|
||||
{ horizontal = { height = 50 } },
|
||||
{ horizontal = { height = 100 } },
|
||||
{ height = 120 }
|
||||
)
|
||||
|
||||
test_defaults_key("should handle user config overriding a table with a number",
|
||||
'height','horizontal',120,
|
||||
{height={padding=5}},{height=120},{}
|
||||
test_defaults_key(
|
||||
"should handle user config overriding a table with a number",
|
||||
"height",
|
||||
"horizontal",
|
||||
120,
|
||||
{ height = { padding = 5 } },
|
||||
{ height = 120 },
|
||||
{}
|
||||
)
|
||||
|
||||
test_defaults_key("should handle user oneshot overriding a table with a number",
|
||||
'height','horizontal',120,
|
||||
{},{height={padding=5}},{height=120}
|
||||
test_defaults_key(
|
||||
"should handle user oneshot overriding a table with a number",
|
||||
"height",
|
||||
"horizontal",
|
||||
120,
|
||||
{},
|
||||
{ height = { padding = 5 } },
|
||||
{ height = 120 }
|
||||
)
|
||||
|
||||
end)
|
||||
|
||||
@@ -1,131 +1,131 @@
|
||||
local LinkedList = require('telescope.algos.linked_list')
|
||||
local LinkedList = require "telescope.algos.linked_list"
|
||||
|
||||
describe('LinkedList', function()
|
||||
it('can create a list', function()
|
||||
describe("LinkedList", function()
|
||||
it("can create a list", function()
|
||||
local l = LinkedList:new()
|
||||
|
||||
assert.are.same(0, l.size)
|
||||
end)
|
||||
|
||||
it('can add a single entry to the list', function()
|
||||
it("can add a single entry to the list", function()
|
||||
local l = LinkedList:new()
|
||||
l:append('hello')
|
||||
l:append "hello"
|
||||
|
||||
assert.are.same(1, l.size)
|
||||
end)
|
||||
|
||||
it('can iterate over one item', function()
|
||||
it("can iterate over one item", function()
|
||||
local l = LinkedList:new()
|
||||
l:append('hello')
|
||||
l:append "hello"
|
||||
|
||||
for val in l:iter() do
|
||||
assert.are.same('hello', val)
|
||||
assert.are.same("hello", val)
|
||||
end
|
||||
end)
|
||||
|
||||
it('iterates in order', function()
|
||||
it("iterates in order", function()
|
||||
local l = LinkedList:new()
|
||||
l:append('hello')
|
||||
l:append('world')
|
||||
l:append "hello"
|
||||
l:append "world"
|
||||
|
||||
local x = {}
|
||||
for val in l:iter() do
|
||||
table.insert(x, val)
|
||||
end
|
||||
|
||||
assert.are.same({'hello', 'world'}, x)
|
||||
assert.are.same({ "hello", "world" }, x)
|
||||
end)
|
||||
|
||||
it('iterates in order, for prepend', function()
|
||||
it("iterates in order, for prepend", function()
|
||||
local l = LinkedList:new()
|
||||
l:prepend('world')
|
||||
l:prepend('hello')
|
||||
l:prepend "world"
|
||||
l:prepend "hello"
|
||||
|
||||
local x = {}
|
||||
for val in l:iter() do
|
||||
table.insert(x, val)
|
||||
end
|
||||
|
||||
assert.are.same({'hello', 'world'}, x)
|
||||
assert.are.same({ "hello", "world" }, x)
|
||||
end)
|
||||
|
||||
it('iterates in order, for combo', function()
|
||||
it("iterates in order, for combo", function()
|
||||
local l = LinkedList:new()
|
||||
l:prepend('world')
|
||||
l:prepend('hello')
|
||||
l:append('last')
|
||||
l:prepend('first')
|
||||
l:prepend "world"
|
||||
l:prepend "hello"
|
||||
l:append "last"
|
||||
l:prepend "first"
|
||||
|
||||
local x = {}
|
||||
for val in l:iter() do
|
||||
table.insert(x, val)
|
||||
end
|
||||
|
||||
assert.are.same({'first', 'hello', 'world', 'last'}, x)
|
||||
assert.are.same({ "first", "hello", "world", "last" }, x)
|
||||
assert.are.same(#x, l.size)
|
||||
end)
|
||||
|
||||
it('has ipairs', function()
|
||||
it("has ipairs", function()
|
||||
local l = LinkedList:new()
|
||||
l:prepend('world')
|
||||
l:prepend('hello')
|
||||
l:append('last')
|
||||
l:prepend('first')
|
||||
l:prepend "world"
|
||||
l:prepend "hello"
|
||||
l:append "last"
|
||||
l:prepend "first"
|
||||
|
||||
local x = {}
|
||||
for v in l:iter() do
|
||||
table.insert(x, v)
|
||||
end
|
||||
assert.are.same({'first', 'hello', 'world', 'last'}, x)
|
||||
assert.are.same({ "first", "hello", "world", "last" }, x)
|
||||
|
||||
local expected = {}
|
||||
for i, v in ipairs(x) do
|
||||
table.insert(expected, {i, v})
|
||||
table.insert(expected, { i, v })
|
||||
end
|
||||
|
||||
local actual = {}
|
||||
for i, v in l:ipairs() do
|
||||
table.insert(actual, {i, v})
|
||||
table.insert(actual, { i, v })
|
||||
end
|
||||
|
||||
assert.are.same(expected, actual)
|
||||
end)
|
||||
|
||||
describe('track_at', function()
|
||||
it('should update tracked when only appending', function()
|
||||
describe("track_at", function()
|
||||
it("should update tracked when only appending", function()
|
||||
local l = LinkedList:new { track_at = 2 }
|
||||
l:append("first")
|
||||
l:append("second")
|
||||
l:append("third")
|
||||
l:append "first"
|
||||
l:append "second"
|
||||
l:append "third"
|
||||
|
||||
assert.are.same("second", l.tracked)
|
||||
end)
|
||||
|
||||
it('should update tracked when first some prepend and then append', function()
|
||||
it("should update tracked when first some prepend and then append", function()
|
||||
local l = LinkedList:new { track_at = 2 }
|
||||
l:prepend("first")
|
||||
l:append("second")
|
||||
l:append("third")
|
||||
l:prepend "first"
|
||||
l:append "second"
|
||||
l:append "third"
|
||||
|
||||
assert.are.same("second", l.tracked)
|
||||
end)
|
||||
|
||||
it('should update when only prepending', function()
|
||||
it("should update when only prepending", function()
|
||||
local l = LinkedList:new { track_at = 2 }
|
||||
l:prepend("third")
|
||||
l:prepend("second")
|
||||
l:prepend("first")
|
||||
l:prepend "third"
|
||||
l:prepend "second"
|
||||
l:prepend "first"
|
||||
|
||||
assert.are.same("second", l.tracked)
|
||||
end)
|
||||
|
||||
it('should update when lots of prepend and append', function()
|
||||
it("should update when lots of prepend and append", function()
|
||||
local l = LinkedList:new { track_at = 2 }
|
||||
l:prepend("third")
|
||||
l:prepend("second")
|
||||
l:prepend("first")
|
||||
l:append("fourth")
|
||||
l:prepend("zeroth")
|
||||
l:prepend "third"
|
||||
l:prepend "second"
|
||||
l:prepend "first"
|
||||
l:append "fourth"
|
||||
l:prepend "zeroth"
|
||||
|
||||
assert.are.same("first", l.tracked)
|
||||
end)
|
||||
|
||||
@@ -1,26 +1,27 @@
|
||||
require('plenary.reload').reload_module('telescope')
|
||||
require("plenary.reload").reload_module "telescope"
|
||||
|
||||
local tester = require('telescope.pickers._test')
|
||||
local tester = require "telescope.pickers._test"
|
||||
|
||||
local disp = function(val)
|
||||
return vim.inspect(val, { newline = " ", indent = "" })
|
||||
end
|
||||
|
||||
describe('builtin.find_files', function()
|
||||
it('should find the readme', function()
|
||||
tester.run_file('find_files__readme')
|
||||
describe("builtin.find_files", function()
|
||||
it("should find the readme", function()
|
||||
tester.run_file "find_files__readme"
|
||||
end)
|
||||
|
||||
it('should be able to move selections', function()
|
||||
tester.run_file('find_files__with_ctrl_n')
|
||||
it("should be able to move selections", function()
|
||||
tester.run_file "find_files__with_ctrl_n"
|
||||
end)
|
||||
|
||||
for _, configuration in ipairs {
|
||||
{ sorting_strategy = 'descending', },
|
||||
{ sorting_strategy = 'ascending', },
|
||||
{ sorting_strategy = "descending" },
|
||||
{ sorting_strategy = "ascending" },
|
||||
} do
|
||||
it('should not display devicons when disabled: ' .. disp(configuration), function()
|
||||
tester.run_string(string.format([[
|
||||
it("should not display devicons when disabled: " .. disp(configuration), function()
|
||||
tester.run_string(string.format(
|
||||
[[
|
||||
local max_results = 5
|
||||
|
||||
tester.builtin_picker('find_files', 'README.md', {
|
||||
@@ -41,18 +42,21 @@ describe('builtin.find_files', function()
|
||||
width = 0.9,
|
||||
},
|
||||
}, vim.fn.json_decode([==[%s]==])))
|
||||
]], vim.fn.json_encode(configuration)))
|
||||
]],
|
||||
vim.fn.json_encode(configuration)
|
||||
))
|
||||
end)
|
||||
|
||||
it('should only save one line for ascending, but many for descending', function()
|
||||
it("should only save one line for ascending, but many for descending", function()
|
||||
local expected
|
||||
if configuration.sorting_strategy == 'descending' then
|
||||
if configuration.sorting_strategy == "descending" then
|
||||
expected = 5
|
||||
else
|
||||
expected = 1
|
||||
end
|
||||
|
||||
tester.run_string(string.format([[
|
||||
tester.run_string(string.format(
|
||||
[[
|
||||
tester.builtin_picker('find_files', 'README.md', {
|
||||
post_typed = {
|
||||
{ %s, function() return #GetResults() end },
|
||||
@@ -66,15 +70,19 @@ describe('builtin.find_files', function()
|
||||
width = 0.9,
|
||||
},
|
||||
}, vim.fn.json_decode([==[%s]==])))
|
||||
]], expected, vim.fn.json_encode(configuration)))
|
||||
]],
|
||||
expected,
|
||||
vim.fn.json_encode(configuration)
|
||||
))
|
||||
end)
|
||||
|
||||
it('use devicons, if it has it when enabled', function()
|
||||
if not pcall(require, 'nvim-web-devicons') then
|
||||
it("use devicons, if it has it when enabled", function()
|
||||
if not pcall(require, "nvim-web-devicons") then
|
||||
return
|
||||
end
|
||||
|
||||
tester.run_string(string.format([[
|
||||
tester.run_string(string.format(
|
||||
[[
|
||||
tester.builtin_picker('find_files', 'README.md', {
|
||||
post_typed = {
|
||||
{ "> README.md", GetPrompt },
|
||||
@@ -88,11 +96,13 @@ describe('builtin.find_files', function()
|
||||
disable_devicons = false,
|
||||
sorter = require('telescope.sorters').get_fzy_sorter(),
|
||||
}, vim.fn.json_decode([==[%s]==])))
|
||||
]], vim.fn.json_encode(configuration)))
|
||||
]],
|
||||
vim.fn.json_encode(configuration)
|
||||
))
|
||||
end)
|
||||
end
|
||||
|
||||
it('should find the readme, using lowercase', function()
|
||||
it("should find the readme, using lowercase", function()
|
||||
tester.run_string [[
|
||||
tester.builtin_picker('find_files', 'readme.md', {
|
||||
post_close = {
|
||||
@@ -102,7 +112,7 @@ describe('builtin.find_files', function()
|
||||
]]
|
||||
end)
|
||||
|
||||
it('should find the pickers.lua, using lowercase', function()
|
||||
it("should find the pickers.lua, using lowercase", function()
|
||||
tester.run_string [[
|
||||
tester.builtin_picker('find_files', 'pickers.lua', {
|
||||
post_close = {
|
||||
@@ -112,7 +122,7 @@ describe('builtin.find_files', function()
|
||||
]]
|
||||
end)
|
||||
|
||||
it('should find the pickers.lua', function()
|
||||
it("should find the pickers.lua", function()
|
||||
tester.run_string [[
|
||||
tester.builtin_picker('find_files', 'pickers.lua', {
|
||||
post_close = {
|
||||
@@ -123,7 +133,7 @@ describe('builtin.find_files', function()
|
||||
]]
|
||||
end)
|
||||
|
||||
it('should be able to c-n the items', function()
|
||||
it("should be able to c-n the items", function()
|
||||
tester.run_string [[
|
||||
tester.builtin_picker('find_files', 'fixtures/file<c-p>', {
|
||||
post_typed = {
|
||||
@@ -151,7 +161,7 @@ describe('builtin.find_files', function()
|
||||
]]
|
||||
end)
|
||||
|
||||
it('should be able to get the current selection', function()
|
||||
it("should be able to get the current selection", function()
|
||||
tester.run_string [[
|
||||
tester.builtin_picker('find_files', 'fixtures/file_abc', {
|
||||
post_typed = {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
require('plenary.reload').reload_module('telescope')
|
||||
require("plenary.reload").reload_module "telescope"
|
||||
|
||||
local tester = require('telescope.pickers._test')
|
||||
local tester = require "telescope.pickers._test"
|
||||
|
||||
local log = require('telescope.log')
|
||||
local log = require "telescope.log"
|
||||
log.use_console = false
|
||||
|
||||
describe('scrolling strategies', function()
|
||||
it('should handle cycling for full list', function()
|
||||
describe("scrolling strategies", function()
|
||||
it("should handle cycling for full list", function()
|
||||
tester.run_file [[find_files__scrolling_descending_cycle]]
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -2,12 +2,11 @@ local eq = function(a, b)
|
||||
assert.are.same(a, b)
|
||||
end
|
||||
|
||||
local resolve = require('telescope.config.resolve')
|
||||
local resolve = require "telescope.config.resolve"
|
||||
|
||||
|
||||
describe('telescope.config.resolve', function()
|
||||
describe('win_option', function()
|
||||
it('should resolve for percentages', function()
|
||||
describe("telescope.config.resolve", function()
|
||||
describe("win_option", function()
|
||||
it("should resolve for percentages", function()
|
||||
local height_config = 0.8
|
||||
local opt = resolve.win_option(height_config)
|
||||
|
||||
@@ -16,7 +15,7 @@ describe('telescope.config.resolve', function()
|
||||
eq(height_config, opt.results)
|
||||
end)
|
||||
|
||||
it('should resolve for percetnages with default', function()
|
||||
it("should resolve for percetnages with default", function()
|
||||
local height_config = 0.8
|
||||
local opt = resolve.win_option(nil, height_config)
|
||||
|
||||
@@ -25,8 +24,8 @@ describe('telescope.config.resolve', function()
|
||||
eq(height_config, opt.results)
|
||||
end)
|
||||
|
||||
it('should resolve table values', function()
|
||||
local table_val = {'a'}
|
||||
it("should resolve table values", function()
|
||||
local table_val = { "a" }
|
||||
local opt = resolve.win_option(nil, table_val)
|
||||
|
||||
eq(table_val, opt.preview)
|
||||
@@ -34,32 +33,32 @@ describe('telescope.config.resolve', function()
|
||||
eq(table_val, opt.results)
|
||||
end)
|
||||
|
||||
it('should allow overrides for different wins', function()
|
||||
local prompt_override = {'a', prompt = 'b'}
|
||||
it("should allow overrides for different wins", function()
|
||||
local prompt_override = { "a", prompt = "b" }
|
||||
local opt = resolve.win_option(prompt_override)
|
||||
eq('a', opt.preview)
|
||||
eq('a', opt.results)
|
||||
eq('b', opt.prompt)
|
||||
eq("a", opt.preview)
|
||||
eq("a", opt.results)
|
||||
eq("b", opt.prompt)
|
||||
end)
|
||||
|
||||
it('should allow overrides for all wins', function()
|
||||
local all_specified = {preview = 'a', prompt = 'b', results = 'c'}
|
||||
it("should allow overrides for all wins", function()
|
||||
local all_specified = { preview = "a", prompt = "b", results = "c" }
|
||||
local opt = resolve.win_option(all_specified)
|
||||
eq('a', opt.preview)
|
||||
eq('b', opt.prompt)
|
||||
eq('c', opt.results)
|
||||
eq("a", opt.preview)
|
||||
eq("b", opt.prompt)
|
||||
eq("c", opt.results)
|
||||
end)
|
||||
|
||||
it('should allow some specified with a simple default', function()
|
||||
local some_specified = {prompt = 'b', results = 'c'}
|
||||
local opt = resolve.win_option(some_specified, 'a')
|
||||
eq('a', opt.preview)
|
||||
eq('b', opt.prompt)
|
||||
eq('c', opt.results)
|
||||
it("should allow some specified with a simple default", function()
|
||||
local some_specified = { prompt = "b", results = "c" }
|
||||
local opt = resolve.win_option(some_specified, "a")
|
||||
eq("a", opt.preview)
|
||||
eq("b", opt.prompt)
|
||||
eq("c", opt.results)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('resolve_height/width', function()
|
||||
describe("resolve_height/width", function()
|
||||
eq(10, resolve.resolve_height(0.1)(nil, 24, 100))
|
||||
eq(2, resolve.resolve_width(0.1)(nil, 24, 100))
|
||||
|
||||
|
||||
@@ -1,144 +1,143 @@
|
||||
local p_scroller = require('telescope.pickers.scroller')
|
||||
local p_scroller = require "telescope.pickers.scroller"
|
||||
|
||||
local log = require('telescope.log')
|
||||
local log = require "telescope.log"
|
||||
log.use_console = false
|
||||
|
||||
local eq = assert.are.same
|
||||
|
||||
describe('scroller', function()
|
||||
describe("scroller", function()
|
||||
local max_results = 10
|
||||
|
||||
describe('ascending cycle', function()
|
||||
local cycle_scroller = p_scroller.create('cycle', 'ascending')
|
||||
describe("ascending cycle", function()
|
||||
local cycle_scroller = p_scroller.create("cycle", "ascending")
|
||||
|
||||
it('should return values within the max results', function()
|
||||
it("should return values within the max results", function()
|
||||
eq(5, cycle_scroller(max_results, max_results, 5))
|
||||
end)
|
||||
|
||||
it('should return 0 at 0', function()
|
||||
it("should return 0 at 0", function()
|
||||
eq(0, cycle_scroller(max_results, max_results, 0))
|
||||
end)
|
||||
|
||||
it('should cycle you to the top when you go below 0', function()
|
||||
it("should cycle you to the top when you go below 0", function()
|
||||
eq(max_results - 1, cycle_scroller(max_results, max_results, -1))
|
||||
end)
|
||||
|
||||
it('should cycle you to 0 when you go past the results', function()
|
||||
it("should cycle you to 0 when you go past the results", function()
|
||||
eq(0, cycle_scroller(max_results, max_results, max_results + 1))
|
||||
end)
|
||||
|
||||
it('should cycle when current results is less than max_results', function()
|
||||
it("should cycle when current results is less than max_results", function()
|
||||
eq(0, cycle_scroller(max_results, 5, 7))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('ascending limit', function()
|
||||
local limit_scroller = p_scroller.create('limit', 'ascending')
|
||||
describe("ascending limit", function()
|
||||
local limit_scroller = p_scroller.create("limit", "ascending")
|
||||
|
||||
it('should return values within the max results', function()
|
||||
it("should return values within the max results", function()
|
||||
eq(5, limit_scroller(max_results, max_results, 5))
|
||||
end)
|
||||
|
||||
it('should return 0 at 0', function()
|
||||
it("should return 0 at 0", function()
|
||||
eq(0, limit_scroller(max_results, max_results, 0))
|
||||
end)
|
||||
|
||||
it('should not cycle', function()
|
||||
it("should not cycle", function()
|
||||
eq(0, limit_scroller(max_results, max_results, -1))
|
||||
end)
|
||||
|
||||
it('should not cycle you to 0 when you go past the results', function()
|
||||
it("should not cycle you to 0 when you go past the results", function()
|
||||
eq(max_results - 1, limit_scroller(max_results, max_results, max_results + 1))
|
||||
end)
|
||||
|
||||
it('should stay at current results when current results is less than max_results', function()
|
||||
it("should stay at current results when current results is less than max_results", function()
|
||||
local current = 5
|
||||
eq(current - 1, limit_scroller(max_results, current, 7))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('descending cycle', function()
|
||||
local cycle_scroller = p_scroller.create('cycle', 'descending')
|
||||
describe("descending cycle", function()
|
||||
local cycle_scroller = p_scroller.create("cycle", "descending")
|
||||
|
||||
it('should return values within the max results', function()
|
||||
it("should return values within the max results", function()
|
||||
eq(5, cycle_scroller(max_results, max_results, 5))
|
||||
end)
|
||||
|
||||
it('should return max_results - 1 at 0', function()
|
||||
it("should return max_results - 1 at 0", function()
|
||||
eq(0, cycle_scroller(max_results, max_results, 0))
|
||||
end)
|
||||
|
||||
it('should cycle you to the bot when you go below 0', function()
|
||||
it("should cycle you to the bot when you go below 0", function()
|
||||
eq(max_results - 1, cycle_scroller(max_results, max_results, -1))
|
||||
end)
|
||||
|
||||
it('should cycle you to 0 when you go past the results', function()
|
||||
it("should cycle you to 0 when you go past the results", function()
|
||||
eq(0, cycle_scroller(max_results, max_results, max_results + 1))
|
||||
end)
|
||||
|
||||
it('should cycle when current results is less than max_results', function()
|
||||
it("should cycle when current results is less than max_results", function()
|
||||
eq(9, cycle_scroller(max_results, 5, 4))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('descending limit', function()
|
||||
local limit_scroller = p_scroller.create('limit', 'descending')
|
||||
describe("descending limit", function()
|
||||
local limit_scroller = p_scroller.create("limit", "descending")
|
||||
|
||||
it('should return values within the max results', function()
|
||||
it("should return values within the max results", function()
|
||||
eq(5, limit_scroller(max_results, max_results, 5))
|
||||
end)
|
||||
|
||||
it('should return 0 at 0', function()
|
||||
it("should return 0 at 0", function()
|
||||
eq(0, limit_scroller(max_results, max_results, 0))
|
||||
end)
|
||||
|
||||
it('should not cycle', function()
|
||||
it("should not cycle", function()
|
||||
eq(0, limit_scroller(max_results, max_results, -1))
|
||||
end)
|
||||
|
||||
it('should not cycle you to 0 when you go past the results', function()
|
||||
it("should not cycle you to 0 when you go past the results", function()
|
||||
eq(max_results - 1, limit_scroller(max_results, max_results, max_results + 1))
|
||||
end)
|
||||
|
||||
it('should stay at current results when current results is less than max_results', function()
|
||||
it("should stay at current results when current results is less than max_results", function()
|
||||
local current = 5
|
||||
eq(max_results - current, limit_scroller(max_results, current, 4))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('https://github.com/nvim-telescope/telescope.nvim/pull/293#issuecomment-751463224', function()
|
||||
it('should handle having many more results than necessary', function()
|
||||
local scroller = p_scroller.create('cycle', 'descending')
|
||||
describe("https://github.com/nvim-telescope/telescope.nvim/pull/293#issuecomment-751463224", function()
|
||||
it("should handle having many more results than necessary", function()
|
||||
local scroller = p_scroller.create("cycle", "descending")
|
||||
|
||||
-- 23 112 23
|
||||
eq(0, scroller(23, 112, 23))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("should give top, middle and bottom index", function()
|
||||
it("should handle ascending", function()
|
||||
eq(0, p_scroller.top("ascending", 20, 1000))
|
||||
eq(19, p_scroller.bottom("ascending", 20, 1000))
|
||||
|
||||
describe('should give top, middle and bottom index', function()
|
||||
it('should handle ascending', function()
|
||||
eq(0, p_scroller.top('ascending', 20, 1000))
|
||||
eq(19, p_scroller.bottom('ascending', 20, 1000))
|
||||
eq(0, p_scroller.top("ascending", 20, 10))
|
||||
eq(9, p_scroller.bottom("ascending", 20, 10))
|
||||
|
||||
eq(0, p_scroller.top('ascending', 20, 10))
|
||||
eq(9, p_scroller.bottom('ascending', 20, 10))
|
||||
|
||||
eq(5, p_scroller.middle('ascending', 11, 100))
|
||||
eq(10, p_scroller.middle('ascending', 20, 100))
|
||||
eq(12, p_scroller.middle('ascending', 25, 100))
|
||||
eq(5, p_scroller.middle("ascending", 11, 100))
|
||||
eq(10, p_scroller.middle("ascending", 20, 100))
|
||||
eq(12, p_scroller.middle("ascending", 25, 100))
|
||||
end)
|
||||
|
||||
it('should handle descending', function()
|
||||
eq(0, p_scroller.top('descending', 20, 1000))
|
||||
eq(19, p_scroller.bottom('descending', 20, 1000))
|
||||
it("should handle descending", function()
|
||||
eq(0, p_scroller.top("descending", 20, 1000))
|
||||
eq(19, p_scroller.bottom("descending", 20, 1000))
|
||||
|
||||
eq(10, p_scroller.top('descending', 20, 10))
|
||||
eq(19, p_scroller.bottom('descending', 20, 10))
|
||||
eq(10, p_scroller.top("descending", 20, 10))
|
||||
eq(19, p_scroller.bottom("descending", 20, 10))
|
||||
|
||||
eq(25, p_scroller.middle('descending', 30, 10))
|
||||
eq(50, p_scroller.middle('descending', 60, 20))
|
||||
eq(105, p_scroller.middle('descending', 120, 30))
|
||||
eq(25, p_scroller.middle("descending", 30, 10))
|
||||
eq(50, p_scroller.middle("descending", 60, 20))
|
||||
eq(105, p_scroller.middle("descending", 120, 30))
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -1,111 +1,108 @@
|
||||
local picker = require('telescope.pickers')
|
||||
local picker = require "telescope.pickers"
|
||||
|
||||
local eq = assert.are.same
|
||||
|
||||
describe('telescope', function()
|
||||
describe('Picker', function()
|
||||
describe('window_dimensions', function()
|
||||
it('', function()
|
||||
describe("telescope", function()
|
||||
describe("Picker", function()
|
||||
describe("window_dimensions", function()
|
||||
it("", function()
|
||||
assert(true)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('attach_mappings', function()
|
||||
it('should allow for passing in a function', function()
|
||||
local p = picker.new({}, { attach_mappings = function() return 1 end })
|
||||
describe("attach_mappings", function()
|
||||
it("should allow for passing in a function", function()
|
||||
local p = picker.new({}, {
|
||||
attach_mappings = function()
|
||||
return 1
|
||||
end,
|
||||
})
|
||||
eq(1, p.attach_mappings())
|
||||
end)
|
||||
|
||||
it('should override an attach mappings passed in by opts', function()
|
||||
it("should override an attach mappings passed in by opts", function()
|
||||
local called_order = {}
|
||||
local p = picker.new({
|
||||
attach_mappings = function()
|
||||
table.insert(called_order, 'opts')
|
||||
table.insert(called_order, "opts")
|
||||
end,
|
||||
}, {
|
||||
attach_mappings = function()
|
||||
table.insert(called_order, 'default')
|
||||
end
|
||||
table.insert(called_order, "default")
|
||||
end,
|
||||
})
|
||||
|
||||
p.attach_mappings()
|
||||
|
||||
eq({'default', 'opts'}, called_order)
|
||||
eq({ "default", "opts" }, called_order)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('Sorters', function()
|
||||
describe('generic_fuzzy_sorter', function()
|
||||
it('sort matches well', function()
|
||||
local sorter = require('telescope.sorters').get_generic_fuzzy_sorter()
|
||||
describe("Sorters", function()
|
||||
describe("generic_fuzzy_sorter", function()
|
||||
it("sort matches well", function()
|
||||
local sorter = require("telescope.sorters").get_generic_fuzzy_sorter()
|
||||
|
||||
local exact_match = sorter:score('hello', {ordinal = 'hello'})
|
||||
local no_match = sorter:score('abcdef', {ordinal = 'ghijkl'})
|
||||
local ok_match = sorter:score('abcdef', {ordinal = 'ab'})
|
||||
local exact_match = sorter:score("hello", { ordinal = "hello" })
|
||||
local no_match = sorter:score("abcdef", { ordinal = "ghijkl" })
|
||||
local ok_match = sorter:score("abcdef", { ordinal = "ab" })
|
||||
|
||||
assert(exact_match < no_match, "exact match better than no match")
|
||||
assert(exact_match < ok_match, "exact match better than ok match")
|
||||
assert(ok_match < no_match, "ok match better than no match")
|
||||
end)
|
||||
|
||||
it('sorts multiple finds better', function()
|
||||
local sorter = require('telescope.sorters').get_generic_fuzzy_sorter()
|
||||
it("sorts multiple finds better", function()
|
||||
local sorter = require("telescope.sorters").get_generic_fuzzy_sorter()
|
||||
|
||||
local multi_match = sorter:score('generics', 'exercises/generics/generics2.rs')
|
||||
local one_match = sorter:score('abcdef', 'exercises/generics/README.md')
|
||||
local multi_match = sorter:score("generics", "exercises/generics/generics2.rs")
|
||||
local one_match = sorter:score("abcdef", "exercises/generics/README.md")
|
||||
|
||||
-- assert(multi_match < one_match)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('fuzzy_file', function()
|
||||
it('sort matches well', function()
|
||||
local sorter = require('telescope.sorters').get_fuzzy_file()
|
||||
describe("fuzzy_file", function()
|
||||
it("sort matches well", function()
|
||||
local sorter = require("telescope.sorters").get_fuzzy_file()
|
||||
|
||||
local exact_match = sorter:score('abcdef', {ordinal = 'abcdef'})
|
||||
local no_match = sorter:score('abcdef', {ordinal = 'ghijkl'})
|
||||
local ok_match = sorter:score('abcdef', {ordinal = 'ab'})
|
||||
local exact_match = sorter:score("abcdef", { ordinal = "abcdef" })
|
||||
local no_match = sorter:score("abcdef", { ordinal = "ghijkl" })
|
||||
local ok_match = sorter:score("abcdef", { ordinal = "ab" })
|
||||
|
||||
assert(
|
||||
exact_match < no_match,
|
||||
string.format("Exact match better than no match: %s %s", exact_match, no_match)
|
||||
)
|
||||
assert(
|
||||
exact_match < ok_match,
|
||||
string.format("Exact match better than OK match: %s %s", exact_match, ok_match)
|
||||
)
|
||||
assert(exact_match < no_match, string.format("Exact match better than no match: %s %s", exact_match, no_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")
|
||||
end)
|
||||
|
||||
it('sorts matches after last os sep better', function()
|
||||
local sorter = require('telescope.sorters').get_fuzzy_file()
|
||||
it("sorts matches after last os sep better", function()
|
||||
local sorter = require("telescope.sorters").get_fuzzy_file()
|
||||
|
||||
local better_match = sorter:score('aaa', {ordinal = 'bbb/aaa'})
|
||||
local worse_match = sorter:score('aaa', {ordinal = 'aaa/bbb'})
|
||||
local better_match = sorter:score("aaa", { ordinal = "bbb/aaa" })
|
||||
local worse_match = sorter:score("aaa", { ordinal = "aaa/bbb" })
|
||||
|
||||
assert(better_match < worse_match, "Final match should be stronger")
|
||||
end)
|
||||
|
||||
pending('sorts multiple finds better', function()
|
||||
local sorter = require('telescope.sorters').get_fuzzy_file()
|
||||
pending("sorts multiple finds better", function()
|
||||
local sorter = require("telescope.sorters").get_fuzzy_file()
|
||||
|
||||
local multi_match = sorter:score('generics', {ordinal = 'exercises/generics/generics2.rs'})
|
||||
local one_match = sorter:score('abcdef', {ordinal = 'exercises/generics/README.md'})
|
||||
local multi_match = sorter:score("generics", { ordinal = "exercises/generics/generics2.rs" })
|
||||
local one_match = sorter:score("abcdef", { ordinal = "exercises/generics/README.md" })
|
||||
|
||||
assert(multi_match < one_match)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('fzy', function()
|
||||
local sorter = require'telescope.sorters'.get_fzy_sorter()
|
||||
describe("fzy", function()
|
||||
local sorter = require("telescope.sorters").get_fzy_sorter()
|
||||
local function score(prompt, line)
|
||||
return sorter:score(
|
||||
prompt,
|
||||
{ordinal = line},
|
||||
function(val) return val end,
|
||||
function() return -1 end
|
||||
)
|
||||
return sorter:score(prompt, { ordinal = line }, function(val)
|
||||
return val
|
||||
end, function()
|
||||
return -1
|
||||
end)
|
||||
end
|
||||
|
||||
describe("matches", function()
|
||||
@@ -150,9 +147,9 @@ describe('telescope', function()
|
||||
assert.True(score("gemfil", "Gemfile") < score("gemfil", "Gemfile.lock"))
|
||||
end)
|
||||
it("prefers shorter matches", function()
|
||||
assert.True(score("abce", "abcdef") < score("abce", "abc de"));
|
||||
assert.True(score("abc", " a b c ") < score("abc", " a b c "));
|
||||
assert.True(score("abc", " a b c ") < score("abc", " a b c "));
|
||||
assert.True(score("abce", "abcdef") < score("abce", "abc de"))
|
||||
assert.True(score("abc", " a b c ") < score("abc", " a b c "))
|
||||
assert.True(score("abc", " a b c ") < score("abc", " a b c "))
|
||||
end)
|
||||
it("prefers shorter candidates", function()
|
||||
assert.True(score("test", "tests") < score("test", "testing"))
|
||||
@@ -174,21 +171,21 @@ describe('telescope', function()
|
||||
|
||||
describe("positioning", function()
|
||||
it("favors consecutive positions", function()
|
||||
assert.same({1, 5, 6}, positions("amo", "app/models/foo"))
|
||||
assert.same({ 1, 5, 6 }, positions("amo", "app/models/foo"))
|
||||
end)
|
||||
it("favors word beginnings", function()
|
||||
assert.same({1, 5, 12, 13}, positions("amor", "app/models/order"))
|
||||
assert.same({ 1, 5, 12, 13 }, positions("amor", "app/models/order"))
|
||||
end)
|
||||
it("works when there are no bonuses", function()
|
||||
assert.same({2, 4}, positions("as", "tags"))
|
||||
assert.same({3, 8}, positions("as", "examples.txt"))
|
||||
assert.same({ 2, 4 }, positions("as", "tags"))
|
||||
assert.same({ 3, 8 }, positions("as", "examples.txt"))
|
||||
end)
|
||||
it("favors smaller groupings of positions", function()
|
||||
assert.same({3, 5, 7}, positions("abc", "a/a/b/c/c"))
|
||||
assert.same({3, 5}, positions("ab", "caacbbc"))
|
||||
assert.same({ 3, 5, 7 }, positions("abc", "a/a/b/c/c"))
|
||||
assert.same({ 3, 5 }, positions("ab", "caacbbc"))
|
||||
end)
|
||||
it("handles exact matches", function()
|
||||
assert.same({1, 2, 3}, positions("foo", "foo"))
|
||||
assert.same({ 1, 2, 3 }, positions("foo", "foo"))
|
||||
end)
|
||||
it("ignores empty requests", function()
|
||||
assert.same({}, positions("", ""))
|
||||
@@ -198,9 +195,9 @@ describe('telescope', function()
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('layout_strategies', function()
|
||||
describe('center', function()
|
||||
it('should handle large terminals', function()
|
||||
describe("layout_strategies", function()
|
||||
describe("center", function()
|
||||
it("should handle large terminals", function()
|
||||
-- TODO: This could call layout_strategies.center w/ some weird edge case.
|
||||
-- and then assert stuff about the dimensions.
|
||||
end)
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
local finders = require('telescope.finders')
|
||||
local make_entry = require('telescope.make_entry')
|
||||
local previewers = require('telescope.previewers')
|
||||
local pickers = require('telescope.pickers')
|
||||
local sorters = require('telescope.sorters')
|
||||
local finders = require "telescope.finders"
|
||||
local make_entry = require "telescope.make_entry"
|
||||
local previewers = require "telescope.previewers"
|
||||
local pickers = require "telescope.pickers"
|
||||
local sorters = require "telescope.sorters"
|
||||
|
||||
local helpers = {}
|
||||
|
||||
-- TODO: We should do something with builtins to get those easily.
|
||||
helpers.auto_find_files = function(opts)
|
||||
opts = opts or {}
|
||||
opts.prompt_prefix = ''
|
||||
opts.prompt_prefix = ""
|
||||
|
||||
local find_command = opts.find_command
|
||||
|
||||
if not find_command then
|
||||
if 1 == vim.fn.executable("fd") then
|
||||
find_command = { 'fd', '--type', 'f' }
|
||||
elseif 1 == vim.fn.executable("fdfind") then
|
||||
find_command = { 'fdfind', '--type', 'f' }
|
||||
elseif 1 == vim.fn.executable("rg") then
|
||||
find_command = { 'rg', '--files' }
|
||||
if 1 == vim.fn.executable "fd" then
|
||||
find_command = { "fd", "--type", "f" }
|
||||
elseif 1 == vim.fn.executable "fdfind" then
|
||||
find_command = { "fdfind", "--type", "f" }
|
||||
elseif 1 == vim.fn.executable "rg" then
|
||||
find_command = { "rg", "--files" }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -30,11 +30,8 @@ helpers.auto_find_files = function(opts)
|
||||
opts.entry_maker = opts.entry_maker or make_entry.gen_from_file(opts)
|
||||
|
||||
local p = pickers.new(opts, {
|
||||
prompt = 'Find Files',
|
||||
finder = finders.new_oneshot_job(
|
||||
find_command,
|
||||
opts
|
||||
),
|
||||
prompt = "Find Files",
|
||||
finder = finders.new_oneshot_job(find_command, opts),
|
||||
previewer = previewers.cat.new(opts),
|
||||
sorter = sorters.get_fuzzy_file(),
|
||||
|
||||
@@ -43,21 +40,24 @@ helpers.auto_find_files = function(opts)
|
||||
|
||||
local count = 0
|
||||
p:register_completion_callback(function(s)
|
||||
print(count, vim.inspect(s.stats, {
|
||||
process = function(item)
|
||||
if type(item) == 'string' and item:sub(1, 1) == '_' then
|
||||
return nil
|
||||
end
|
||||
print(
|
||||
count,
|
||||
vim.inspect(s.stats, {
|
||||
process = function(item)
|
||||
if type(item) == "string" and item:sub(1, 1) == "_" then
|
||||
return nil
|
||||
end
|
||||
|
||||
return item
|
||||
end,
|
||||
}))
|
||||
return item
|
||||
end,
|
||||
})
|
||||
)
|
||||
|
||||
count = count + 1
|
||||
end)
|
||||
|
||||
local feed = function(text, feed_opts)
|
||||
feed_opts = feed_opts or 'n'
|
||||
feed_opts = feed_opts or "n"
|
||||
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(text, true, false, true), feed_opts, true)
|
||||
end
|
||||
|
||||
@@ -70,7 +70,7 @@ helpers.auto_find_files = function(opts)
|
||||
end
|
||||
|
||||
vim.wait(300, function() end)
|
||||
feed("<CR>", '')
|
||||
feed("<CR>", "")
|
||||
|
||||
vim.defer_fn(function()
|
||||
PASSED = opts.condition()
|
||||
|
||||
@@ -2,19 +2,21 @@
|
||||
vim.api.nvim_buf_set_lines(0, 4, -1, false, vim.tbl_keys(require('telescope.builtin')))
|
||||
--]]
|
||||
|
||||
require('telescope.builtin').git_files()
|
||||
RELOAD('telescope'); require('telescope.builtin').oldfiles()
|
||||
require('telescope.builtin').grep_string()
|
||||
require('telescope.builtin').lsp_document_symbols()
|
||||
RELOAD('telescope'); require('telescope.builtin').lsp_workspace_symbols()
|
||||
require('telescope.builtin').lsp_references()
|
||||
require('telescope.builtin').builtin()
|
||||
require('telescope.builtin').fd()
|
||||
require('telescope.builtin').command_history()
|
||||
require('telescope.builtin').search_history()
|
||||
require('telescope.builtin').live_grep()
|
||||
require('telescope.builtin').loclist()
|
||||
require("telescope.builtin").git_files()
|
||||
RELOAD "telescope"
|
||||
require("telescope.builtin").oldfiles()
|
||||
require("telescope.builtin").grep_string()
|
||||
require("telescope.builtin").lsp_document_symbols()
|
||||
RELOAD "telescope"
|
||||
require("telescope.builtin").lsp_workspace_symbols()
|
||||
require("telescope.builtin").lsp_references()
|
||||
require("telescope.builtin").builtin()
|
||||
require("telescope.builtin").fd()
|
||||
require("telescope.builtin").command_history()
|
||||
require("telescope.builtin").search_history()
|
||||
require("telescope.builtin").live_grep()
|
||||
require("telescope.builtin").loclist()
|
||||
|
||||
-- TODO: make a function that puts stuff into quickfix.
|
||||
-- that way we can test this better.
|
||||
require('telescope.builtin').quickfix()
|
||||
require("telescope.builtin").quickfix()
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
RELOAD('telescope')
|
||||
RELOAD "telescope"
|
||||
|
||||
local finders = require('telescope.finders')
|
||||
local make_entry = require('telescope.make_entry')
|
||||
local previewers = require('telescope.previewers')
|
||||
local pickers = require('telescope.pickers')
|
||||
local sorters = require('telescope.sorters')
|
||||
local finders = require "telescope.finders"
|
||||
local make_entry = require "telescope.make_entry"
|
||||
local previewers = require "telescope.previewers"
|
||||
local pickers = require "telescope.pickers"
|
||||
local sorters = require "telescope.sorters"
|
||||
|
||||
local find_files = function(opts)
|
||||
opts = opts or {}
|
||||
opts.prompt_prefix = ''
|
||||
opts.prompt_prefix = ""
|
||||
|
||||
local find_command = opts.find_command
|
||||
|
||||
if not find_command then
|
||||
if 1 == vim.fn.executable("fd") then
|
||||
find_command = { 'fd', '--type', 'f' }
|
||||
elseif 1 == vim.fn.executable("fdfind") then
|
||||
find_command = { 'fdfind', '--type', 'f' }
|
||||
elseif 1 == vim.fn.executable("rg") then
|
||||
find_command = { 'rg', '--files' }
|
||||
if 1 == vim.fn.executable "fd" then
|
||||
find_command = { "fd", "--type", "f" }
|
||||
elseif 1 == vim.fn.executable "fdfind" then
|
||||
find_command = { "fdfind", "--type", "f" }
|
||||
elseif 1 == vim.fn.executable "rg" then
|
||||
find_command = { "rg", "--files" }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -29,11 +29,8 @@ local find_files = function(opts)
|
||||
opts.entry_maker = opts.entry_maker or make_entry.gen_from_file(opts)
|
||||
|
||||
local p = pickers.new(opts, {
|
||||
prompt = 'Find Files',
|
||||
finder = finders.new_oneshot_job(
|
||||
find_command,
|
||||
opts
|
||||
),
|
||||
prompt = "Find Files",
|
||||
finder = finders.new_oneshot_job(find_command, opts),
|
||||
previewer = previewers.cat.new(opts),
|
||||
sorter = sorters.get_fuzzy_file(),
|
||||
|
||||
@@ -42,21 +39,24 @@ local find_files = function(opts)
|
||||
|
||||
local count = 0
|
||||
p:register_completion_callback(function(s)
|
||||
print(count, vim.inspect(s.stats, {
|
||||
process = function(item)
|
||||
if type(item) == 'string' and item:sub(1, 1) == '_' then
|
||||
return nil
|
||||
end
|
||||
print(
|
||||
count,
|
||||
vim.inspect(s.stats, {
|
||||
process = function(item)
|
||||
if type(item) == "string" and item:sub(1, 1) == "_" then
|
||||
return nil
|
||||
end
|
||||
|
||||
return item
|
||||
end,
|
||||
}))
|
||||
return item
|
||||
end,
|
||||
})
|
||||
)
|
||||
|
||||
count = count + 1
|
||||
end)
|
||||
|
||||
local feed = function(text, feed_opts)
|
||||
feed_opts = feed_opts or 'n'
|
||||
feed_opts = feed_opts or "n"
|
||||
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(text, true, false, true), feed_opts, true)
|
||||
end
|
||||
|
||||
@@ -68,10 +68,10 @@ local find_files = function(opts)
|
||||
end
|
||||
|
||||
vim.wait(300, function() end)
|
||||
feed("<CR>", '')
|
||||
feed("<CR>", "")
|
||||
|
||||
coroutine.yield()
|
||||
print("STILL CALLED?")
|
||||
print "STILL CALLED?"
|
||||
end))
|
||||
|
||||
p:find()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
require('plenary.reload').reload_module('plenary')
|
||||
require('plenary.reload').reload_module('telescope')
|
||||
require("plenary.reload").reload_module "plenary"
|
||||
require("plenary.reload").reload_module "telescope"
|
||||
|
||||
--[[
|
||||
|
||||
@@ -8,11 +8,11 @@ Goals:
|
||||
|
||||
--]]
|
||||
|
||||
local finders = require('telescope.finders')
|
||||
local make_entry = require('telescope.make_entry')
|
||||
local pickers = require('telescope.pickers')
|
||||
local sorters = require('telescope.sorters')
|
||||
local EntryManager = require('telescope.entry_manager')
|
||||
local finders = require "telescope.finders"
|
||||
local make_entry = require "telescope.make_entry"
|
||||
local pickers = require "telescope.pickers"
|
||||
local sorters = require "telescope.sorters"
|
||||
local EntryManager = require "telescope.entry_manager"
|
||||
|
||||
local find_and_sort_test = function(prompt, f, s)
|
||||
local info = {}
|
||||
@@ -42,10 +42,7 @@ local find_and_sort_test = function(prompt, f, s)
|
||||
end
|
||||
|
||||
info.added = info.added + 1
|
||||
entry_manager:add_entry(
|
||||
s:score(prompt, entry),
|
||||
entry
|
||||
)
|
||||
entry_manager:add_entry(s:score(prompt, entry), entry)
|
||||
end
|
||||
|
||||
local process_complete = function()
|
||||
@@ -58,7 +55,9 @@ local find_and_sort_test = function(prompt, f, s)
|
||||
f(prompt, process_result, process_complete)
|
||||
|
||||
-- Wait until we're done to return
|
||||
vim.wait(5000, function() return completed end, 10)
|
||||
vim.wait(5000, function()
|
||||
return completed
|
||||
end, 10)
|
||||
|
||||
return entry_manager, info
|
||||
end
|
||||
@@ -74,42 +73,33 @@ local info_to_csv = function(info, filename)
|
||||
writer:write(info.inserted .. "\t")
|
||||
writer:write(info.total .. "\t")
|
||||
writer:write(info.set_entry .. "\t")
|
||||
writer:write(string.format("%.0f", collectgarbage("count")) .. "\t")
|
||||
writer:write("\n")
|
||||
writer:write(string.format("%.0f", collectgarbage "count") .. "\t")
|
||||
writer:write "\n"
|
||||
|
||||
writer:close()
|
||||
end
|
||||
|
||||
local cwd = vim.fn.expand "~/build/neovim"
|
||||
|
||||
local cwd = vim.fn.expand("~/build/neovim")
|
||||
|
||||
collectgarbage("collect")
|
||||
collectgarbage "collect"
|
||||
for _ = 1, 1 do
|
||||
|
||||
-- local s = sorters.get_fuzzy_file()
|
||||
local s = sorters.get_generic_fuzzy_sorter()
|
||||
local finder = finders.new_oneshot_job(
|
||||
{"fdfind"},
|
||||
{
|
||||
cwd = cwd,
|
||||
entry_maker = make_entry.gen_from_file {cwd = cwd},
|
||||
-- disable_devicons = true,
|
||||
-- maximum_results = 1000,
|
||||
}
|
||||
)
|
||||
local finder = finders.new_oneshot_job({ "fdfind" }, {
|
||||
cwd = cwd,
|
||||
entry_maker = make_entry.gen_from_file { cwd = cwd },
|
||||
-- disable_devicons = true,
|
||||
-- maximum_results = 1000,
|
||||
})
|
||||
|
||||
local res, info = find_and_sort_test(
|
||||
"pickers.lua",
|
||||
finder,
|
||||
s
|
||||
)
|
||||
local res, info = find_and_sort_test("pickers.lua", finder, s)
|
||||
|
||||
-- print(vim.inspect(res:get_entry(1)))
|
||||
-- print(vim.inspect(info))
|
||||
|
||||
info_to_csv(info, "/home/tj/tmp/profile.csv")
|
||||
|
||||
collectgarbage("collect")
|
||||
collectgarbage "collect"
|
||||
end
|
||||
-- No skip: 2,206,186
|
||||
-- Ya skip: 2,133
|
||||
|
||||
@@ -1,29 +1,25 @@
|
||||
RELOAD('plenary')
|
||||
RELOAD('telescope')
|
||||
RELOAD "plenary"
|
||||
RELOAD "telescope"
|
||||
|
||||
local finders = require('telescope.finders')
|
||||
local make_entry = require('telescope.make_entry')
|
||||
local previewers = require('telescope.previewers')
|
||||
local pickers = require('telescope.pickers')
|
||||
local sorters = require('telescope.sorters')
|
||||
local finders = require "telescope.finders"
|
||||
local make_entry = require "telescope.make_entry"
|
||||
local previewers = require "telescope.previewers"
|
||||
local pickers = require "telescope.pickers"
|
||||
local sorters = require "telescope.sorters"
|
||||
|
||||
local cwd = vim.fn.expand("~/build/neovim")
|
||||
local cwd = vim.fn.expand "~/build/neovim"
|
||||
|
||||
pickers.new {
|
||||
prompt = 'Large search',
|
||||
finder = finders.new_oneshot_job(
|
||||
{"fdfind"},
|
||||
{
|
||||
cwd = cwd,
|
||||
entry_maker = make_entry.gen_from_file {cwd = cwd},
|
||||
-- disable_devicons = true,
|
||||
-- maximum_results = 1000,
|
||||
}
|
||||
),
|
||||
pickers.new({
|
||||
prompt = "Large search",
|
||||
finder = finders.new_oneshot_job({ "fdfind" }, {
|
||||
cwd = cwd,
|
||||
entry_maker = make_entry.gen_from_file { cwd = cwd },
|
||||
-- disable_devicons = true,
|
||||
-- maximum_results = 1000,
|
||||
}),
|
||||
sorter = sorters.get_fuzzy_file(),
|
||||
previewer = previewers.cat.new{cwd = cwd},
|
||||
}:find()
|
||||
|
||||
previewer = previewers.cat.new { cwd = cwd },
|
||||
}):find()
|
||||
|
||||
-- vim.wait(3000, function()
|
||||
-- vim.cmd [[redraw!]]
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
require('plenary.reload').reload_module('telescope')
|
||||
require("plenary.reload").reload_module "telescope"
|
||||
|
||||
local finders = require('telescope.finders')
|
||||
local pickers = require('telescope.pickers')
|
||||
local sorters = require('telescope.sorters')
|
||||
local previewers = require('telescope.previewers')
|
||||
local make_entry = require('telescope.make_entry')
|
||||
local finders = require "telescope.finders"
|
||||
local pickers = require "telescope.pickers"
|
||||
local sorters = require "telescope.sorters"
|
||||
local previewers = require "telescope.previewers"
|
||||
local make_entry = require "telescope.make_entry"
|
||||
|
||||
local my_list = {
|
||||
'lua/telescope/WIP.lua',
|
||||
'lua/telescope/actions.lua',
|
||||
'lua/telescope/builtin.lua',
|
||||
"lua/telescope/WIP.lua",
|
||||
"lua/telescope/actions.lua",
|
||||
"lua/telescope/builtin.lua",
|
||||
}
|
||||
|
||||
local opts = {}
|
||||
|
||||
pickers.new(opts, {
|
||||
prompt = 'Telescope Builtin',
|
||||
finder = finders.new_table {
|
||||
prompt = "Telescope Builtin",
|
||||
finder = finders.new_table {
|
||||
results = my_list,
|
||||
},
|
||||
sorter = sorters.get_generic_fuzzy_sorter(),
|
||||
sorter = sorters.get_generic_fuzzy_sorter(),
|
||||
previewer = previewers.cat.new(opts),
|
||||
}):find()
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
-- TODO: Add a ladder test.
|
||||
-- 1, 2, 4, 8, 16, 32 attempts
|
||||
|
||||
RELOAD('plenary')
|
||||
RELOAD "plenary"
|
||||
-- RELOAD('telescope')
|
||||
|
||||
local profiler = require('plenary.profile.lua_profiler')
|
||||
local Job = require('plenary.job')
|
||||
local profiler = require "plenary.profile.lua_profiler"
|
||||
local Job = require "plenary.job"
|
||||
|
||||
BIG_LIST = nil
|
||||
BIG_LIST = BIG_LIST or Job:new { command = 'fdfind', cwd = '~/build/' }:sync()
|
||||
BIG_LIST = BIG_LIST or Job:new({ command = "fdfind", cwd = "~/build/" }):sync()
|
||||
print(#BIG_LIST)
|
||||
|
||||
local do_profile = true
|
||||
local sorter_to_test = require('telescope.sorters').get_fuzzy_file()
|
||||
local sorter_to_test = require("telescope.sorters").get_fuzzy_file()
|
||||
|
||||
local strings_to_test = { "", "ev", "eval.c", "neovim/eval.c" }
|
||||
|
||||
@@ -25,7 +25,7 @@ local first_results = setmetatable({}, {
|
||||
local obj = {}
|
||||
rawset(t, k, obj)
|
||||
return obj
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
local second_results = {}
|
||||
@@ -66,6 +66,5 @@ print(vim.inspect(first_results))
|
||||
|
||||
if do_profile then
|
||||
profiler.stop()
|
||||
profiler.report('/home/tj/tmp/profiler_score.txt')
|
||||
profiler.report "/home/tj/tmp/profiler_score.txt"
|
||||
end
|
||||
|
||||
|
||||
@@ -1,19 +1,24 @@
|
||||
|
||||
-- local actions = require('telescope.actions')
|
||||
-- local utils = require('telescope.utils')
|
||||
require('telescope')
|
||||
local finders = require('telescope.finders')
|
||||
local make_entry = require('telescope.make_entry')
|
||||
local previewers = require('telescope.previewers')
|
||||
local pickers = require('telescope.pickers')
|
||||
local sorters = require('telescope.sorters')
|
||||
require "telescope"
|
||||
local finders = require "telescope.finders"
|
||||
local make_entry = require "telescope.make_entry"
|
||||
local previewers = require "telescope.previewers"
|
||||
local pickers = require "telescope.pickers"
|
||||
local sorters = require "telescope.sorters"
|
||||
|
||||
local log = require('telescope.log')
|
||||
local log = require "telescope.log"
|
||||
|
||||
local real_opts = setmetatable({}, { __mode = 'v' })
|
||||
local opts = setmetatable({}, {
|
||||
__index = function(t, k) log.debug("accessing:", k); return real_opts[k] end,
|
||||
__newindex = function(t, k, v) log.debug("setting:", k, v); real_opts[k] = v end
|
||||
local real_opts = setmetatable({}, { __mode = "v" })
|
||||
local opts = setmetatable({}, {
|
||||
__index = function(t, k)
|
||||
log.debug("accessing:", k)
|
||||
return real_opts[k]
|
||||
end,
|
||||
__newindex = function(t, k, v)
|
||||
log.debug("setting:", k, v)
|
||||
real_opts[k] = v
|
||||
end,
|
||||
})
|
||||
|
||||
opts.entry_maker = opts.entry_maker or make_entry.gen_from_file()
|
||||
@@ -31,17 +36,14 @@ end
|
||||
-- assert(not opts.entry_maker)
|
||||
|
||||
local picker_config = {
|
||||
prompt = 'Git File',
|
||||
finder = finders.new_oneshot_job(
|
||||
{ "git", "ls-files", "-o", "--exclude-standard", "-c" }
|
||||
, opts
|
||||
),
|
||||
prompt = "Git File",
|
||||
finder = finders.new_oneshot_job({ "git", "ls-files", "-o", "--exclude-standard", "-c" }, opts),
|
||||
-- previewer = previewers.cat.new(opts),
|
||||
-- sorter = sorters.get_fuzzy_file(opts),
|
||||
-- sorter = sorters.get_fuzzy_file(),
|
||||
}
|
||||
|
||||
log.debug("Done with config")
|
||||
log.debug "Done with config"
|
||||
|
||||
local x = pickers.new(picker_config)
|
||||
x:find()
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
RELOAD('telescope')
|
||||
RELOAD "telescope"
|
||||
|
||||
local resolve = require('telescope.config.resolve')
|
||||
local resolve = require "telescope.config.resolve"
|
||||
|
||||
local eq = function(a, b)
|
||||
if a ~= b then
|
||||
error(string.format(
|
||||
"Expected a == b, got: %s and %s", vim.inspect(a), vim.inspect(b)
|
||||
))
|
||||
error(string.format("Expected a == b, got: %s and %s", vim.inspect(a), vim.inspect(b)))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -25,30 +23,29 @@ eq(height_config, opt.preview)
|
||||
eq(height_config, opt.prompt)
|
||||
eq(height_config, opt.results)
|
||||
|
||||
local table_val = {'a'}
|
||||
local table_val = { "a" }
|
||||
opt = resolve.win_option(nil, table_val)
|
||||
eq(table_val, opt.preview)
|
||||
eq(table_val, opt.prompt)
|
||||
eq(table_val, opt.results)
|
||||
|
||||
local prompt_override = {'a', prompt = 'b'}
|
||||
local prompt_override = { "a", prompt = "b" }
|
||||
opt = resolve.win_option(prompt_override)
|
||||
eq('a', opt.preview)
|
||||
eq('a', opt.results)
|
||||
eq('b', opt.prompt)
|
||||
eq("a", opt.preview)
|
||||
eq("a", opt.results)
|
||||
eq("b", opt.prompt)
|
||||
|
||||
local all_specified = {preview = 'a', prompt = 'b', results = 'c'}
|
||||
local all_specified = { preview = "a", prompt = "b", results = "c" }
|
||||
opt = resolve.win_option(all_specified)
|
||||
eq('a', opt.preview)
|
||||
eq('b', opt.prompt)
|
||||
eq('c', opt.results)
|
||||
|
||||
local some_specified = {prompt = 'b', results = 'c'}
|
||||
opt = resolve.win_option(some_specified, 'a')
|
||||
eq('a', opt.preview)
|
||||
eq('b', opt.prompt)
|
||||
eq('c', opt.results)
|
||||
eq("a", opt.preview)
|
||||
eq("b", opt.prompt)
|
||||
eq("c", opt.results)
|
||||
|
||||
local some_specified = { prompt = "b", results = "c" }
|
||||
opt = resolve.win_option(some_specified, "a")
|
||||
eq("a", opt.preview)
|
||||
eq("b", opt.prompt)
|
||||
eq("c", opt.results)
|
||||
|
||||
eq(10, resolve.resolve_height(0.1)(nil, 24, 100))
|
||||
eq(2, resolve.resolve_width(0.1)(nil, 24, 100))
|
||||
@@ -62,4 +59,4 @@ eq(24, resolve.resolve_width(50)(nil, 24, 100))
|
||||
-- eq('b', opt.prompt)
|
||||
-- eq('c', opt.results)
|
||||
|
||||
print("DONE!")
|
||||
print "DONE!"
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
RELOAD('telescope')
|
||||
RELOAD "telescope"
|
||||
|
||||
local actions = require('telescope.actions')
|
||||
local finders = require('telescope.finders')
|
||||
local make_entry = require('telescope.make_entry')
|
||||
local previewers = require('telescope.previewers')
|
||||
local pickers = require('telescope.pickers')
|
||||
local sorters = require('telescope.sorters')
|
||||
local utils = require('telescope.utils')
|
||||
local actions = require "telescope.actions"
|
||||
local finders = require "telescope.finders"
|
||||
local make_entry = require "telescope.make_entry"
|
||||
local previewers = require "telescope.previewers"
|
||||
local pickers = require "telescope.pickers"
|
||||
local sorters = require "telescope.sorters"
|
||||
local utils = require "telescope.utils"
|
||||
|
||||
local slow_proc = function(opts)
|
||||
opts = opts or {}
|
||||
@@ -18,11 +18,8 @@ local slow_proc = function(opts)
|
||||
opts.entry_maker = opts.entry_maker or make_entry.gen_from_file(opts)
|
||||
|
||||
local p = pickers.new(opts, {
|
||||
prompt = 'Slow Proc',
|
||||
finder = finders.new_oneshot_job(
|
||||
{"./scratch/slow_proc.sh"},
|
||||
opts
|
||||
),
|
||||
prompt = "Slow Proc",
|
||||
finder = finders.new_oneshot_job({ "./scratch/slow_proc.sh" }, opts),
|
||||
previewer = previewers.cat.new(opts),
|
||||
sorter = sorters.get_fuzzy_file(),
|
||||
|
||||
@@ -31,21 +28,24 @@ local slow_proc = function(opts)
|
||||
|
||||
local count = 0
|
||||
p:register_completion_callback(function(s)
|
||||
print(count, vim.inspect(s.stats, {
|
||||
process = function(item)
|
||||
if type(item) == 'string' and item:sub(1, 1) == '_' then
|
||||
return nil
|
||||
end
|
||||
print(
|
||||
count,
|
||||
vim.inspect(s.stats, {
|
||||
process = function(item)
|
||||
if type(item) == "string" and item:sub(1, 1) == "_" then
|
||||
return nil
|
||||
end
|
||||
|
||||
return item
|
||||
end,
|
||||
}))
|
||||
return item
|
||||
end,
|
||||
})
|
||||
)
|
||||
|
||||
count = count + 1
|
||||
end)
|
||||
|
||||
local feed = function(text)
|
||||
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(text, true, false, true), 'n', true)
|
||||
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(text, true, false, true), "n", true)
|
||||
end
|
||||
|
||||
if false then
|
||||
@@ -64,7 +64,6 @@ local slow_proc = function(opts)
|
||||
end))
|
||||
end
|
||||
|
||||
|
||||
p:find()
|
||||
end
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
local tester = require('telescope.pickers._test')
|
||||
local helper = require('telescope.pickers._test_helpers')
|
||||
local tester = require "telescope.pickers._test"
|
||||
local helper = require "telescope.pickers._test_helpers"
|
||||
|
||||
tester.builtin_picker('find_files', 'README.md', {
|
||||
tester.builtin_picker("find_files", "README.md", {
|
||||
post_close = {
|
||||
{'README.md', helper.get_file },
|
||||
}
|
||||
{ "README.md", helper.get_file },
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
require('plenary.reload').reload_module('plenary')
|
||||
require('plenary.reload').reload_module('telescope')
|
||||
require("plenary.reload").reload_module "plenary"
|
||||
require("plenary.reload").reload_module "telescope"
|
||||
|
||||
local tester = require('telescope.pickers._test')
|
||||
local helper = require('telescope.pickers._test_helpers')
|
||||
local tester = require "telescope.pickers._test"
|
||||
local helper = require "telescope.pickers._test_helpers"
|
||||
|
||||
tester.builtin_picker('find_files', 'telescope<c-n>', {
|
||||
tester.builtin_picker("find_files", "telescope<c-n>", {
|
||||
post_close = {
|
||||
tester.not_ { 'plugin/telescope.vim', helper.get_file },
|
||||
tester.not_ { "plugin/telescope.vim", helper.get_file },
|
||||
},
|
||||
}, {
|
||||
sorting_strategy = "descending",
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
local tester = require('telescope.pickers._test')
|
||||
local helper = require('telescope.pickers._test_helpers')
|
||||
local tester = require "telescope.pickers._test"
|
||||
local helper = require "telescope.pickers._test_helpers"
|
||||
|
||||
tester.builtin_picker('find_files', 'fixtures/file<c-p>', {
|
||||
tester.builtin_picker("find_files", "fixtures/file<c-p>", {
|
||||
post_close = {
|
||||
{ 'lua/tests/fixtures/file_abc.txt', helper.get_selection_value },
|
||||
{ "lua/tests/fixtures/file_abc.txt", helper.get_selection_value },
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user