forked from thatguystone/swan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutf8_test.go
49 lines (41 loc) · 922 Bytes
/
utf8_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
package swan
import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
)
func TestToUtf8(t *testing.T) {
dir := "test_data/utf8/"
filepath.Walk(dir,
func(path string, info os.FileInfo, err error) error {
if err != nil {
t.Fatalf("error while walking directory %s: %s", dir, err)
}
if info.IsDir() || !strings.HasSuffix(path, ".in") {
return nil
}
in, err := ioutil.ReadFile(path)
if err != nil {
t.Fatalf("failed to read %s: %s", path, err)
}
name := strings.Replace(path, ".in", ".out", -1)
out, err := ioutil.ReadFile(name)
if err != nil {
t.Fatalf("failed to read %s: %s", path, err)
}
uout, err := ToUtf8(in)
if err != nil {
t.Fatalf("failed to convert %s: %s", path, err)
}
if !bytes.Equal(out, uout) {
t.Fatalf("conversion doesn't match for %s:\n\t%s\n\t%s",
path,
out,
uout)
}
return nil
})
}