From 357d727eca1c4f7c6cc527c2537f2cc7af8e02d5 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Thu, 5 Jun 2025 14:39:55 -0300 Subject: [PATCH] test(diffview): add test for custom context lines --- internal/exp/diffview/diffview_test.go | 17 +++++++++++++++++ .../TestCustomContextLines/DarkMode.golden | 17 +++++++++++++++++ .../TestCustomContextLines/LightMode.golden | 17 +++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 internal/exp/diffview/testdata/TestCustomContextLines/DarkMode.golden create mode 100644 internal/exp/diffview/testdata/TestCustomContextLines/LightMode.golden diff --git a/internal/exp/diffview/diffview_test.go b/internal/exp/diffview/diffview_test.go index 250f06bd9e212fcf19d16c8d47996a199eef97e1..32cccaaf6b4c03503b3c688c9fb8de8d60250ed8 100644 --- a/internal/exp/diffview/diffview_test.go +++ b/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())) + }) +} diff --git a/internal/exp/diffview/testdata/TestCustomContextLines/DarkMode.golden b/internal/exp/diffview/testdata/TestCustomContextLines/DarkMode.golden new file mode 100644 index 0000000000000000000000000000000000000000..263ada13e18ba7a28110b358be92b78fbd6a9bc8 --- /dev/null +++ b/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  }  diff --git a/internal/exp/diffview/testdata/TestCustomContextLines/LightMode.golden b/internal/exp/diffview/testdata/TestCustomContextLines/LightMode.golden new file mode 100644 index 0000000000000000000000000000000000000000..ab3295817aff64626089aa4ea8e6f1c5855c2896 --- /dev/null +++ b/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  }