summaryrefslogtreecommitdiff
path: root/lua/tests
diff options
context:
space:
mode:
authorTJ DeVries <devries.timothyj@gmail.com>2020-12-10 23:31:28 -0500
committerTJ DeVries <devries.timothyj@gmail.com>2020-12-10 23:31:28 -0500
commitf3609abd7f9bf34ad482b1beb1c0482b76562af3 (patch)
tree4b298a725cdbcfd400a179a3d6cddede4725f8ea /lua/tests
parentb74c4b3efddf6d6031918c2e2de83e44e26da9f2 (diff)
refactor: Move scroller into own testable module
Diffstat (limited to 'lua/tests')
-rw-r--r--lua/tests/automated/scroller_spec.lua56
1 files changed, 56 insertions, 0 deletions
diff --git a/lua/tests/automated/scroller_spec.lua b/lua/tests/automated/scroller_spec.lua
new file mode 100644
index 0000000..7889573
--- /dev/null
+++ b/lua/tests/automated/scroller_spec.lua
@@ -0,0 +1,56 @@
+local p_scroller = require('telescope.pickers.scroller')
+
+local eq = assert.are.same
+
+describe('scroller', function()
+ local max_results = 10
+
+ describe('cycle', function()
+ local cycle_scroller = p_scroller.create('cycle')
+
+ 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()
+ eq(0, cycle_scroller(max_results, max_results, 0))
+ end)
+
+ 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()
+ eq(0, cycle_scroller(max_results, max_results, max_results + 1))
+ end)
+
+ it('should cycle when current results is less than max_results', function()
+ eq(0, cycle_scroller(max_results, 5, 7))
+ end)
+ end)
+
+ describe('other', function()
+ local limit_scroller = p_scroller.create('limit')
+
+ 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()
+ eq(0, limit_scroller(max_results, max_results, 0))
+ end)
+
+ it('should not cycle', function()
+ eq(0, limit_scroller(max_results, max_results, -1))
+ end)
+
+ it('should 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()
+ local current = 5
+ eq(current - 1, limit_scroller(max_results, current, 7))
+ end)
+ end)
+end)