From f41f909fc722b2ff5f89b6d0d48a50d26e4e19d3 Mon Sep 17 00:00:00 2001 From: Cameron Date: Mon, 10 Jul 2023 22:40:40 +0200 Subject: [PATCH] Fix spec on CI --- tests/status_buf_spec.lua | 64 ++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/tests/status_buf_spec.lua b/tests/status_buf_spec.lua index 056fc3226..c0671cfdc 100644 --- a/tests/status_buf_spec.lua +++ b/tests/status_buf_spec.lua @@ -13,32 +13,43 @@ local function act(normal_cmd) status.wait_on_current_operation() end +local function find(text) + for index, line in ipairs(vim.api.nvim_buf_get_lines(0, 0, -1, true)) do + if line:match(text) then + vim.api.nvim_win_set_cursor(0, { index, 0 }) + print(">" .. tostring(index) .. " " .. line) + -- break + else + print(tostring(index) .. " " .. line) + end + end +end + describe("status buffer", function() describe("staging files - s", function() it( "can stage an untracked file under the cursor", in_prepared_repo(function() - vim.fn.setpos(".", { 0, 5, 1, 0 }) + find("untracked%.txt") act("s") - local result = get_git_status("untracked.txt") - eq("A untracked.txt\n", result) + eq("A untracked.txt\n", get_git_status("untracked.txt")) end) ) it( "can stage a tracked file under the cursor", in_prepared_repo(function() - vim.fn.setpos(".", { 0, 7, 1, 0 }) + find("Modified a%.txt") + eq(" M a.txt\n", get_git_status("a.txt")) act("s") - local result = get_git_status("a.txt") - eq(" M a.txt\n", result) + eq("M a.txt\n", get_git_status("a.txt")) end) ) it( "can stage a hunk under the cursor of a tracked file", in_prepared_repo(function() - vim.fn.setpos(".", { 0, 9, 1, 0 }) + find("Modified a%.txt") act("jjs") eq("MM a.txt\n", get_git_status("a.txt")) eq( @@ -60,7 +71,7 @@ describe("status buffer", function() it( "can stage a subsequent hunk under the cursor of a tracked file", in_prepared_repo(function() - vim.fn.setpos(".", { 0, 9, 1, 0 }) + find("Modified a%.txt") act("8js") eq("MM a.txt\n", get_git_status("a.txt")) eq( @@ -81,7 +92,7 @@ describe("status buffer", function() it( "can stage from a selection in a hunk", in_prepared_repo(function() - vim.fn.setpos(".", { 0, 9, 1, 0 }) + find("Modified a%.txt") act("jjjjVs") -- eq("M a.txt\n", get_git_status("a.txt")) eq( @@ -105,17 +116,17 @@ describe("status buffer", function() it( "can unstage a staged file under the cursor", in_prepared_repo(function() - vim.fn.setpos(".", { 0, 12, 1, 0 }) + find("Modified b%.txt") + eq("M b.txt\n", get_git_status("b.txt")) act("u") - local result = get_git_status("b.txt") - eq(" M b.txt\n", result) + eq(" M b.txt\n", get_git_status("b.txt")) end) ) it( "can unstage a hunk under the cursor of a staged file", in_prepared_repo(function() - vim.fn.setpos(".", { 0, 12, 1, 0 }) + find("Modified b%.txt") act("jju") eq("MM b.txt\n", get_git_status("b.txt")) eq( @@ -135,7 +146,7 @@ describe("status buffer", function() it( "can unstage from a selection in a hunk", in_prepared_repo(function() - vim.fn.setpos(".", { 0, 12, 1, 0 }) + find("Modified b%.txt") act("jjjjVu") eq("MM b.txt\n", get_git_status("b.txt")) eq( @@ -156,7 +167,7 @@ describe("status buffer", function() it( "can unstage a subsequent hunk from a staged file", in_prepared_repo(function() - vim.fn.setpos(".", { 0, 12, 1, 0 }) + find("Modified b%.txt") act("8ju") eq("MM b.txt\n", get_git_status("b.txt")) eq( @@ -178,17 +189,16 @@ describe("status buffer", function() it( "can discard the changes of a file under the cursor", in_prepared_repo(function() - vim.fn.setpos(".", { 0, 9, 1, 0 }) + find("Modified a%.txt") act("x") - local result = get_git_status("a.txt") - eq("", result) + eq("", get_git_status("a.txt")) end) ) it( "can discard a hunk under the cursor", in_prepared_repo(function() - vim.fn.setpos(".", { 0, 9, 1, 0 }) + find("Modified a%.txt") act("jjx") eq(" M a.txt\n", get_git_status("a.txt")) eq( @@ -209,7 +219,7 @@ describe("status buffer", function() it( "can discard a selection of a hunk", in_prepared_repo(function() - vim.fn.setpos(".", { 0, 9, 1, 0 }) + find("Modified a%.txt") act("jjjjVx") eq(" M a.txt\n", get_git_status("a.txt")) eq( @@ -236,27 +246,25 @@ describe("status buffer", function() it( "can delete an untracked file", in_prepared_repo(function() - vim.fn.setpos(".", { 0, 6, 1, 0 }) + find("untracked%.txt") act("x") - local result = get_git_status("untracked.txt") - eq("", result) + eq("", get_git_status("untracked.txt")) end) ) it( "can discard the changes of a staged file under the cursor", in_prepared_repo(function() - vim.fn.setpos(".", { 0, 12, 1, 0 }) + find("Modified b%.txt") act("x") - local result = get_git_status("b.txt") - eq("", result) + eq("", get_git_status("b.txt")) end) ) it( "can discard a hunk of the staged file under the cursor", in_prepared_repo(function() - vim.fn.setpos(".", { 0, 12, 1, 0 }) + find("Modified b%.txt") act("jjx") eq("M b.txt\n", get_git_status("b.txt")) eq( @@ -276,7 +284,7 @@ describe("status buffer", function() it( "can discard a selection of a staged file", in_prepared_repo(function() - vim.fn.setpos(".", { 0, 12, 1, 0 }) + find("Modified b%.txt") act("jjjjVx") eq("M b.txt\n", get_git_status("b.txt")) eq(