forked from dave/jennifer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_test.go
51 lines (47 loc) · 1.13 KB
/
file_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
package jen
import (
"fmt"
"testing"
)
func TestGuessAlias(t *testing.T) {
data := map[string]string{
"A": "a",
"a": "a",
"a$": "a",
"a/b": "b",
"a/b/c": "c",
"a/b/c-d": "cd",
"a/b/c-d/": "cd",
"a.b": "ab",
"a/b.c": "bc",
"a/b-c.d": "bcd",
"a/bb-ccc.dddd": "bbcccdddd",
"a/foo-go": "foogo",
"123a": "a",
"a/321a.b": "ab",
"a/123": "pkg",
}
for path, expected := range data {
if guessAlias(path) != expected {
fmt.Printf("guessAlias test failed %s should return %s but got %s\n", path, expected, guessAlias(path))
t.Fail()
}
}
}
func TestValidAlias(t *testing.T) {
data := map[string]bool{
"a": true, // ok
"b": false, // already registered
"go": false, // keyword
"int": false, // predeclared
"err": false, // common name
}
f := NewFile("test")
f.register("b")
for alias, expected := range data {
if f.isValidAlias(alias) != expected {
fmt.Printf("isValidAlias test failed %s should return %t but got %t\n", alias, expected, f.isValidAlias(alias))
t.Fail()
}
}
}