@@ -17,11 +17,42 @@ import (
1717 "github.com/stretchr/testify/require"
1818)
1919
20- //go:embed internal/testimage/sprite-sheet-16x16.png
21- var spriteSheet16x16 []byte
20+ var (
21+ //go:embed internal/testimage/sprite-sheet-16x16.png
22+ spriteSheet16x16 []byte
23+ //go:embed internal/testimage/*.png
24+ images embed.FS
25+ )
26+
27+ func TestColor (t * testing.T ) {
28+ t .Run ("should return default color" , func (t * testing.T ) {
29+ pi .BootOrPanic ()
30+ assert .Equal (t , byte (6 ), pi .Color (2 ))
31+ })
32+
33+ t .Run ("should return previous color" , func (t * testing.T ) {
34+ pi .BootOrPanic ()
35+ prev := byte (3 )
36+ pi .Color (prev )
37+ assert .Equal (t , prev , pi .Color (4 ))
38+ })
39+ }
40+
41+ func TestColorReset (t * testing.T ) {
42+ t .Run ("should reset color to default" , func (t * testing.T ) {
43+ pi .BootOrPanic ()
44+ pi .Color (3 )
45+ pi .ColorReset ()
46+ assert .Equal (t , byte (6 ), pi .Color (5 ))
47+ })
2248
23- //go:embed internal/testimage/*.png
24- var images embed.FS
49+ t .Run ("should return previous color" , func (t * testing.T ) {
50+ pi .BootOrPanic ()
51+ prev := byte (5 )
52+ pi .Color (prev )
53+ assert .Equal (t , prev , pi .ColorReset ())
54+ })
55+ }
2556
2657func TestCls (t * testing.T ) {
2758 t .Run ("should clean screen using color 0" , func (t * testing.T ) {
@@ -58,7 +89,7 @@ func TestPset(t *testing.T) {
5889 pi .ScreenHeight = 2
5990 pi .BootOrPanic ()
6091 // when
61- pi .Color = col
92+ pi .Color ( col )
6293 pi .Pset (1 , 1 )
6394 // then
6495 assert .Equal (t , col , pi .ScreenData [3 ])
@@ -81,7 +112,7 @@ func TestPset(t *testing.T) {
81112 name := fmt .Sprintf ("%+v" , coords )
82113 t .Run (name , func (t * testing.T ) {
83114 // when
84- pi .Color = col
115+ pi .Color ( col )
85116 pi .Pset (coords .X , coords .Y )
86117 // then
87118 assert .Equal (t , emptyScreen , pi .ScreenData )
@@ -105,7 +136,7 @@ func TestPset(t *testing.T) {
105136 pi .BootOrPanic ()
106137 pi .Clip (1 , 1 , 1 , 1 )
107138 // when
108- pi .Color = col
139+ pi .Color ( col )
109140 pi .Pset (coords .X , coords .Y )
110141 // then
111142 assert .Equal (t , emptyScreen , pi .ScreenData )
@@ -118,7 +149,7 @@ func TestPset(t *testing.T) {
118149 pi .ScreenHeight = 2
119150 pi .BootOrPanic ()
120151 pi .Camera (1 , 2 )
121- pi .Color = 8
152+ pi .Color ( 8 )
122153 // when
123154 pi .Pset (1 , 2 )
124155 // then
@@ -149,7 +180,7 @@ func TestPset(t *testing.T) {
149180 name := fmt .Sprintf ("%+v" , coords )
150181 t .Run (name , func (t * testing.T ) {
151182 pi .BootOrPanic ()
152- pi .Color = col
183+ pi .Color ( col )
153184 // when
154185 pi .Camera (1 , 1 )
155186 pi .Pset (coords .X , coords .Y )
@@ -163,7 +194,7 @@ func TestPset(t *testing.T) {
163194 pi .ScreenWidth = 1
164195 pi .ScreenHeight = 1
165196 pi .BootOrPanic ()
166- pi .Color = 1
197+ pi .Color ( 1 )
167198 pi .Pal (1 , 2 )
168199 // when
169200 pi .Pset (0 , 0 )
@@ -175,7 +206,7 @@ func TestPset(t *testing.T) {
175206 pi .ScreenWidth = 1
176207 pi .ScreenHeight = 1
177208 pi .BootOrPanic ()
178- pi .Color = 1
209+ pi .Color ( 1 )
179210 pi .Pal (1 , 2 )
180211 pi .PalReset ()
181212 // when
@@ -191,7 +222,7 @@ func TestPget(t *testing.T) {
191222 pi .ScreenHeight = 2
192223 pi .BootOrPanic ()
193224 col := byte (7 )
194- pi .Color = col
225+ pi .Color ( col )
195226 pi .Pset (1 , 1 )
196227 // expect
197228 assert .Equal (t , col , pi .Pget (1 , 1 ))
@@ -249,12 +280,12 @@ func TestPget(t *testing.T) {
249280 pi .ScreenHeight = 2
250281 pi .BootOrPanic ()
251282 pi .Camera (1 , 2 )
252- pi .Color = 8
283+ pi .Color ( 8 )
253284 pi .Pset (1 , 2 )
254285 // when
255286 actual := pi .Pget (1 , 2 )
256287 // then
257- assert .Equal (t , pi .Color , actual )
288+ assert .Equal (t , pi .ColorReset () , actual )
258289 })
259290
260291 t .Run ("should get color 0 for pixels outside the screen when camera is set" , func (t * testing.T ) {
0 commit comments