summaryrefslogtreecommitdiff
path: root/lua/tests/automated/resolver_spec.lua
blob: ac141bd6ab02c96f41915df68978c54b8793e127 (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
local eq = function(a, b)
  assert.are.same(a, b)
end

local resolve = require "telescope.config.resolve"

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)

      eq(height_config, opt.preview)
      eq(height_config, opt.prompt)
      eq(height_config, opt.results)
    end)

    it("should resolve for percentages with default", function()
      local height_config = 0.8
      local opt = resolve.win_option(nil, height_config)

      eq(height_config, opt.preview)
      eq(height_config, opt.prompt)
      eq(height_config, opt.results)
    end)

    it("should resolve table values", function()
      local table_val = { "a" }
      local opt = resolve.win_option(nil, table_val)

      eq(table_val, opt.preview)
      eq(table_val, opt.prompt)
      eq(table_val, opt.results)
    end)

    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)
    end)

    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)
    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)
    end)
  end)

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

    eq(10, resolve.resolve_width(10)(nil, 24, 100))
    eq(24, resolve.resolve_width(50)(nil, 24, 100))
  end)
end)