-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiff_test.go
More file actions
79 lines (74 loc) · 1.47 KB
/
diff_test.go
File metadata and controls
79 lines (74 loc) · 1.47 KB
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
package review
import (
"testing"
)
func TestParseDiff_FileWithSingleHunk(t *testing.T) {
raw := `diff --git a/src/foo.go b/src/foo.go
index abc..def 100644
--- a/src/foo.go
+++ b/src/foo.go
@@ -1,5 +1,6 @@
package foo
+import "fmt"
func Bar() {
- println("old")
+ fmt.Println("new")
}
`
files, err := ParseDiff(raw)
if err != nil {
t.Fatalf("ParseDiff: %v", err)
}
if len(files) != 1 {
t.Fatalf("expected 1 file, got %d", len(files))
}
f := files[0]
if f.Path != "src/foo.go" {
t.Errorf("path = %q want src/foo.go", f.Path)
}
if f.AddedLines != 2 {
t.Errorf("added = %d want 2", f.AddedLines)
}
if f.RemovedLines != 1 {
t.Errorf("removed = %d want 1", f.RemovedLines)
}
if len(f.Hunks) != 1 {
t.Errorf("hunks = %d want 1", len(f.Hunks))
}
}
func TestParseDiff_MultipleFiles(t *testing.T) {
raw := `diff --git a/a.txt b/a.txt
index 0..1 100644
--- a/a.txt
+++ b/a.txt
@@ -1 +1 @@
-a
+A
diff --git a/b.txt b/b.txt
new file mode 100644
index 0..2
--- /dev/null
+++ b/b.txt
@@ -0,0 +1 @@
+B
`
files, err := ParseDiff(raw)
if err != nil {
t.Fatalf("ParseDiff: %v", err)
}
if len(files) != 2 {
t.Fatalf("expected 2 files, got %d", len(files))
}
if files[0].Path != "a.txt" || files[1].Path != "b.txt" {
t.Errorf("paths = %q, %q", files[0].Path, files[1].Path)
}
}
func TestParseDiff_Empty(t *testing.T) {
files, err := ParseDiff("")
if err != nil {
t.Fatal(err)
}
if len(files) != 0 {
t.Errorf("expected 0 files from empty diff, got %d", len(files))
}
}