-
Notifications
You must be signed in to change notification settings - Fork 0
/
diff_test.go
81 lines (76 loc) · 1.37 KB
/
diff_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package lint2hub
import (
"fmt"
"testing"
)
func TestDiff(t *testing.T) {
cases := []struct {
diff string
positions map[string]map[int]int
}{
{
diff: `diff --git a/README.md b/README.md
index abc1234..bcd3456 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,2 @@
-Howdy
+Hello
-Cruel
World
@@ -50,53 +50,50 @@
Goodbye
-One
-Two
-Three
@@ -100,100 +100,103 @@
Hello
+One
+Two
+Three
diff --git a/foo/bar.rb b/foo/bar.rb
index abc1234..bcd3456 100644
--- a/foo/bar.rb
+++ b/foo/bar.rb
@@ -1,3 +1,3 @@ Wat
Foo
-Bar
+Baz
Bob
`,
positions: map[string]map[int]int{
"README.md": {
1: 2,
2: 4,
3: 0, // not present
101: 12,
102: 13,
103: 14,
},
"foo/bar.rb": {
2: 3,
},
},
},
}
for i, tc := range cases {
tc := tc
t.Run(fmt.Sprintf("index %d", i), func(t *testing.T) {
t.Parallel()
diff := newDiff(tc.diff)
for file, positions := range tc.positions {
for lineNum, position := range positions {
actual, ok := diff.GetPosition(file, lineNum)
if position == 0 && ok {
t.Fatalf("lineNum %v: expected ok = false, but got %v", lineNum, ok)
} else if position != 0 && !ok {
t.Fatalf("lineNum %v: expected ok = true, but got %v", lineNum, ok)
}
if position != actual {
t.Fatalf("lineNum %v: expected %v, got %v", lineNum, position, actual)
}
}
}
})
}
}