Skip to content

Commit

Permalink
✅ Fix test conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
aksdb committed Jan 23, 2025
1 parent 91daf2a commit fe4bf5c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 37 deletions.
68 changes: 36 additions & 32 deletions image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,17 +533,19 @@ func TestImage_ChangeColorspace(t *testing.T) {
}

func TestImageTransformation_Save(t *testing.T) {
t.Run("save bitmap", func(t *testing.T) {
img, err := NewImageFromFile(testfile("test.bmp"))
if err != nil {
t.Fatalf("cannot load image: %v", err)
}
if out, err := img.Save(SaveOptions{MagickFormat: "bmp"}); err != nil {
t.Errorf("cannot save image: %v", err)
} else {
_ = Write("testdata/transformation_save_bmp_out.bmp", out)
}
})
if vipsVersionMin(8, 13) {
t.Run("save bitmap", func(t *testing.T) {
img, err := NewImageFromFile(testfile("test.bmp"))
if err != nil {
t.Fatalf("cannot load image: %v", err)
}
if out, err := img.Save(SaveOptions{MagickFormat: "bmp"}); err != nil {
t.Errorf("cannot save image: %v", err)
} else {
_ = Write("testdata/transformation_save_bmp_out.bmp", out)
}
})
}
}

func TestFormatSupport(t *testing.T) {
Expand Down Expand Up @@ -590,31 +592,33 @@ func TestFormatSupport(t *testing.T) {
})
})

t.Run("pdf", func(t *testing.T) {
t.Run("can load", func(t *testing.T) {
img, err := NewImageFromFile(testfile("test.pdf"))
if err != nil {
t.Fatalf("cannot load the pdf: %v", err)
}
if vipsVersionMin(8, 12) {
t.Run("pdf", func(t *testing.T) {
t.Run("can load", func(t *testing.T) {
img, err := NewImageFromFile(testfile("test.pdf"))
if err != nil {
t.Fatalf("cannot load the pdf: %v", err)
}

size := img.Size()
if size.Height != 1050 || size.Width != 1680 {
t.Errorf("unexpected size: %#v", size)
}
})
size := img.Size()
if size.Height != 1050 || size.Width != 1680 {
t.Errorf("unexpected size: %#v", size)
}
})

t.Run("cannot save", func(t *testing.T) {
img, err := NewImageFromFile(testfile("test.pdf"))
if err != nil {
t.Fatalf("cannot load the pdf: %v", err)
}
t.Run("cannot save", func(t *testing.T) {
img, err := NewImageFromFile(testfile("test.pdf"))
if err != nil {
t.Fatalf("cannot load the pdf: %v", err)
}

_, err = img.Save(SaveOptions{})
if err == nil {
t.Error("saving should not work")
}
_, err = img.Save(SaveOptions{})
if err == nil {
t.Error("saving should not work")
}
})
})
})
}

// TODO add a table test for all expected formats
}
10 changes: 5 additions & 5 deletions type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestDeterminateImageType(t *testing.T) {
{"test2.heic", HEIF, true},
{"test3.heic", HEIF, true},
{"test.avif", AVIF, true},
{"test.bmp", MAGICK, true},
{"test.bmp", MAGICK, vipsVersionMin(8, 13)},
}

for _, file := range files {
Expand Down Expand Up @@ -57,13 +57,13 @@ func TestDeterminateImageTypeName(t *testing.T) {
{"test.png", "png", true},
{"test.webp", "webp", true},
{"test.gif", "gif", true},
{"test.pdf", "pdf", true},
{"test.pdf", "pdf", vipsVersionMin(8, 12)},
{"test.svg", "svg", true},
{"test.jp2", "jp2k", vipsVersionMin(8, 11)},
{"test.jxl", "jxl", vipsVersionMin(8, 11)},
{"test.heic", "heif", true},
{"test.avif", "avif", true},
{"test.bmp", "magick", true},
{"test.bmp", "magick", vipsVersionMin(8, 13)},
}

for _, file := range files {
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestIsTypeSupported(t *testing.T) {
{PNG, true},
{WEBP, true},
{GIF, true},
{PDF, true},
{PDF, vipsVersionMin(8, 12)},
{HEIF, true},
{AVIF, true},
{JP2K, vipsVersionMin(8, 11)},
Expand All @@ -120,7 +120,7 @@ func TestIsTypeNameSupported(t *testing.T) {
{"png", true, true},
{"webp", true, true},
{"gif", true, true},
{"pdf", true, true},
{"pdf", true, vipsVersionMin(8, 12)},
{"heif", true, true},
{"avif", true, true},
{"jp2k", true, vipsVersionMin(8, 11)},
Expand Down

0 comments on commit fe4bf5c

Please sign in to comment.