-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgosimports_test.go
53 lines (43 loc) · 997 Bytes
/
gosimports_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
package gosimports_test
import (
"bytes"
"os"
"testing"
"github.com/rinchsan/gosimports"
)
func TestMain(m *testing.M) {
gosimports.Debug = true
m.Run()
}
func TestProcess_from_src(t *testing.T) {
src, err := os.ReadFile("gosimports.go")
if err != nil {
t.Fatal("expected: err == nil")
}
formatted, err := gosimports.Process("", src, nil)
if err != nil {
t.Fatal("expected: err == nil")
}
if !bytes.Equal(src, formatted) {
t.Fatal("expected: src == formatted")
}
}
func TestProcess_from_filename(t *testing.T) {
formatted, err := gosimports.Process("gosimports.go", nil, nil)
if err != nil {
t.Fatal("expected: err == nil")
}
src, err := os.ReadFile("gosimports.go")
if err != nil {
t.Fatal("expected: err == nil")
}
if !bytes.Equal(src, formatted) {
t.Fatal("expected: src == formatted")
}
}
func TestProcess_unknown_filename(t *testing.T) {
_, err := gosimports.Process("unknown.go", nil, nil)
if err == nil {
t.Fatal("expected: err != nil")
}
}