You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
caddy-hugo2/media/media_test.go

49 lines
1.2 KiB

package media
import (
"fmt"
"image"
"testing"
)
// TestThumbSizeStrings tests parsing various size strings, which doesn't include
// scaling zeros, but does use the actual image size to infer single-dimension
// strings
func TestThumbSizeStrings(t *testing.T) {
type testcase struct {
input string
actualSize image.Rectangle
expect image.Rectangle
}
i50x100 := image.Rect(0, 0, 50, 100)
i100x100 := image.Rect(0, 0, 100, 100)
var cases = []testcase{
{"100x100", i100x100, image.Rect(0, 0, 100, 100)},
{"x100", i100x100, image.Rect(0, 0, 0, 100)},
{"100x", i100x100, image.Rect(0, 0, 100, 0)},
{"100", i100x100, image.Rect(0, 0, 100, 0)},
{"100x100", i50x100, image.Rect(0, 0, 100, 100)},
{"x100", i50x100, image.Rect(0, 0, 0, 100)},
{"100x", i50x100, image.Rect(0, 0, 100, 0)},
{"100", i50x100, image.Rect(0, 0, 0, 100)},
}
for _, c := range cases {
t.Run(fmt.Sprint(c.input, "=>", c.actualSize), func(t *testing.T) {
got, err := ParseSizeString(c.input, image.Rect(0, 0, 100, 100))
if err != nil {
t.Errorf("error parsing size string: %v", err)
return
}
if !got.Eq(c.expect) {
t.Errorf("expected %v, got %v", c.expect, got)
return
}
})
}
}