diff options
| author | TJ DeVries <devries.timothyj@gmail.com> | 2020-08-03 20:40:04 -0400 |
|---|---|---|
| committer | TJ DeVries <devries.timothyj@gmail.com> | 2020-08-03 20:40:04 -0400 |
| commit | 96cac0a8c861d5cdb1bb7765cc2d20e47ebb7885 (patch) | |
| tree | 43edecaeef53e683cdacc9588c75817d62f7844f /lua/tests | |
| parent | fa0382d93e73b66e7ec769cec27b9fbb21020641 (diff) | |
Work on ngram sorter
Diffstat (limited to 'lua/tests')
| -rw-r--r-- | lua/tests/telescope_spec.lua | 107 |
1 files changed, 99 insertions, 8 deletions
diff --git a/lua/tests/telescope_spec.lua b/lua/tests/telescope_spec.lua index b6e01a6..692f469 100644 --- a/lua/tests/telescope_spec.lua +++ b/lua/tests/telescope_spec.lua @@ -1,15 +1,106 @@ --- require('plenary.test_harness'):setup_busted() +require('plenary.test_harness'):setup_busted() + +local utils = require('telescope.utils') --[[ -require("plenary.test_harness"):test_directory("busted", "./tests/telescope_spec.lua") +require("plenary.test_harness"):test_directory("busted", "./tests/") --]] -if false then - describe('Picker', function() - describe('window_dimensions', function() - it('', function() - assert(true) +describe('Picker', function() + describe('window_dimensions', function() + it('', function() + assert(true) + end) + end) + + describe('ngrams', function() + it('should capture intself in the ngram', function() + local n = utils.new_ngram() + + n:add("hi") + assert.are.same(n._grams.hi, {hi = 1}) + end) + + it('should have repeated strings count more than once', function() + local n = utils.new_ngram() + + n:add("llll") + assert.are.same(n._grams.ll, {llll = 3}) + end) + + describe('_items_sharing_ngrams', function() + -- it('should be able to find similar strings', function() + -- end) + local n + before_each(function() + n = utils.new_ngram() + + n:add("SPAM") + n:add("SPAN") + n:add("EG") + end) + + it('should find items at the start', function() + assert.are.same({ SPAM = 1, SPAN = 1 }, n:_items_sharing_ngrams("SP")) + end) + + it('should find items at the end', function() + assert.are.same({ SPAM = 1, }, n:_items_sharing_ngrams("AM")) + end) + + it('should find items at the end', function() + assert.are.same({ SPAM = 2, SPAN = 1}, n:_items_sharing_ngrams("PAM")) + end) + end) + + describe('search', function() + describe('for simple strings', function() + local n + before_each(function() + n = utils.new_ngram() + + n:add("SPAM") + n:add("SPAN") + n:add("EG") + end) + + it('should sort for equal cases', function() + assert.are.same({ "SPAM", "SPAN" }, n:search("SPAM")) + end) + + it('should sort for obvious cases', function() + assert.are.same({ "SPAM", "SPAN" }, n:search("PAM")) + end) + end) + + describe('for file paths', function() + local n + before_each(function() + n = utils.new_ngram() + + n:add("sho/rt") + n:add("telescope/init.lua") + n:add("telescope/utils.lua") + n:add("telescope/pickers.lua") + n:add("a/random/file/pickers.lua") + n:add("microscope/init.lua") + end) + + it("should find exact match", function() + assert.are.same(n:find("telescope/init.lua"), "telescope/init.lua") + assert.are.same(n:score("telescope/init.lua"), 1) + end) + + it("should find unique match", function() + assert.are.same(n:find("micro"), "microscope/init.lua") + end) + + it("should find some match", function() + assert.are.same(n:find("telini"), "telescope/init.lua") + end) end) end) end) -end +end) + + |
