-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmain_test.go
44 lines (33 loc) · 1.03 KB
/
main_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
package main
import (
"io/ioutil"
"os"
"strings"
"testing"
)
func TestAppAST(t *testing.T) {
fileContent := "package testing\n\nimport \"fmt\"\n\nfunc HelloWorld() {\nfmt.Println(\"Hello World!\")\n}\n"
ioutil.WriteFile("hello.go", []byte(fileContent), os.ModePerm)
ProcessFileAST("hello.go", "fmt", "replacedImport")
result, err := ioutil.ReadFile("hello.go")
if err != nil {
t.Error("Failed to read written file.")
}
if !strings.Contains(string(result), "replacedImport") {
t.Error("Got different results")
}
os.Remove("hello.go")
}
func TestAppNative(t *testing.T) {
fileContent := "package testing\n\nimport \"fmt\"\n\nfunc HelloWorld() {\nfmt.Println(\"Hello World!\")\n}\n"
ioutil.WriteFile("hello.go", []byte(fileContent), os.ModePerm)
ProcessFileNative("hello.go", "fmt", "replacedImport")
result, err := ioutil.ReadFile("hello.go")
if err != nil {
t.Error("Failed to read written file.")
}
if !strings.Contains(string(result), "replacedImport") {
t.Error("Got different results")
}
os.Remove("hello.go")
}