-
Notifications
You must be signed in to change notification settings - Fork 1
/
color_test.go
91 lines (74 loc) · 2.4 KB
/
color_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
package tmx_test
import (
. "github.com/manyminds/tmx"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Test Background Color parsing", func() {
Context("Test default cases", func() {
It("Should be default if empty", func() {
m := Map{}
r, g, b, a := m.BackgroundColor.RGBA()
Expect(r).To(Equal(uint32(128)))
Expect(g).To(Equal(uint32(128)))
Expect(b).To(Equal(uint32(128)))
Expect(a).To(Equal(uint32(255)))
})
It("Should be default if too long", func() {
m := Map{BackgroundColor: "thisisnocolor"}
r, g, b, a := m.BackgroundColor.RGBA()
Expect(r).To(Equal(uint32(128)))
Expect(g).To(Equal(uint32(128)))
Expect(b).To(Equal(uint32(128)))
Expect(a).To(Equal(uint32(255)))
})
It("Should be default if invalid", func() {
m := Map{BackgroundColor: "nocolor"}
r, g, b, a := m.BackgroundColor.RGBA()
Expect(r).To(Equal(uint32(128)))
Expect(g).To(Equal(uint32(128)))
Expect(b).To(Equal(uint32(128)))
Expect(a).To(Equal(uint32(255)))
})
It("will default if it fails to decode red", func() {
m := Map{BackgroundColor: "fgaaaa"}
r, g, b, a := m.BackgroundColor.RGBA()
Expect(r).To(Equal(uint32(128)))
Expect(g).To(Equal(uint32(128)))
Expect(b).To(Equal(uint32(128)))
Expect(a).To(Equal(uint32(255)))
})
It("will default if it fails to decode green", func() {
m := Map{BackgroundColor: "faagaa"}
r, g, b, a := m.BackgroundColor.RGBA()
Expect(r).To(Equal(uint32(128)))
Expect(g).To(Equal(uint32(128)))
Expect(b).To(Equal(uint32(128)))
Expect(a).To(Equal(uint32(255)))
})
It("will default if it fails to decode blue", func() {
m := Map{BackgroundColor: "faaaga"}
r, g, b, a := m.BackgroundColor.RGBA()
Expect(r).To(Equal(uint32(128)))
Expect(g).To(Equal(uint32(128)))
Expect(b).To(Equal(uint32(128)))
Expect(a).To(Equal(uint32(255)))
})
It("Should be ok if correct", func() {
m := Map{BackgroundColor: "#23af40"}
r, g, b, a := m.BackgroundColor.RGBA()
Expect(r).To(Equal(uint32(35)))
Expect(g).To(Equal(uint32(175)))
Expect(b).To(Equal(uint32(64)))
Expect(a).To(Equal(uint32(255)))
})
It("Should be ok if hash is missing", func() {
m := Map{BackgroundColor: "23AF40"}
r, g, b, a := m.BackgroundColor.RGBA()
Expect(r).To(Equal(uint32(35)))
Expect(g).To(Equal(uint32(175)))
Expect(b).To(Equal(uint32(64)))
Expect(a).To(Equal(uint32(255)))
})
})
})