MCPcopy
hub / github.com/jesseduffield/lazygit / TestAdjustLineNumber

Function TestAdjustLineNumber

pkg/commands/patch/patch_test.go:658–712  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

656}
657
658func TestAdjustLineNumber(t *testing.T) {
659 type scenario struct {
660 oldLineNumbers []int
661 expectedResults []int
662 }
663 scenarios := []scenario{
664 {
665 oldLineNumbers: []int{1, 2, 3, 4, 5, 6, 7},
666 expectedResults: []int{1, 2, 2, 3, 4, 7, 8},
667 },
668 }
669
670 // The following diff was generated from old.txt:
671 // 1
672 // 2a
673 // 2b
674 // 3
675 // 4
676 // 7
677 // 8
678 // against new.txt:
679 // 1
680 // 2
681 // 3
682 // 4
683 // 5
684 // 6
685 // 7
686 // 8
687
688 // This test setup makes the test easy to understand, because the resulting
689 // adjusted line numbers are the same as the content of the lines in new.txt.
690
691 diff := `--- old.txt 2024-12-16 18:04:29
692+++ new.txt 2024-12-16 18:04:27
693@@ -2,2 +2 @@
694-2a
695-2b
696+2
697@@ -5,0 +5,2 @@
698+5
699+6
700`
701
702 patch := Parse(diff)
703
704 for _, s := range scenarios {
705 t.Run("TestAdjustLineNumber", func(t *testing.T) {
706 for idx, oldLineNumber := range s.oldLineNumbers {
707 result := patch.AdjustLineNumber(oldLineNumber)
708 assert.Equal(t, s.expectedResults[idx], result)
709 }
710 })
711 }
712}
713
714func TestIsSingleHunkForWholeFile(t *testing.T) {
715 scenarios := []struct {

Callers

nothing calls this directly

Calls 3

ParseFunction · 0.85
RunMethod · 0.65
AdjustLineNumberMethod · 0.45

Tested by

no test coverage detected