-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils_test.go
52 lines (45 loc) · 1.39 KB
/
utils_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
package gopath
import (
"reflect"
"testing"
)
func assertGoPathHasErr(t *testing.T, actual GoPath) {
if !actual.HasErr() {
t.Errorf("Expected to have Err(), but was %v", actual)
}
}
func assertGoPathToSlashEqual(t *testing.T, actual GoPath, expected GoPath) {
assertGoPathEqual(t, actual.ToSlash(), expected.ToSlash())
}
func assertGoPathEqual(t *testing.T, actual GoPath, expected GoPath) {
if actual.Err() != expected.Err() {
t.Errorf("expected Err() to be %v, but was %v", expected.Err(), actual.Err())
}
if actual.Path() != expected.Path() {
t.Errorf("expected Path() to be %v, but was %v", expected.Path(), actual.Path())
}
}
func assertStrEqual(t *testing.T, actual string, expected string) {
if expected != actual {
t.Errorf("expected to be equal %s, but was %s", expected, actual)
}
}
func assertSliceEmpty(t *testing.T, actual interface{}) {
switch reflect.TypeOf(actual).Kind() {
case reflect.Slice:
slice := reflect.ValueOf(actual)
if slice.Len() != 0 {
t.Errorf("expected to be empty, but was %v", actual)
}
}
}
func assertStrSliceEqual(t *testing.T, actual []string, expected ...string) {
if len(actual) != len(expected) {
t.Errorf("expected to be a [] string of len %d, but was of len %d", len(expected), len(actual))
}
for i := range actual {
if actual[i] != expected[i] {
t.Errorf("expected %dth element to be %v, but was %v", expected[i], actual[i])
}
}
}