Skip to content

Commit

Permalink
Add some missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Feb 5, 2020
1 parent 630e772 commit e697a21
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/ui/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (e *editor) pixAt(x, y int) []uint8 {
iy := y / e.zoom

if ix >= e.img.Bounds().Dx() || iy >= e.img.Bounds().Dy() {
return []uint8{0, 0, 0, 128}
return []uint8{0, 0, 0, 0}
}

return colorToBytes(e.img.At(ix, iy))
Expand Down
32 changes: 32 additions & 0 deletions internal/ui/editor_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ui

import (
"image"
"image/color"
"io/ioutil"
"os"
Expand Down Expand Up @@ -73,6 +74,29 @@ func TestEditor_Save(t *testing.T) {
assert.Equal(t, red, e.PixelColor(0, 0))
}

func TestEditorFGColor(t *testing.T) {
e := NewEditor()

assert.Equal(t, color.Black, e.FGColor())
}

func TestEditor_SetFGColor(t *testing.T) {
e := NewEditor()

fg := color.White
e.SetFGColor(fg)
assert.Equal(t, fg, e.FGColor())
}

func TestEditor_PixelColor(t *testing.T) {
file := testFile("8x8")
e := NewEditor()
e.LoadFile(file)

assert.Equal(t, color.RGBA{A: 255}, e.PixelColor(0, 0))
assert.Equal(t, color.RGBA{R: 0, G: 0, B: 0, A: 0}, e.PixelColor(9, 9))
}

func TestEditor_SetPixelColor(t *testing.T) {
file := testFile("8x8")
e := NewEditor()
Expand All @@ -83,3 +107,11 @@ func TestEditor_SetPixelColor(t *testing.T) {
e.SetPixelColor(1, 1, col)
assert.Equal(t, col, e.PixelColor(1, 1))
}

func TestEditor_fixEncoding(t *testing.T) {
size := 4
nonRGBA := image.NewCMYK(image.Rect(0, 0, size, size))

fixed := fixEncoding(nonRGBA)
assert.Equal(t, image.Rect(0, 0, size, size), fixed.Bounds())
}

0 comments on commit e697a21

Please sign in to comment.