adding a test for parsing size strings

pull/8/head
Stephen Searles 7 years ago
parent e5d16dd2d5
commit 07daa5e160
  1. 49
      media_test.go

@ -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
}
})
}
}
Loading…
Cancel
Save