adding a test for parsing size strings
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package caddyhugo
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user