-
Notifications
You must be signed in to change notification settings - Fork 4
/
rgba_test.go
51 lines (42 loc) · 998 Bytes
/
rgba_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
package altv
import (
"testing"
"github.com/timo972/altv-go/mvalue"
)
func TestRGBAMarshal(t *testing.T) {
testCases := []struct {
input RGBA
output string
}{
{RGBA{R: 1, G: 2, B: 3, A: 4}, `{"$type":12,"r":1,"g":2,"b":3,"a":4}`},
}
for _, testCase := range testCases {
result, err := mvalue.Marshal(testCase.input)
if err != nil {
t.Error(err)
continue
}
if string(result) != testCase.output {
t.Errorf("mvalue.Marshal(%+v) = %s; want %s", testCase.input, string(result), testCase.output)
}
}
}
func TestRGBAUnmarshal(t *testing.T) {
testCases := []struct {
input string
output RGBA
}{
{`{"r":1,"g":2,"b":3,"a":4}`, RGBA{R: 1, G: 2, B: 3, A: 4}},
}
for _, testCase := range testCases {
var color RGBA
err := mvalue.Unmarshal([]byte(testCase.input), &color)
if err != nil {
t.Error(err)
continue
}
if color != testCase.output {
t.Errorf("mvalue.Unmarshal(%s) = %+v; want %+v", testCase.input, color, testCase.output)
}
}
}