test(diffview): add test for custom context lines

Andrey Nering created

Change summary

internal/exp/diffview/diffview_test.go                                 | 17 
internal/exp/diffview/testdata/TestCustomContextLines/DarkMode.golden  | 17 
internal/exp/diffview/testdata/TestCustomContextLines/LightMode.golden | 17 
3 files changed, 51 insertions(+)

Detailed changes

internal/exp/diffview/diffview_test.go šŸ”—

@@ -68,3 +68,20 @@ func TestMultipleHunks(t *testing.T) {
 		golden.RequireEqual(t, []byte(dv.String()))
 	})
 }
+
+func TestCustomContextLines(t *testing.T) {
+	dv := diffview.New().
+		Before("main.go", TestMultipleHunksBefore).
+		After("main.go", TestMultipleHunksAfter).
+		ContextLines(4)
+
+	t.Run("LightMode", func(t *testing.T) {
+		dv = dv.Style(diffview.DefaultLightStyle)
+		golden.RequireEqual(t, []byte(dv.String()))
+	})
+
+	t.Run("DarkMode", func(t *testing.T) {
+		dv = dv.Style(diffview.DefaultDarkStyle)
+		golden.RequireEqual(t, []byte(dv.String()))
+	})
+}

internal/exp/diffview/testdata/TestCustomContextLines/DarkMode.golden šŸ”—

@@ -0,0 +1,17 @@
+Ā  …Ā Ā  …Ā   @@ -1,13 +1,15 @@                              
+Ā  1Ā Ā  1Ā   package main                                   
+Ā  2Ā Ā  2Ā                                                  
+Ā  3Ā Ā  3Ā   import (                                       
+Ā  4Ā Ā  4Ā       "fmt"                                      
+Ā   Ā Ā  5Ā +     "strings"                                  
+Ā  5Ā Ā  6Ā   )                                              
+Ā  6Ā Ā  7Ā                                                  
+Ā  7Ā Ā  8Ā   func main() {                                  
+Ā  8Ā Ā  9Ā       fmt.Println(getContent())                  
+Ā  9Ā Ā 10Ā   }                                              
+Ā 10Ā Ā 11Ā                                                  
+Ā 11Ā Ā 12Ā   func getContent() string {                     
+Ā 12Ā Ā   Ā -     return "Hello, world!"                     
+Ā   Ā Ā 13Ā +     content := strings.ToUpper("Hello, World!")
+Ā   Ā Ā 14Ā +     return content                             
+Ā 13Ā Ā 15Ā   }                                              

internal/exp/diffview/testdata/TestCustomContextLines/LightMode.golden šŸ”—

@@ -0,0 +1,17 @@
+Ā  …Ā Ā  …Ā   @@ -1,13 +1,15 @@                              
+Ā  1Ā Ā  1Ā   package main                                   
+Ā  2Ā Ā  2Ā                                                  
+Ā  3Ā Ā  3Ā   import (                                       
+Ā  4Ā Ā  4Ā       "fmt"                                      
+Ā   Ā Ā  5Ā +     "strings"                                  
+Ā  5Ā Ā  6Ā   )                                              
+Ā  6Ā Ā  7Ā                                                  
+Ā  7Ā Ā  8Ā   func main() {                                  
+Ā  8Ā Ā  9Ā       fmt.Println(getContent())                  
+Ā  9Ā Ā 10Ā   }                                              
+Ā 10Ā Ā 11Ā                                                  
+Ā 11Ā Ā 12Ā   func getContent() string {                     
+Ā 12Ā Ā   Ā -     return "Hello, world!"                     
+Ā   Ā Ā 13Ā +     content := strings.ToUpper("Hello, World!")
+Ā   Ā Ā 14Ā +     return content                             
+Ā 13Ā Ā 15Ā   }