|
| 1 | +local live_command = require("live-command") |
| 2 | + |
| 3 | +describe("inline_highlights", function() |
| 4 | + -- Checks for the case when the end of the line was unchanged |
| 5 | + it("single insertion", function() |
| 6 | + local highlights = {} |
| 7 | + local updated_lines = { "new word" } |
| 8 | + live_command._add_inline_highlights(1, { "word" }, updated_lines, true, highlights) |
| 9 | + |
| 10 | + assert.are_same({ |
| 11 | + { kind = "insertion", line = 1, column = 1, length = 4 }, |
| 12 | + }, highlights) |
| 13 | + assert.are_same({ "new word" }, updated_lines) |
| 14 | + end) |
| 15 | + |
| 16 | + it("insertions 1", function() |
| 17 | + local highlights = {} |
| 18 | + local updated_lines = { "new word new" } |
| 19 | + live_command._add_inline_highlights(1, { "word" }, updated_lines, true, highlights) |
| 20 | + |
| 21 | + assert.are_same({ |
| 22 | + { kind = "insertion", line = 1, column = 1, length = 4 }, |
| 23 | + { kind = "insertion", line = 1, column = 9, length = 4 }, |
| 24 | + }, highlights) |
| 25 | + assert.are_same({ "new word new" }, updated_lines) |
| 26 | + end) |
| 27 | + |
| 28 | + it("insertions 2", function() |
| 29 | + local highlights = {} |
| 30 | + local updated_lines = { "new word new" } |
| 31 | + live_command._add_inline_highlights(1, { "word" }, updated_lines, true, highlights) |
| 32 | + |
| 33 | + assert.are_same({ |
| 34 | + { kind = "insertion", line = 1, column = 1, length = 4 }, |
| 35 | + { kind = "insertion", line = 1, column = 9, length = 4 }, |
| 36 | + }, highlights) |
| 37 | + assert.are_same({ "new word new" }, updated_lines) |
| 38 | + end) |
| 39 | + |
| 40 | + it("insertions + deletion", function() |
| 41 | + local highlights = {} |
| 42 | + local updated_lines = { "test1" } |
| 43 | + live_command._add_inline_highlights(1, { "a test" }, updated_lines, true, highlights) |
| 44 | + |
| 45 | + assert.are_same({ |
| 46 | + { kind = "deletion", line = 1, column = 1, length = 2 }, |
| 47 | + { kind = "insertion", line = 1, column = 7, length = 1 }, |
| 48 | + }, highlights) |
| 49 | + assert.are_same({ "a test1" }, updated_lines) |
| 50 | + end) |
| 51 | + |
| 52 | + it("change", function() |
| 53 | + local highlights = {} |
| 54 | + local updated_lines = { " x.insert" } |
| 55 | + live_command._add_inline_highlights(1, { " table.insert" }, updated_lines, true, highlights) |
| 56 | + |
| 57 | + assert.are_same({ |
| 58 | + { kind = "change", line = 1, column = 7, length = 1 }, |
| 59 | + }, highlights) |
| 60 | + assert.are_same({ " x.insert" }, updated_lines) |
| 61 | + end) |
| 62 | + |
| 63 | + it("#kek change + deletion", function() |
| 64 | + local highlights = {} |
| 65 | + local updated_lines = { "lel" } |
| 66 | + live_command._add_inline_highlights(1, { "-- require plugins.nvim-surround" }, updated_lines, true, highlights) |
| 67 | + assert.are_same({ |
| 68 | + { kind = "change", line = 1, column = 1, length = 1 }, |
| 69 | + { kind = "deletion", line = 1, column = 3, length = 2 }, |
| 70 | + { kind = "deletion", line = 1, column = 6, length = 19 }, |
| 71 | + }, highlights) |
| 72 | + assert.are_same({"le plugins.nvim-surround"}, updated_lines) |
| 73 | + end) |
| 74 | + |
| 75 | + it("deletion", function() |
| 76 | + local highlights = {} |
| 77 | + local updated_lines = { "local s" } |
| 78 | + live_command._add_inline_highlights(1, { "local tests" }, updated_lines, true, highlights) |
| 79 | + assert.are_same({ |
| 80 | + { kind = "deletion", line = 1, column = 7, length = 4 }, |
| 81 | + }, highlights) |
| 82 | + assert.are_same({ "local tests" }, updated_lines) |
| 83 | + end) |
| 84 | +end) |
0 commit comments