-
Notifications
You must be signed in to change notification settings - Fork 39
/
compile_test.go
146 lines (112 loc) · 3.1 KB
/
compile_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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package gcss
import (
"errors"
"os"
)
import "strings"
import "testing"
var errErrReader = errors.New("errReader error")
type errReader struct{}
func (r *errReader) Read(p []byte) (int, error) {
return 0, errErrReader
}
func TestCompile_readAllErr(t *testing.T) {
if _, err := Compile(os.Stdout, &errReader{}); err != errErrReader {
t.Errorf("error should be %+v [actual: %+v]", errErrReader, err)
return
}
}
func TestCompile_compileBytesErr(t *testing.T) {
r, err := os.Open("test/0015.gcss")
if err != nil {
t.Errorf("error occurred [error: %q]", err.Error())
return
}
_, err = Compile(os.Stdout, r)
if expected, actual := "indent is invalid [line: 5]", err.Error(); actual != expected {
t.Errorf("error should be %+q [actual: %+q]", expected, actual)
return
}
}
func TestCompile(t *testing.T) {
r, err := os.Open("test/0016.gcss")
if err != nil {
t.Errorf("error occurred [error: %q]", err.Error())
return
}
if _, err := Compile(os.Stdout, r); err != nil {
t.Errorf("error occurred [error: %q]", err.Error())
return
}
}
func TestCompileFile_readFileErr(t *testing.T) {
_, err := CompileFile("not_exist_file")
if err == nil {
t.Error("error should be occurred")
return
}
if expected, actual := "open not_exist_file: ", err.Error(); !strings.HasPrefix(actual, expected) || !os.IsNotExist(err) {
t.Errorf("err should be %q [actual: %q]", expected, actual)
return
}
}
func TestCompileFile_compileStringErr(t *testing.T) {
_, err := CompileFile("test/0004.gcss")
if err == nil {
t.Error("error should be occurred")
return
}
if expected, actual := "indent is invalid [line: 5]", err.Error(); expected != actual {
t.Errorf("err should be %q [actual: %q]", expected, actual)
return
}
}
func TestCompileFile_writeErr(t *testing.T) {
cssFileBack := cssFilePath
cssFilePath = func(_ string) string {
return "not_exist_dir/not_exist_file"
}
_, err := CompileFile("test/0003.gcss")
if err == nil {
t.Error("error should be occurred")
return
}
if expected, actual := "open not_exist_dir/not_exist_file: ", err.Error(); !strings.HasPrefix(actual, expected) || !os.IsNotExist(err) {
t.Errorf("err should be %q [actual: %q]", expected, actual)
return
}
cssFilePath = cssFileBack
}
func TestCompileFile(t *testing.T) {
path, err := CompileFile("test/0003.gcss")
if err != nil {
t.Errorf("error occurred [error: %q]", err.Error())
return
}
if expected := "test/0003.css"; expected != path {
t.Errorf("path should be %q [actual: %q]", expected, path)
return
}
}
func TestCompileFile_pattern2(t *testing.T) {
gcssPath := "test/0007.gcss"
path, err := CompileFile(gcssPath)
if err != nil {
t.Errorf("error occurred [error: %q]", err.Error())
return
}
if expected := cssFilePath(path); expected != path {
t.Errorf("path should be %q [actual: %q]", expected, path)
return
}
}
func Test_complieBytes(t *testing.T) {
compileBytes([]byte(""))
}
func TestPath(t *testing.T) {
path := "/test"
if expected, actual := path+extGCSS, Path(path+extCSS); actual != expected {
t.Errorf("returned value should be %q [actual: %q]", expected, actual)
return
}
}