|
| 1 | +require("tests.busted_setup") |
| 2 | +require("tests.mocks.vim") |
| 3 | + |
| 4 | +describe("none terminal provider", function() |
| 5 | + local terminal |
| 6 | + local saved_packages |
| 7 | + |
| 8 | + local termopen_calls |
| 9 | + local jobstart_calls |
| 10 | + |
| 11 | + before_each(function() |
| 12 | + -- Prepare vim.fn helpers used by terminal module |
| 13 | + vim.fn = vim.fn or {} |
| 14 | + vim.fn.getcwd = function() |
| 15 | + return "/mock/cwd" |
| 16 | + end |
| 17 | + vim.fn.expand = function(val) |
| 18 | + return val |
| 19 | + end |
| 20 | + |
| 21 | + -- Spy-able termopen/jobstart that count invocations |
| 22 | + termopen_calls = 0 |
| 23 | + jobstart_calls = 0 |
| 24 | + vim.fn.termopen = function(...) |
| 25 | + termopen_calls = termopen_calls + 1 |
| 26 | + return 1 |
| 27 | + end |
| 28 | + vim.fn.jobstart = function(...) |
| 29 | + jobstart_calls = jobstart_calls + 1 |
| 30 | + return 1 |
| 31 | + end |
| 32 | + |
| 33 | + -- Minimal logger + server mocks |
| 34 | + package.loaded["claudecode.logger"] = { |
| 35 | + debug = function() end, |
| 36 | + warn = function() end, |
| 37 | + error = function() end, |
| 38 | + info = function() end, |
| 39 | + setup = function() end, |
| 40 | + } |
| 41 | + package.loaded["claudecode.server.init"] = { state = { port = 12345 } } |
| 42 | + |
| 43 | + -- Ensure fresh terminal module load |
| 44 | + package.loaded["claudecode.terminal"] = nil |
| 45 | + package.loaded["claudecode.terminal.none"] = nil |
| 46 | + package.loaded["claudecode.terminal.native"] = nil |
| 47 | + package.loaded["claudecode.terminal.snacks"] = nil |
| 48 | + |
| 49 | + terminal = require("claudecode.terminal") |
| 50 | + terminal.setup({ provider = "none" }, nil, {}) |
| 51 | + end) |
| 52 | + |
| 53 | + it("does not invoke any terminal APIs", function() |
| 54 | + -- Exercise all public actions |
| 55 | + terminal.open({}, "--help") |
| 56 | + terminal.simple_toggle({}, "--resume") |
| 57 | + terminal.focus_toggle({}, "--continue") |
| 58 | + terminal.ensure_visible({}, nil) |
| 59 | + terminal.toggle_open_no_focus({}, nil) |
| 60 | + terminal.close() |
| 61 | + |
| 62 | + -- Assert no terminal processes/windows were spawned |
| 63 | + assert.are.equal(0, termopen_calls) |
| 64 | + assert.are.equal(0, jobstart_calls) |
| 65 | + end) |
| 66 | + |
| 67 | + it("returns nil for active buffer", function() |
| 68 | + local bufnr = terminal.get_active_terminal_bufnr() |
| 69 | + assert.is_nil(bufnr) |
| 70 | + end) |
| 71 | +end) |
0 commit comments