mirror of
https://github.com/imjasonh/dots
synced 2026-07-07 00:22:55 +00:00
golangci-lint, remove image creation from tests
Signed-off-by: Jason Hall <jason@chainguard.dev>
This commit is contained in:
parent
b3157c7007
commit
40cc74ad03
3 changed files with 30 additions and 102 deletions
44
ansi_test.go
44
ansi_test.go
|
|
@ -2,7 +2,6 @@ package dots
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"image/color"
|
||||
"image/png"
|
||||
"os"
|
||||
"testing"
|
||||
|
|
@ -40,13 +39,16 @@ func TestANSIColorFunctions(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBackgroundOption(t *testing.T) {
|
||||
// Create a simple red image using existing helper
|
||||
img := createTestImage(t, "test_red.png", 8, 16, color.RGBA{R: 255, G: 0, B: 0, A: 255})
|
||||
|
||||
// Load it back
|
||||
f, _ := os.Open(img)
|
||||
defer f.Close()
|
||||
decoded, _ := png.Decode(f)
|
||||
// Load existing red image from testdata
|
||||
f, err := os.Open("testdata/red.png")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open test image: %v", err)
|
||||
}
|
||||
defer func() { _ = f.Close() }()
|
||||
decoded, err := png.Decode(f)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to decode test image: %v", err)
|
||||
}
|
||||
|
||||
// Without background
|
||||
linesNoBackground := Convert(decoded, Options{
|
||||
|
|
@ -95,10 +97,15 @@ func containsSubstring(s, substr string) bool {
|
|||
|
||||
func TestBackgroundColorQuantization(t *testing.T) {
|
||||
// Test that different background colors are properly quantized and applied
|
||||
img := createTestImage(t, "test_white.png", 8, 16, color.RGBA{R: 255, G: 255, B: 255, A: 255})
|
||||
f, _ := os.Open(img)
|
||||
defer f.Close()
|
||||
decoded, _ := png.Decode(f)
|
||||
f, err := os.Open("testdata/white.png")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open test image: %v", err)
|
||||
}
|
||||
defer func() { _ = f.Close() }()
|
||||
decoded, err := png.Decode(f)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to decode test image: %v", err)
|
||||
}
|
||||
|
||||
testCases := []struct {
|
||||
desc string
|
||||
|
|
@ -171,10 +178,15 @@ func TestBackgroundColorQuantization(t *testing.T) {
|
|||
|
||||
func TestBackgroundColorNil(t *testing.T) {
|
||||
// Test that nil background doesn't add background codes
|
||||
img := createTestImage(t, "test_color.png", 8, 16, color.RGBA{R: 128, G: 64, B: 200, A: 255})
|
||||
f, _ := os.Open(img)
|
||||
defer f.Close()
|
||||
decoded, _ := png.Decode(f)
|
||||
f, err := os.Open("testdata/purple.png")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open test image: %v", err)
|
||||
}
|
||||
defer func() { _ = f.Close() }()
|
||||
decoded, err := png.Decode(f)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to decode test image: %v", err)
|
||||
}
|
||||
|
||||
lines := Convert(decoded, Options{
|
||||
Width: 2,
|
||||
|
|
|
|||
|
|
@ -8,83 +8,6 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
// createTestImage creates a simple test image and saves it to testdata.
|
||||
func createTestImage(t *testing.T, name string, width, height int, fillColor color.Color) string {
|
||||
t.Helper()
|
||||
img := image.NewRGBA(image.Rect(0, 0, width, height))
|
||||
for y := 0; y < height; y++ {
|
||||
for x := 0; x < width; x++ {
|
||||
img.Set(x, y, fillColor)
|
||||
}
|
||||
}
|
||||
|
||||
path := "testdata/" + name
|
||||
f, err := os.Create(path)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create test image: %v", err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
if err := png.Encode(f, img); err != nil {
|
||||
t.Fatalf("failed to encode test image: %v", err)
|
||||
}
|
||||
|
||||
return path
|
||||
}
|
||||
|
||||
// createCheckerboard creates a checkerboard pattern test image.
|
||||
func createCheckerboard(t *testing.T, name string, size int) string {
|
||||
t.Helper()
|
||||
img := image.NewRGBA(image.Rect(0, 0, size, size))
|
||||
for y := 0; y < size; y++ {
|
||||
for x := 0; x < size; x++ {
|
||||
if (x/4+y/4)%2 == 0 {
|
||||
img.Set(x, y, color.White)
|
||||
} else {
|
||||
img.Set(x, y, color.Black)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
path := "testdata/" + name
|
||||
f, err := os.Create(path)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create test image: %v", err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
if err := png.Encode(f, img); err != nil {
|
||||
t.Fatalf("failed to encode test image: %v", err)
|
||||
}
|
||||
|
||||
return path
|
||||
}
|
||||
|
||||
// createGradient creates a horizontal gradient test image.
|
||||
func createGradient(t *testing.T, name string, width, height int) string {
|
||||
t.Helper()
|
||||
img := image.NewRGBA(image.Rect(0, 0, width, height))
|
||||
for y := 0; y < height; y++ {
|
||||
for x := 0; x < width; x++ {
|
||||
brightness := uint8(x * 255 / width)
|
||||
img.Set(x, y, color.Gray{Y: brightness})
|
||||
}
|
||||
}
|
||||
|
||||
path := "testdata/" + name
|
||||
f, err := os.Create(path)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create test image: %v", err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
if err := png.Encode(f, img); err != nil {
|
||||
t.Fatalf("failed to encode test image: %v", err)
|
||||
}
|
||||
|
||||
return path
|
||||
}
|
||||
|
||||
func TestBlockToBraille(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
desc string
|
||||
|
|
@ -173,13 +96,6 @@ func TestQuantizeRGB(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestConvert(t *testing.T) {
|
||||
// Create test images
|
||||
_ = createTestImage(t, "white.png", 8, 16, color.White)
|
||||
_ = createTestImage(t, "black.png", 8, 16, color.Black)
|
||||
_ = createCheckerboard(t, "checkerboard.png", 16)
|
||||
_ = createGradient(t, "gradient.png", 64, 16)
|
||||
_ = createTestImage(t, "red.png", 8, 16, color.RGBA{R: 255, G: 0, B: 0, A: 255})
|
||||
|
||||
for _, tt := range []struct {
|
||||
desc string
|
||||
imgPath string
|
||||
|
|
@ -257,7 +173,7 @@ func TestConvert(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("failed to open test image: %v", err)
|
||||
}
|
||||
defer f.Close()
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
img, err := png.Decode(f)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ func main() {
|
|||
fmt.Fprintf(os.Stderr, "Error: failed to open image: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer f.Close()
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
img, _, err := image.Decode(f)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue