summaryrefslogtreecommitdiff
path: root/mut/neovim/pack/plugins/start/quicker.nvim/tests/whitespace_spec.lua
blob: 0933276212538c5857fc0808806e79fa23acb5f0 (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
local quicker = require("quicker")
local test_util = require("tests.test_util")

describe("whitespace", function()
  before_each(function()
    require("quicker.config").trim_leading_whitespace = "common"
  end)
  after_each(function()
    test_util.reset_editor()
  end)

  it("removes common leading whitespace from valid results", function()
    local bufnr = vim.fn.bufadd(test_util.make_tmp_file("whitespace.txt", {
      "    line 1",
      "  line 2",
      "    line 3",
      "",
      "      line 4",
    }))
    vim.fn.setqflist({
      {
        bufnr = bufnr,
        text = "  line 2",
        lnum = 2,
      },
      {
        bufnr = bufnr,
        text = "    line 3",
        lnum = 3,
      },
    })
    vim.cmd.copen()
    test_util.assert_snapshot(0, "trim_whitespace")
    quicker.expand()
    test_util.assert_snapshot(0, "trim_whitespace_expanded")
  end)

  it("handles mixed tabs and spaces", function()
    local bufnr = vim.fn.bufadd(test_util.make_tmp_file("mixed_whitespace.txt", {
      "  line 1",
      "\t\tline 2",
    }))
    vim.fn.setqflist({
      {
        bufnr = bufnr,
        text = "  line 1",
        lnum = 1,
      },
      {
        bufnr = bufnr,
        text = "\t\tline 2",
        lnum = 2,
      },
    })
    vim.cmd.copen()
    test_util.assert_snapshot(0, "trim_mixed_whitespace")
  end)

  it("removes all leading whitespace", function()
    require("quicker.config").trim_leading_whitespace = "all"
    local bufnr = vim.fn.bufadd(test_util.make_tmp_file("whitespace_1.txt", {
      "    line 1",
      "  line 2",
      "    line 3",
      "",
      "      line 4",
    }))
    vim.fn.setqflist({
      {
        bufnr = bufnr,
        text = "  line 2",
        lnum = 2,
      },
      {
        bufnr = bufnr,
        text = "    line 3",
        lnum = 3,
      },
    })
    vim.cmd.copen()
    test_util.assert_snapshot(0, "trim_all_whitespace")
  end)
end)