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.
 
 
 

50 lines
1.2 KiB

  1. package media
  2. import (
  3. "fmt"
  4. "image"
  5. "testing"
  6. )
  7. // TestThumbSizeStrings tests parsing various size strings, which doesn't include
  8. // scaling zeros, but does use the actual image size to infer single-dimension
  9. // strings
  10. func TestThumbSizeStrings(t *testing.T) {
  11. type testcase struct {
  12. input string
  13. actualSize image.Rectangle
  14. expect image.Rectangle
  15. }
  16. i50x100 := image.Rect(0, 0, 50, 100)
  17. i100x100 := image.Rect(0, 0, 100, 100)
  18. var cases = []testcase{
  19. {"100x100", i100x100, image.Rect(0, 0, 100, 100)},
  20. {"x100", i100x100, image.Rect(0, 0, 0, 100)},
  21. {"100x", i100x100, image.Rect(0, 0, 100, 0)},
  22. {"100", i100x100, image.Rect(0, 0, 100, 0)},
  23. {"100x100", i50x100, image.Rect(0, 0, 100, 100)},
  24. {"x100", i50x100, image.Rect(0, 0, 0, 100)},
  25. {"100x", i50x100, image.Rect(0, 0, 100, 0)},
  26. {"100", i50x100, image.Rect(0, 0, 0, 100)},
  27. }
  28. for _, c := range cases {
  29. t.Run(fmt.Sprint(c.input, "=>", c.actualSize), func(t *testing.T) {
  30. got, err := ParseSizeString(c.input, image.Rect(0, 0, 100, 100))
  31. if err != nil {
  32. t.Errorf("error parsing size string: %v", err)
  33. return
  34. }
  35. if !got.Eq(c.expect) {
  36. t.Errorf("expected %v, got %v", c.expect, got)
  37. return
  38. }
  39. })
  40. }
  41. }