|
| 1 | +local eq = MiniTest.expect.equality |
| 2 | +local ref = MiniTest.expect.reference_screenshot |
| 3 | + |
| 4 | +local child = MiniTest.new_child_neovim() |
| 5 | + |
| 6 | +local T = MiniTest.new_set() |
| 7 | +T["nes"] = MiniTest.new_set({ |
| 8 | + hooks = { |
| 9 | + pre_case = function() |
| 10 | + child.restart({ "-u", "scripts/minimal_init.lua" }) |
| 11 | + child.lua_func(function() |
| 12 | + vim.lsp.config("copilot", { |
| 13 | + cmd = require("tests.mock_lsp").server, |
| 14 | + }) |
| 15 | + vim.lsp.enable("copilot") |
| 16 | + end) |
| 17 | + end, |
| 18 | + post_once = child.stop, |
| 19 | + }, |
| 20 | +}) |
| 21 | + |
| 22 | +T["nes"]["same line edit"] = function() |
| 23 | + child.cmd("edit tests/fixtures/sameline_edit.txt") |
| 24 | + ref(child.get_screenshot()) |
| 25 | + vim.uv.sleep(500) |
| 26 | + local lsp_name = child.lua_func(function() |
| 27 | + return vim.lsp.get_clients()[1].name |
| 28 | + end) |
| 29 | + eq(lsp_name, "copilot") |
| 30 | + child.lua_func(function() |
| 31 | + local copilot = vim.lsp.get_clients()[1] |
| 32 | + require("copilot-lsp.nes").request_nes(copilot) |
| 33 | + end) |
| 34 | + vim.uv.sleep(500) |
| 35 | + ref(child.get_screenshot()) |
| 36 | + child.lua_func(function() |
| 37 | + require("copilot-lsp.nes").apply_pending_nes(0) |
| 38 | + end) |
| 39 | + ref(child.get_screenshot()) |
| 40 | +end |
| 41 | + |
| 42 | +T["nes"]["multi line edit"] = function() |
| 43 | + child.cmd("edit tests/fixtures/multiline_edit.txt") |
| 44 | + ref(child.get_screenshot()) |
| 45 | + vim.uv.sleep(500) |
| 46 | + local lsp_name = child.lua_func(function() |
| 47 | + return vim.lsp.get_clients()[1].name |
| 48 | + end) |
| 49 | + eq(lsp_name, "copilot") |
| 50 | + child.lua_func(function() |
| 51 | + local copilot = vim.lsp.get_clients()[1] |
| 52 | + require("copilot-lsp.nes").request_nes(copilot) |
| 53 | + end) |
| 54 | + vim.uv.sleep(500) |
| 55 | + ref(child.get_screenshot()) |
| 56 | + child.lua_func(function() |
| 57 | + require("copilot-lsp.nes").apply_pending_nes(0) |
| 58 | + end) |
| 59 | + ref(child.get_screenshot()) |
| 60 | +end |
| 61 | + |
| 62 | +T["nes"]["removal edit"] = function() |
| 63 | + child.cmd("edit tests/fixtures/removal_edit.txt") |
| 64 | + ref(child.get_screenshot()) |
| 65 | + vim.uv.sleep(500) |
| 66 | + local lsp_name = child.lua_func(function() |
| 67 | + return vim.lsp.get_clients()[1].name |
| 68 | + end) |
| 69 | + eq(lsp_name, "copilot") |
| 70 | + child.lua_func(function() |
| 71 | + local copilot = vim.lsp.get_clients()[1] |
| 72 | + require("copilot-lsp.nes").request_nes(copilot) |
| 73 | + end) |
| 74 | + vim.uv.sleep(500) |
| 75 | + ref(child.get_screenshot()) |
| 76 | + child.lua_func(function() |
| 77 | + require("copilot-lsp.nes").apply_pending_nes(0) |
| 78 | + end) |
| 79 | + ref(child.get_screenshot()) |
| 80 | +end |
| 81 | + |
| 82 | +T["nes"]["add only edit"] = function() |
| 83 | + child.cmd("edit tests/fixtures/addonly_edit.txt") |
| 84 | + ref(child.get_screenshot()) |
| 85 | + vim.uv.sleep(500) |
| 86 | + local lsp_name = child.lua_func(function() |
| 87 | + return vim.lsp.get_clients()[1].name |
| 88 | + end) |
| 89 | + eq(lsp_name, "copilot") |
| 90 | + child.lua_func(function() |
| 91 | + local copilot = vim.lsp.get_clients()[1] |
| 92 | + require("copilot-lsp.nes").request_nes(copilot) |
| 93 | + end) |
| 94 | + vim.uv.sleep(500) |
| 95 | + ref(child.get_screenshot()) |
| 96 | + child.lua_func(function() |
| 97 | + require("copilot-lsp.nes").apply_pending_nes(0) |
| 98 | + end) |
| 99 | + ref(child.get_screenshot()) |
| 100 | +end |
| 101 | +return T |
0 commit comments