-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
45 lines (35 loc) · 844 Bytes
/
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
45
package main
import (
"bytes"
"embed"
"os"
"path"
"testing"
"github.com/stretchr/testify/require"
)
//go:embed testdata
var testdata embed.FS
func TestSortAST(t *testing.T) {
dirs, err := testdata.ReadDir("testdata")
require.NoError(t, err)
paths := make([]string, len(dirs))
for i, entry := range dirs {
require.True(t, entry.IsDir())
paths[i] = path.Join("testdata", entry.Name())
}
config := Config{
SortAlphabetically: true,
}
for _, p := range paths {
t.Run(p, func(t *testing.T) {
in, err := os.ReadFile(path.Join(p, "in.txt"))
require.NoError(t, err)
expected, err := os.ReadFile(path.Join(p, "expected.txt"))
require.NoError(t, err)
actual := &bytes.Buffer{}
err = sortFile(in, actual, config)
require.NoError(t, err)
require.Equal(t, string(expected), actual.String())
})
}
}