-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathvalues_test.go
173 lines (141 loc) · 3.93 KB
/
values_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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// +build ignore
package rbxfile
import (
"math"
"reflect"
"strings"
"testing"
)
var testTypes = []Type{}
func init() {
testTypes = make([]Type, len(typeStrings))
for i := range testTypes {
testTypes[i] = Type(i + 1)
}
}
func TestType_String(t *testing.T) {
if TypeString.String() != "String" {
t.Error("unexpected result")
}
if Type(0).String() != "Invalid" || Type(len(testTypes)+1).String() != "Invalid" {
t.Error("expected Invalid string")
}
}
func TestTypeFromString(t *testing.T) {
for _, typ := range testTypes {
if st := TypeFromString(typ.String()); st != typ {
t.Errorf("expected type %s from TypeFromString (got %s)", typ, st)
}
}
if TypeFromString("String") != TypeString {
t.Error("unexpected result from TypeFromString")
}
if TypeFromString("UnknownType") != TypeInvalid {
t.Error("unexpected result from TypeFromString")
}
}
func TestNewValue(t *testing.T) {
for _, typ := range testTypes {
name := reflect.ValueOf(NewValue(typ)).Type().Name()
if strings.TrimPrefix(name, "Value") != typ.String() {
t.Errorf("type %s does not match Type%s", name, typ)
}
}
if NewValue(TypeInvalid) != nil {
t.Error("expected nil value for invalid type")
}
}
func TestValueCopy(t *testing.T) {
for _, typ := range testTypes {
v := NewValue(typ)
c := v.Copy()
if !reflect.DeepEqual(v, c) {
t.Errorf("copy of value %q is not equal to original", v.Type().String())
}
}
}
type testCompareString struct {
v Value
s string
}
func testCompareStrings(t *testing.T, vts []testCompareString) {
for _, vt := range vts {
if vt.v.String() != vt.s {
t.Errorf("unexpected result from String method of value %q (%q expected, got %q)", vt.v.Type().String(), vt.s, vt.v.String())
}
}
}
func TestValueString(t *testing.T) {
testCompareStrings(t, []testCompareString{
{ValueString("test\000string"), "test\000string"},
{ValueBinaryString("test\000string"), "test\000string"},
{ValueProtectedString("test\000string"), "test\000string"},
{ValueContent("test\000string"), "test\000string"},
{ValueBool(true), "true"},
{ValueBool(false), "false"},
{ValueInt(42), "42"},
{ValueInt(-42), "-42"},
{ValueFloat(8388607.314159), "8388607.5"},
{ValueFloat(math.Pi), "3.1415927"},
{ValueFloat(-math.Phi), "-1.618034"},
{ValueFloat(math.Inf(1)), "+Inf"},
{ValueFloat(math.Inf(-1)), "-Inf"},
{ValueFloat(math.NaN()), "NaN"},
{ValueDouble(8388607.314159), "8388607.314159"},
{ValueDouble(math.Pi), "3.141592653589793"},
{ValueDouble(-math.Phi), "-1.618033988749895"},
{ValueDouble(math.Inf(1)), "+Inf"},
{ValueDouble(math.Inf(-1)), "-Inf"},
{ValueDouble(math.NaN()), "NaN"},
{ValueUDim{
Scale: math.Pi,
Offset: 12345,
}, "3.1415927, 12345"},
{ValueUDim2{
X: ValueUDim{
Scale: 1,
Offset: 2,
},
Y: ValueUDim{
Scale: 3,
Offset: 4,
},
}, "{1, 2}, {3, 4}"},
{ValueRay{
Origin: ValueVector3{X: 1, Y: 2, Z: 3},
Direction: ValueVector3{X: 4, Y: 5, Z: 6},
}, "{1, 2, 3}, {4, 5, 6}"},
{ValueFaces{
Front: true,
Bottom: true,
Left: true,
Back: true,
Top: true,
Right: true,
}, "Front, Bottom, Left, Back, Top, Right"},
{ValueFaces{
Front: true,
Bottom: false,
Left: true,
Back: false,
Top: true,
Right: false,
}, "Front, Left, Top"},
{ValueAxes{X: true, Y: true, Z: true}, "X, Y, Z"},
{ValueAxes{X: true, Y: false, Z: true}, "X, Z"},
{ValueBrickColor(194), "194"},
{ValueColor3{R: 0.5, G: 0.25, B: 0.75}, "0.5, 0.25, 0.75"},
{ValueVector2{X: 1, Y: 2}, "1, 2"},
{ValueVector3{X: 1, Y: 2, Z: 3}, "1, 2, 3"},
{ValueCFrame{
Position: ValueVector3{X: 1, Y: 2, Z: 3},
Rotation: [9]float32{4, 5, 6, 7, 8, 9, 10, 11, 12},
}, "1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12"},
{ValueToken(42), "42"},
{ValueReference{}, "<nil>"},
{ValueReference{Instance: namedInst("Instance", nil)}, "Instance"},
{ValueVector3int16{X: 1, Y: 2, Z: 3}, "1, 2, 3"},
{ValueVector2int16{X: 1, Y: 2}, "1, 2"},
},
)
}