summaryrefslogtreecommitdiffstats
path: root/pkg/commands
diff options
context:
space:
mode:
authorStefan Haller <stefan@haller-berlin.de>2023-08-09 17:25:49 +0200
committerStefan Haller <stefan@haller-berlin.de>2023-08-10 07:22:42 +0200
commitbf699d3a79dbe160830d56cb8d13574b8efd766c (patch)
tree2f0ebbb712c37f556db6ca250ebded385edacb55 /pkg/commands
parentf2e8d549bad89d1369b5888db2085375feeeb5aa (diff)
Add test case for LineNumberOfLine()
There's a bug in LineNumberOfLine, but the existing test coverage doesn't catch it, as the only test case for this was one where oldStart and newStart were the same for all hunks. Add a test case where newStart is different for one of the hunks; this demonstrates a bug, where all expected results from index 12 on are off by one.
Diffstat (limited to 'pkg/commands')
-rw-r--r--pkg/commands/patch/patch_test.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/pkg/commands/patch/patch_test.go b/pkg/commands/patch/patch_test.go
index bc029da0d..57d17e7c9 100644
--- a/pkg/commands/patch/patch_test.go
+++ b/pkg/commands/patch/patch_test.go
@@ -67,6 +67,29 @@ index e48a11c..b2ab81b 100644
...
`
+const twoHunksWithMoreAdditionsThanRemovals = `diff --git a/filename b/filename
+index bac359d75..6e5b89f36 100644
+--- a/filename
++++ b/filename
+@@ -1,5 +1,6 @@
+ apple
+-grape
++orange
++kiwi
+ ...
+ ...
+ ...
+@@ -8,6 +9,8 @@ grape
+ ...
+ ...
+ ...
++pear
++lemon
+ ...
+ ...
+ ...
+`
+
const twoChangesInOneHunk = `diff --git a/filename b/filename
index 9320895..6d79956 100644
--- a/filename
@@ -572,6 +595,12 @@ func TestLineNumberOfLine(t *testing.T) {
indexes: []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 1000},
expecteds: []int{1, 1, 1, 1, 1, 1, 2, 2, 3, 4, 5, 8, 8, 9, 10, 11, 12, 13, 14, 15, 15, 15, 15, 15, 15},
},
+ {
+ testName: "twoHunksWithMoreAdditionsThanRemovals",
+ patchStr: twoHunksWithMoreAdditionsThanRemovals,
+ indexes: []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 1000},
+ expecteds: []int{1, 1, 1, 1, 1, 1, 2, 2, 3, 4, 5, 6, 8, 8, 9, 10, 11, 12, 13, 14, 15, 16, 16, 16, 16, 16},
+ },
}
for _, s := range scenarios {