-
Notifications
You must be signed in to change notification settings - Fork 4
/
pork_test.go
86 lines (73 loc) · 1.52 KB
/
pork_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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package pork
import (
"errors"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
)
func levels() []Optimization {
return []Optimization{None, Basic, Advanced}
}
func test(t *testing.T,
fn func(*Config, string, string) error,
c *Config, path string,
check func([]byte) error) {
for _, level := range levels() {
c.Level = level
f, err := ioutil.TempFile(os.TempDir(), "pork-test")
if err != nil {
t.Error(err)
}
defer f.Close()
defer os.Remove(f.Name())
if err := fn(c, path, f.Name()); err != nil {
t.Error(err)
}
b, err := ioutil.ReadFile(f.Name())
if err != nil {
t.Error(err)
}
if len(b) == 0 {
t.Errorf("Empty output for level %d", level)
}
if check == nil {
continue
}
if err := check(b); err != nil {
t.Error(err)
}
}
}
func TestScss(t *testing.T) {
test(t,
CompileScss,
NewConfig(None),
filepath.Join(Root(), "tests/scss/a.scss"),
nil)
test(t,
CompileScss,
NewConfig(None),
filepath.Join(Root(), "tests/scss/datauri.scss"),
func(b []byte) error {
if !strings.Contains(string(b), "data:image/png;base64") {
return errors.New("datauri did not produce base64")
}
return nil
})
}
func TestTsc(t *testing.T) {
test(t,
CompileTsc,
NewConfig(None),
filepath.Join(Root(), "tests/tsc/a.ts"),
nil)
}
func TestJs(t *testing.T) {
test(t,
CompileJs,
NewConfig(None),
filepath.Join(Root(), "tests/js/a.js"),
nil)
}