-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtemplify_test.go
70 lines (54 loc) · 1.28 KB
/
templify_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 main
import (
"fmt"
"io/ioutil"
"os"
"testing"
)
var bad = `package main
import "fmt"
func main() {
fmt.Printf("Hello, world.\n")
}`
var good = `package main
import "fmt"
func main() {
fmt.Printf("Hello, world.\n")
}
`
func TestFormatFile(t *testing.T) {
var f, _ = ioutil.TempFile(".", "templifytest")
var fname = f.Name()
f.Close()
ioutil.WriteFile(fname, []byte(bad), 0644)
formatFile(fname)
uglytmp, _ := ioutil.ReadFile(fname)
ugly := string(uglytmp)
defer os.Remove(fname)
if good != ugly {
fmt.Printf("Formatted file '%s' differs from gold standard.\n", fname)
t.Fail()
}
}
func TestFlagging(t *testing.T) {
args := []string{"-p", "testpackage", "/my/path/testfile.tpl"}
os.Args = append(os.Args, args...)
flagging()
if pckg != "testpackage" {
fmt.Printf("package flag was not as expected. 'pckg=%s'", pckg)
t.Fail()
}
if inputfile != "/my/path/testfile.tpl" {
fmt.Printf("inputfile flag was not as expected. 'inputfile=%s'", inputfile)
t.Fail()
}
if outfilename != "/my/path/testfile.go" {
fmt.Printf("output filename not correctly determined. 'outfilename=%s'", inputfile)
t.Fail()
}
if functionname != "testfile" {
fmt.Printf("functionname not correctly determined. 'functionname=%s'", inputfile)
t.Fail()
}
fmt.Println()
}