summaryrefslogtreecommitdiff
path: root/lua/tests/automated/scroller_spec.lua
blob: f47edda64eb66d7b7e9763e114cb5f92abaa87fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
local p_scroller = require('telescope.pickers.scroller')

local eq = assert.are.same

describe('scroller', function()
  local max_results = 10

  describe('ascending cycle', function()
    local cycle_scroller = p_scroller.create('cycle', 'ascending')

    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('ascending limit', function()
    local limit_scroller = p_scroller.create('limit', 'ascending')

    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 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()
      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')

    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()
      eq(0, cycle_scroller(max_results, max_results, 0))
    end)

    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()
      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(9, cycle_scroller(max_results, 5, 4))
    end)
  end)

  describe('descending limit', function()
    local limit_scroller = p_scroller.create('limit', 'descending')

    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 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()
      local current = 5
      eq(current - 1, limit_scroller(max_results, current, 4))
    end)
  end)
end)