-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconstant_test.go
123 lines (108 loc) · 2.08 KB
/
constant_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
package cuckle
import (
"fmt"
"testing"
)
func TestConstantBoolean(t *testing.T) {
for _, test := range []struct {
b bool
c Constant
}{
{false, "false"},
{true, "true"},
} {
t.Log("Test:", test)
if a := ConstantBoolean(test.b); a != test.c {
t.Errorf("Actual constant %v, expected %v", a, test.c)
}
}
}
func TestConstantInteger(t *testing.T) {
for _, test := range []struct {
i int64
c Constant
}{
{0, "0"},
{1, "1"},
} {
t.Log("Test:", test)
if a := ConstantInteger(test.i); a != test.c {
t.Errorf("Actual constant %v, expected %v", a, test.c)
}
}
}
func TestConstantFloat(t *testing.T) {
for _, test := range []struct {
f float64
c Constant
}{
{0, "0"},
{1, "1"},
} {
t.Log("Test:", test)
if a := ConstantFloat(test.f); a != test.c {
t.Errorf("Actual constant %v, expected %v", a, test.c)
}
}
}
func TestConstantHex(t *testing.T) {
for _, test := range []struct {
b []byte
c Constant
}{
{nil, ""},
{[]byte{1}, "01"},
{[]byte{1, 2}, "0102"},
} {
t.Log("Test:", test)
if a, e := ConstantHex(test.b), Constant(fmt.Sprintf("0x%v", test.c)); a != e {
t.Errorf("Actual constant %v, expected %v", a, e)
}
}
}
func TestConstantString(t *testing.T) {
for _, test := range []struct {
s string
c Constant
}{
{"", "''"},
{"a", "'a'"},
{"ab", "'ab'"},
} {
t.Log("Test:", test)
if a := ConstantString(test.s); a != test.c {
t.Errorf("Actual constant %v, expected %v", a, test.c)
}
}
}
func TestConstantStringEscaped(t *testing.T) {
for _, test := range []struct {
s string
c Constant
}{
{"", "$$$$"},
{"a", "$$a$$"},
{"ab", "$$ab$$"},
{"a\nb", "$$a\nb$$"},
{"'ab'", "$$'ab'$$"},
} {
t.Log("Test:", test)
if a := ConstantStringEscaped(test.s); a != test.c {
t.Errorf("Actual constant %v, expected %v", a, test.c)
}
}
}
func TestConstantUUID(t *testing.T) {
for _, test := range []struct {
s string
c Constant
}{
{"", ""},
{"a", "a"},
} {
t.Log("Test:", test)
if a := ConstantUUID(test.s); a != test.c {
t.Errorf("Actual constant %v, expected %v", a, test.c)
}
}
}