@@ -10,16 +10,17 @@ import (
10
10
)
11
11
12
12
var formatTests = []struct {
13
- text1 string
14
- text2 string
15
- diff string
13
+ text1 string
14
+ text2 string
15
+ diff string
16
+ suppressCommon string
16
17
}{
17
- {"a b c" , "a b d e f" , "a b -c +d +e +f" },
18
- {"" , "a b c" , "+a +b +c" },
19
- {"a b c" , "" , "-a -b -c" },
20
- {"a b c" , "d e f" , "-a -b -c +d +e +f" },
21
- {"a b c d e f" , "a b d e f" , "a b -c d e f" },
22
- {"a b c e f" , "a b c d e f" , "a b c +d e f" },
18
+ {"a b c" , "a b d e f" , "a b -c +d +e +f" , "3-c 3+d 4+e 5+f" },
19
+ {"" , "a b c" , "+a +b +c" , "1+a 2+b 3+c" },
20
+ {"a b c" , "" , "-a -b -c" , "1-a 2-b 3-c" },
21
+ {"a b c" , "d e f" , "-a -b -c +d +e +f" , "1-a 2-b 3-c 1+d 2+e 3+f" },
22
+ {"a b c d e f" , "a b d e f" , "a b -c d e f" , "3-c" },
23
+ {"a b c e f" , "a b c d e f" , "a b c +d e f" , "4+d" },
23
24
}
24
25
25
26
func TestFormat (t * testing.T ) {
@@ -33,11 +34,25 @@ func TestFormat(t *testing.T) {
33
34
if text2 != "" {
34
35
text2 += "\n "
35
36
}
36
- out := Format (text1 , text2 )
37
- // Cut final \n, cut spaces, turn remaining \n into spaces.
38
- out = strings .ReplaceAll (strings .ReplaceAll (strings .TrimSuffix (out , "\n " ), " " , "" ), "\n " , " " )
39
- if out != tt .diff {
40
- t .Errorf ("diff(%q, %q) = %q, want %q" , text1 , text2 , out , tt .diff )
41
- }
37
+ compare (t , format , text1 , text2 , tt .diff )
38
+ compare (t , suppressCommon , text1 , text2 , tt .suppressCommon )
39
+ }
40
+ }
41
+
42
+ func format (text1 , text2 string ) string {
43
+ return Format (text1 , text2 )
44
+ }
45
+
46
+ func suppressCommon (text1 , text2 string ) string {
47
+ return Format (text1 , text2 , OptSuppressCommon ())
48
+ }
49
+
50
+ func compare (t * testing.T , testFn func (string , string ) string , text1 , text2 string , want string ) {
51
+ t .Helper ()
52
+ got := testFn (text1 , text2 )
53
+ // Cut final \n, cut spaces, turn remaining \n into spaces.
54
+ got = strings .ReplaceAll (strings .ReplaceAll (strings .TrimSuffix (got , "\n " ), " " , "" ), "\n " , " " )
55
+ if got != want {
56
+ t .Errorf ("diff(%q, %q) = %q, want %q" , text1 , text2 , got , want )
42
57
}
43
58
}
0 commit comments