forked from blampe/goat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
examples_test.go
56 lines (42 loc) · 897 Bytes
/
examples_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
54
55
56
package goat
import (
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
)
const basePath string = "../examples/"
func getInOut(t testing.TB, fileName string) (io.Reader, io.Writer) {
sourceName := basePath + fileName
svgName := basePath + strings.TrimSuffix(sourceName, filepath.Ext(fileName)) + ".svg"
in, err := os.Open(sourceName)
if err != nil {
t.Error(err)
return nil, nil
}
out, err := os.Create(svgName)
if err != nil {
t.Error(err)
return nil, nil
}
return in, out
}
func TestExamples(t *testing.T) {
fileInfos, err := ioutil.ReadDir(basePath)
if err != nil {
t.Error(err)
}
for _, fileInfo := range fileInfos {
in, out := getInOut(t, fileInfo.Name())
ASCIItoSVG(in, out)
}
}
func BenchmarkComplicated(b *testing.B) {
in, out := getInOut(b, "complicated.txt")
b.ResetTimer()
for i := 0; i < b.N; i++ {
ASCIItoSVG(in, out)
}
}