on main help sign in
test(diffview): add test for custom context lines
commit357d727eca1c4f7c6cc527c2537f2cc7af8e02d5 authorAndrey Nering <andreynering@users.noreply.github.com> dateThu 5 Jun 2025, 14:39 (1 year ago) parent07d4221
3 files changed+51
internal/exp/diffview/diffview_test.go+17 internal/exp/diffview/testdata/TestCustomContextLines/DarkMode.golden+17 internal/exp/diffview/testdata/TestCustomContextLines/LightMode.golden+17
internal/exp/diffview/diffview_test.go+17
@@ -68,3 +68,20 @@ func TestMultipleHunks(t *testing.T) {
6868 golden.RequireEqual(t, []byte(dv.String()))
6969 })
7070}
71+
72+func TestCustomContextLines(t *testing.T) {
73+ dv := diffview.New().
74+ Before("main.go", TestMultipleHunksBefore).
75+ After("main.go", TestMultipleHunksAfter).
76+ ContextLines(4)
77+
78+ t.Run("LightMode", func(t *testing.T) {
79+ dv = dv.Style(diffview.DefaultLightStyle)
80+ golden.RequireEqual(t, []byte(dv.String()))
81+ })
82+
83+ t.Run("DarkMode", func(t *testing.T) {
84+ dv = dv.Style(diffview.DefaultDarkStyle)
85+ golden.RequireEqual(t, []byte(dv.String()))
86+ })
87+}
internal/exp/diffview/testdata/TestCustomContextLines/DarkMode.goldennew file+17
@@ -0,0 +1,17 @@
1+  …   …  @@ -1,13 +1,15 @@ 
2+  1   1  package main 
3+  2   2   
4+  3   3  import ( 
5+  4   4  "fmt" 
6+     5 +  "strings" 
7+  5   6  ) 
8+  6   7   
9+  7   8  func main() { 
10+  8   9  fmt.Println(getContent()) 
11+  9  10  } 
12+ 10  11   
13+ 11  12  func getContent() string { 
14+ 12    -  return "Hello, world!" 
15+    13 +  content := strings.ToUpper("Hello, World!")
16+    14 +  return content 
17+ 13  15  } 
internal/exp/diffview/testdata/TestCustomContextLines/LightMode.goldennew file+17
@@ -0,0 +1,17 @@
1+  …   …  @@ -1,13 +1,15 @@ 
2+  1   1  package main 
3+  2   2   
4+  3   3  import ( 
5+  4   4  "fmt" 
6+     5 +  "strings" 
7+  5   6  ) 
8+  6   7   
9+  7   8  func main() { 
10+  8   9  fmt.Println(getContent()) 
11+  9  10  } 
12+ 10  11   
13+ 11  12  func getContent() string { 
14+ 12    -  return "Hello, world!" 
15+    13 +  content := strings.ToUpper("Hello, World!")
16+    14 +  return content 
17+ 13  15  }