-
Notifications
You must be signed in to change notification settings - Fork 39
/
variable_test.go
130 lines (97 loc) · 2.62 KB
/
variable_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
package gcss
import (
"io/ioutil"
"testing"
)
func Test_variable_WriteTo(t *testing.T) {
ln := newLine(1, "$test-name: test-value")
v, err := newVariable(ln, nil)
if err != nil {
t.Error("error occurred [error: %q]", err.Error())
return
}
v.WriteTo(ioutil.Discard)
}
func Test_variable_WriteTo_fromFile(t *testing.T) {
_, err := CompileFile("test/0013.gcss")
if err != nil {
t.Error("error occurred [error: %q]", err.Error())
return
}
}
func Test_variableNV_prefixDollarErr(t *testing.T) {
ln := newLine(1, "test-name: test-value")
_, _, err := variableNV(ln)
if err == nil {
t.Error("error should be occurred")
return
}
if expected := "variable must start with \"$\" [line: 1]"; err.Error() != expected {
t.Errorf("err should be %q [actual: %q]", expected, err.Error())
return
}
}
func Test_variableNV_lenErr(t *testing.T) {
ln := newLine(1, "$test-name:test-value")
_, _, err := variableNV(ln)
if err == nil {
t.Error("error should be occurred")
return
}
if expected := "variable's name and value should be divided by a space [line: 1]"; err.Error() != expected {
t.Errorf("err should be %q [actual: %q]", expected, err.Error())
return
}
}
func Test_variableNV_nameSuffixErr(t *testing.T) {
ln := newLine(1, "$test-name test-value")
_, _, err := variableNV(ln)
if err == nil {
t.Error("error should be occurred")
return
}
if expected := "variable's name should end with a colon [line: 1]"; err.Error() != expected {
t.Errorf("err should be %q [actual: %q]", expected, err.Error())
return
}
}
func Test_variableNV(t *testing.T) {
ln := newLine(1, "$test-name: test-value")
_, _, err := variableNV(ln)
if err != nil {
t.Error("error occurred [error: %q]", err.Error())
return
}
}
func Test_newVariable_err(t *testing.T) {
ln := newLine(1, "test-name: test-value")
_, err := newVariable(ln, nil)
if err == nil {
t.Error("error should be occurred")
return
}
if expected := "variable must start with \"$\" [line: 1]"; err.Error() != expected {
t.Errorf("err should be %q [actual: %q]", expected, err.Error())
return
}
}
func Test_newVariable_suffixErr(t *testing.T) {
ln := newLine(1, "$test-name: test-value;")
_, err := newVariable(ln, nil)
if err == nil {
t.Error("error should be occurred")
return
}
if expected := "variable must not end with \";\""; err.Error() != expected {
t.Errorf("err should be %q [actual: %q]", expected, err.Error())
return
}
}
func Test_newVariable(t *testing.T) {
ln := newLine(1, "$test-name: test-value")
_, err := newVariable(ln, nil)
if err != nil {
t.Error("error occurred [error: %q]", err.Error())
return
}
}