-
Notifications
You must be signed in to change notification settings - Fork 0
/
branch_test.go
55 lines (46 loc) · 1.09 KB
/
branch_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
package main
import (
"strconv"
"testing"
)
var mapString string
func arrayToString(arr []commit) string {
i := 0
for {
if i == len(arr) {
break
} else if i == len(arr)-1 {
mapString += strconv.Itoa(arr[i].id)
break
}
mapString += strconv.Itoa(arr[i].id) + "-"
i++
}
defer func() { mapString = "" }()
return mapString
}
func TestBranches(t *testing.T) {
repo := newGit("my-repo")
repo.Commit("Init")
repo.Commit("Change 1")
if arrayToString(repo.Log()) == "2-1" {
repo.Checkout("new")
repo.Commit("Change 3")
if arrayToString(repo.Log()) == "3-2-0" {
repo.Checkout("master")
if arrayToString(repo.Log()) == "2-1" {
repo.Commit("Change 3")
if arrayToString(repo.Log()) == "4-2-1" {
return
}
t.Errorf("Expected '4-2-0' got %s", arrayToString(repo.Log()))
} else {
t.Errorf("Expected '2-1' got %s", arrayToString(repo.Log()))
}
} else {
t.Errorf("Expected '3-2-0' got %s", arrayToString(repo.Log()))
}
} else {
t.Errorf("Expected '2-1' got %s", arrayToString(repo.Log()))
}
}