-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil_test.go
72 lines (58 loc) · 1.5 KB
/
util_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
package gotables
import (
"fmt"
"strings"
"testing"
)
func TestFormatSource(t *testing.T) {
source := `
if err != nil { return nil }
`
expected := `
if err != nil {
return nil
}
`
formatted, err := UtilFormatSource(source)
if err != nil {
t.Error(err)
}
if formatted != expected {
t.Fatalf("expecting %s but got %s", expected, formatted)
}
}
func ExampleUtilFuncName() {
// Called from inside func ExampleFuncName()
fmt.Println(UtilFuncName())
// Output:
// ExampleUtilFuncName()
}
func ExampleUtilFuncNameNoParens() {
// Called from inside func ExampleFuncNameNoParens()
fmt.Println(UtilFuncNameNoParens())
// Output:
// ExampleUtilFuncNameNoParens
}
// Output can vary, so don't use as an example, such as:
// c:/golang/src/github.com/urban-wombat/util/util_test.go[40] github.com/urban-wombat/gotables.TestFuncNameFull
func TestFuncNameFull(t *testing.T) {
name := UtilFuncNameFull()
split := strings.Split(name, " ")
if len(split) != 2 {
t.Fatalf("expecting 2 strings but got %d", len(split))
}
pkg := split[1]
pkgExpected := "github.com/urban-wombat/gotables.TestFuncNameFull"
if pkg != pkgExpected {
t.Fatalf("expecting pkg %s but got pkg %s", pkgExpected, pkg)
}
}
// Output can vary, so don't use as an example, such as:
// c:/golang/src/github.com/urban-wombat/util/util_test.go[72]
func TestFuncSource(t *testing.T) {
source := UtilFuncSource()
split := strings.Split(source, " ")
if len(split) != 1 {
t.Fatalf("expecting 1 strings but got %d", len(split))
}
}