-
Notifications
You must be signed in to change notification settings - Fork 0
/
refactor_test.go
48 lines (39 loc) · 961 Bytes
/
refactor_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
package gofactor_test
import (
"go/format"
"io/ioutil"
"path/filepath"
"testing"
"github.com/lwsanty/gofactor"
"github.com/stretchr/testify/require"
)
func TestAll(t *testing.T) {
dirs, err := filepath.Glob("fixtures/*")
require.NoError(t, err)
for _, d := range dirs {
d := d
t.Run(d, func(t *testing.T) {
testCase(t, d)
})
}
}
func testCase(t *testing.T, d string) {
getFileContent := func(name string) string {
data, err := ioutil.ReadFile(filepath.Join(d, name))
require.NoError(t, err)
fdata, err := format.Source(data)
require.NoError(t, err)
return string(fdata)
}
var (
after = getFileContent("after")
before = getFileContent("before")
example = getFileContent("example.go")
expected = getFileContent("expected")
)
refactor, err := gofactor.NewRefactor(before, after)
require.NoError(t, err)
actual, err := refactor.Apply(example)
require.NoError(t, err)
require.Equal(t, expected, actual)
}