From 2aa8bcb87898ed4f45d67c640fe1d6a60b184637 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Mon, 21 Dec 2020 16:03:48 -0500 Subject: feat: Add better highlighting and new CI abilities (#355) * Revert "Revert "fix: Better highlights (#344)" (#350)" This reverts commit 7950fc8ba0accfcf6c540c7810feee646281fd8a. * better highlights take 2 * fixup * install fd find for sameness * add some debug output * more deterministic * better ci --- lua/tests/automated/pickers/find_files_spec.lua | 108 ++++++++++++++++++++++++ lua/tests/fixtures/file_a.txt | 0 lua/tests/fixtures/file_abc.txt | 0 lua/tests/manual/auto_picker.lua | 1 + lua/tests/pickers/find_files__readme.lua | 7 ++ lua/tests/pickers/find_files__with_ctrl_n.lua | 24 ++++++ 6 files changed, 140 insertions(+) create mode 100644 lua/tests/automated/pickers/find_files_spec.lua create mode 100644 lua/tests/fixtures/file_a.txt create mode 100644 lua/tests/fixtures/file_abc.txt create mode 100644 lua/tests/pickers/find_files__readme.lua create mode 100644 lua/tests/pickers/find_files__with_ctrl_n.lua (limited to 'lua/tests') diff --git a/lua/tests/automated/pickers/find_files_spec.lua b/lua/tests/automated/pickers/find_files_spec.lua new file mode 100644 index 0000000..6035075 --- /dev/null +++ b/lua/tests/automated/pickers/find_files_spec.lua @@ -0,0 +1,108 @@ +require('plenary.reload').reload_module('telescope') + +local tester = require('telescope.pickers._tests') + +describe('builtin.find_files', function() + it('should find the readme', function() + tester.run_file('find_files__readme') + end) + + it('should not display devicons when disabled', function() + tester.run_string [[ + tester.builtin_picker('find_files', 'README.md', { + post_typed = { + { "> README.md", GetPrompt }, + { "> README.md", GetLastResult }, + }, + post_close = { + { 'README.md', GetFile }, + { 'README.md', GetFile }, + } + }, { + disable_devicons = true, + sorter = require('telescope.sorters').get_fzy_sorter(), + }) + ]] + end) + + it('use devicons, if it has it when enabled', function() + if not pcall(require, 'nvim-web-devicons') then + return + end + + tester.run_string [[ + tester.builtin_picker('find_files', 'README.md', { + post_typed = { + { "> README.md", GetPrompt }, + { ">  README.md", GetLastResult } + }, + post_close = { + { 'README.md', GetFile }, + { 'README.md', GetFile }, + } + }, { + disable_devicons = false, + sorter = require('telescope.sorters').get_fzy_sorter(), + }) + ]] + end) + + it('should find the readme, using lowercase', function() + tester.run_string [[ + tester.builtin_picker('find_files', 'readme.md', { + post_close = { + { 'README.md', GetFile }, + } + }) + ]] + end) + + it('should find the pickers.lua, using lowercase', function() + tester.run_string [[ + tester.builtin_picker('find_files', 'pickers.lua', { + post_close = { + { 'pickers.lua', GetFile }, + } + }) + ]] + end) + + it('should find the pickers.lua', function() + tester.run_string [[ + tester.builtin_picker('find_files', 'pickers.lua', { + post_close = { + { 'pickers.lua', GetFile }, + { 'pickers.lua', GetFile }, + } + }) + ]] + end) + + it('should be able to c-n the items', function() + tester.run_string [[ + tester.builtin_picker('find_files', 'fixtures/file', { + post_typed = { + { + { + " lua/tests/fixtures/file_abc.txt", + "> lua/tests/fixtures/file_a.txt", + }, function() + local res = GetResults() + + return { + res[#res - 1], + res[#res], + } + end + }, + }, + post_close = { + { 'file_abc.txt', GetFile }, + }, + }, { + sorter = require('telescope.sorters').get_fzy_sorter(), + disable_devicons = true, + }) + ]] + end) +end) diff --git a/lua/tests/fixtures/file_a.txt b/lua/tests/fixtures/file_a.txt new file mode 100644 index 0000000..e69de29 diff --git a/lua/tests/fixtures/file_abc.txt b/lua/tests/fixtures/file_abc.txt new file mode 100644 index 0000000..e69de29 diff --git a/lua/tests/manual/auto_picker.lua b/lua/tests/manual/auto_picker.lua index e0433f9..e33edee 100644 --- a/lua/tests/manual/auto_picker.lua +++ b/lua/tests/manual/auto_picker.lua @@ -71,6 +71,7 @@ local find_files = function(opts) feed("", '') coroutine.yield() + print("STILL CALLED?") end)) p:find() diff --git a/lua/tests/pickers/find_files__readme.lua b/lua/tests/pickers/find_files__readme.lua new file mode 100644 index 0000000..6753d5d --- /dev/null +++ b/lua/tests/pickers/find_files__readme.lua @@ -0,0 +1,7 @@ +local tester = require('telescope.pickers._tests') + +tester.builtin_picker('find_files', 'README.md', { + post_close = { + {'README.md', function() return vim.fn.fnamemodify(vim.api.nvim_buf_get_name(0), ":.") end }, + } +}) diff --git a/lua/tests/pickers/find_files__with_ctrl_n.lua b/lua/tests/pickers/find_files__with_ctrl_n.lua new file mode 100644 index 0000000..e6eecdd --- /dev/null +++ b/lua/tests/pickers/find_files__with_ctrl_n.lua @@ -0,0 +1,24 @@ +pcall(function() RELOAD('telescope') end) + +local builtin = require('telescope.builtin') +local tester = require('telescope.pickers._tests') + +local key = 'find_files' +local input = 'fixtures/file' +local expected = 'lua/tests/fixtures/file_2.txt' +local get_actual = function() + return vim.fn.fnamemodify(vim.api.nvim_buf_get_name(0), ":.") +end + +-- local on_complete_item = tester.picker_feed(input, expected, get_actual, true) +-- +-- builtin[key] { +-- on_complete = { on_complete_item } +-- } + +tester.builtin_picker('find_files', 'fixtures/file', 'lua/tests/fixtures/file_2.txt', function() + return vim.fn.fnamemodify(vim.api.nvim_buf_get_name(0), ":.") +end, { + debug = false, +}) + -- cgit v1.2.3