1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-23 00:39:13 +02:00
Files
.devcontainer
.github
.vscode
cmd
demo
docs
pkg
app
cheatsheet
commands
common
config
constants
env
fakes
gui
context
controllers
helpers
amend_helper.go
app_status_helper.go
bisect_helper.go
branches_helper.go
cherry_pick_helper.go
commits_helper.go
commits_helper_test.go
confirmation_helper.go
credentials_helper.go
diff_helper.go
files_helper.go
fixup_helper.go
fixup_helper_test.go
gpg_helper.go
helpers.go
host_helper.go
inline_status_helper.go
merge_and_rebase_helper.go
merge_conflicts_helper.go
mode_helper.go
patch_building_helper.go
record_directory_helper.go
refresh_helper.go
refs_helper.go
repos_helper.go
search_helper.go
snake_helper.go
staging_helper.go
sub_commits_helper.go
suggestions_helper.go
tags_helper.go
update_helper.go
upstream_helper.go
upstream_helper_test.go
view_helper.go
window_arrangement_helper.go
window_arrangement_helper_test.go
window_helper.go
working_tree_helper.go
worktree_helper.go
attach.go
base_controller.go
basic_commits_controller.go
bisect_controller.go
branches_controller.go
command_log_controller.go
commit_description_controller.go
commit_message_controller.go
commits_files_controller.go
common.go
confirmation_controller.go
context_lines_controller.go
custom_patch_options_menu_action.go
diffing_menu_action.go
files_controller.go
filter_controller.go
filtering_menu_action.go
git_flow_controller.go
global_controller.go
jump_to_side_window_controller.go
list_controller.go
list_controller_trait.go
local_commits_controller.go
local_commits_controller_test.go
menu_controller.go
merge_conflicts_controller.go
options_menu_action.go
patch_building_controller.go
patch_explorer_controller.go
quit_actions.go
reflog_commits_controller.go
remote_branches_controller.go
remotes_controller.go
rename_similarity_threshold_controller.go
screen_mode_actions.go
scroll_off_margin.go
scroll_off_margin_test.go
search_controller.go
search_prompt_controller.go
shell_command_action.go
side_window_controller.go
snake_controller.go
staging_controller.go
stash_controller.go
status_controller.go
sub_commits_controller.go
submodules_controller.go
suggestions_controller.go
switch_to_diff_files_controller.go
switch_to_sub_commits_controller.go
sync_controller.go
tags_controller.go
toggle_whitespace_action.go
undo_controller.go
vertical_scroll_controller.go
workspace_reset_controller.go
worktree_options_controller.go
worktrees_controller.go
filetree
keybindings
mergeconflicts
modes
patch_exploring
popup
presentation
services
status
style
types
background.go
command_log_panel.go
context.go
context_config.go
controllers.go
dummies.go
editors.go
extras_panel.go
global_handlers.go
gui.go
gui_common.go
gui_driver.go
information_panel.go
keybindings.go
layout.go
main_panels.go
menu_panel.go
options_map.go
pty.go
pty_windows.go
recent_repos_panel.go
tasks_adapter.go
test_mode.go
view_helpers.go
views.go
i18n
integration
jsonschema
logs
snake
tasks
theme
updates
utils
schema
scripts
test
vendor
.codespellrc
.editorconfig
.gitattributes
.gitignore
.golangci.yml
.goreleaser.yml
CODE-OF-CONDUCT.md
CONTRIBUTING.md
Dockerfile
LICENSE
Makefile
README.md
VISION.md
go.mod
go.sum
main.go
lazygit/pkg/gui/controllers/helpers/fixup_helper_test.go
Stefan Haller 880528b2e4 Also return hunks with only added lines from parseDiff
We aren't using them, yet, except for deciding whether to show the warning about
hunks with only added lines.

Add a bit of test coverage for parseDiff while we're at it.
2024-06-01 08:31:18 +02:00

138 lines
2.6 KiB
Go

package helpers
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestFixupHelper_parseDiff(t *testing.T) {
scenarios := []struct {
name string
diff string
expectedDeletedLineHunks []*hunk
expectedAddedLineHunks []*hunk
}{
{
name: "no diff",
diff: "",
expectedDeletedLineHunks: []*hunk{},
expectedAddedLineHunks: []*hunk{},
},
{
name: "hunk with only deleted lines",
diff: `
diff --git a/file1.txt b/file1.txt
index 9ce8efb33..aaf2a4666 100644
--- a/file1.txt
+++ b/file1.txt
@@ -3 +2,0 @@ bbb
-xxx
`,
expectedDeletedLineHunks: []*hunk{
{
filename: "file1.txt",
startLineIdx: 3,
numLines: 1,
},
},
expectedAddedLineHunks: []*hunk{},
},
{
name: "hunk with deleted and added lines",
diff: `
diff --git a/file1.txt b/file1.txt
index 9ce8efb33..eb246cf98 100644
--- a/file1.txt
+++ b/file1.txt
@@ -3 +3 @@ bbb
-xxx
+yyy
`,
expectedDeletedLineHunks: []*hunk{
{
filename: "file1.txt",
startLineIdx: 3,
numLines: 1,
},
},
expectedAddedLineHunks: []*hunk{},
},
{
name: "hunk with only added lines",
diff: `
diff --git a/file1.txt b/file1.txt
index 9ce8efb33..fb5e469e7 100644
--- a/file1.txt
+++ b/file1.txt
@@ -4,0 +5,2 @@ ddd
+xxx
+yyy
`,
expectedDeletedLineHunks: []*hunk{},
expectedAddedLineHunks: []*hunk{
{
filename: "file1.txt",
startLineIdx: 4,
numLines: 2,
},
},
},
{
name: "several hunks in different files",
diff: `
diff --git a/file1.txt b/file1.txt
index 9ce8efb33..0632e41b0 100644
--- a/file1.txt
+++ b/file1.txt
@@ -2 +1,0 @@ aaa
-bbb
@@ -4 +3 @@ ccc
-ddd
+xxx
@@ -6,0 +6 @@ fff
+zzz
diff --git a/file2.txt b/file2.txt
index 9ce8efb33..0632e41b0 100644
--- a/file2.txt
+++ b/file2.txt
@@ -0,3 +1,0 @@ aaa
-aaa
-bbb
-ccc
`,
expectedDeletedLineHunks: []*hunk{
{
filename: "file1.txt",
startLineIdx: 2,
numLines: 1,
},
{
filename: "file1.txt",
startLineIdx: 4,
numLines: 1,
},
{
filename: "file2.txt",
startLineIdx: 0,
numLines: 3,
},
},
expectedAddedLineHunks: []*hunk{
{
filename: "file1.txt",
startLineIdx: 6,
numLines: 1,
},
},
},
}
for _, s := range scenarios {
t.Run(s.name, func(t *testing.T) {
deletedLineHunks, addedLineHunks := parseDiff(s.diff)
assert.Equal(t, s.expectedDeletedLineHunks, deletedLineHunks)
assert.Equal(t, s.expectedAddedLineHunks, addedLineHunks)
})
}
}