This repository was archived by the owner on Jan 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathgo_test.go
70 lines (60 loc) · 1.98 KB
/
go_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
package goutil
import (
"bytes"
"strings"
"testing"
"github.com/cosiner/gohper/strings2"
"github.com/cosiner/gohper/testing2"
)
func TestFileType(t *testing.T) {
testing2.Eq(t, true, IsGoFile("aa.go"))
testing2.Eq(t, true, IsSrcFile("aa.go"))
testing2.Eq(t, true, IsTestFile("aa_test.go"))
testing2.Eq(t, false, IsSrcFile("aa_test.go"))
testing2.Eq(t, "aa_test.go", SrcTestFile("aa.go"))
}
func TestExport(t *testing.T) {
tt := testing2.Wrap(t)
tt.True(IsExported("Name"))
tt.True(ToSameExported("Abcd", "abc") == "Abc")
tt.True(ToSameExported("dbcd", "Abc") == "abc")
tt.True(ToExported("aaa") == "Aaa")
tt.True(ToExported("") == "")
tt.True(ToUnexported("Aaa") == "aaa")
tt.True(ToUnexported("") == "")
}
func TestFormat(t *testing.T) {
tt := testing2.Wrap(t)
code := `package main
func TestExport(t *testing.T) {
tt := testing2.Wrap(t)
tt.True(IsExported("Name"))
tt.True(ToSameExported("Abcd", "abc") == "Abc")
tt.True(ToSameExported("dbcd", "Abc") == "abc");tt.True(ToExported("aaa") == "Aaa")
tt.True(ToExported("") == "")
tt.True(ToUnexported("Aaa") == "aaa")
tt.True(ToUnexported("") == "")
}
`
out := bytes.NewBuffer(make([]byte, 0, 1024))
tt.True(Format("test", strings.NewReader(code), out) == nil)
tt.Eq(strings2.RemoveSpace(`package main
func TestExport(t *testing.T) {
tt := testing2.Wrap(t)
tt.True(IsExported("Name"))
tt.True(ToSameExported("Abcd", "abc") == "Abc")
tt.True(ToSameExported("dbcd", "Abc") == "abc")
tt.True(ToExported("aaa") == "Aaa")
tt.True(ToExported("") == "")
tt.True(ToUnexported("Aaa") == "aaa")
tt.True(ToUnexported("") == "")
}
`), strings2.RemoveSpace(out.String()))
}
func TestPath(t *testing.T) {
tt := testing2.Wrap(t)
out := bytes.NewBuffer(make([]byte, 0, 1024))
WriteImportpath(out, "github.com", "cosiner", "gohper")
tt.Eq(`"github.com/cosiner/gohper"`+"\n", out.String())
PackagePath("bufio") // difficult to test
}