pos_test.go 889 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
  2. // Use of this source code is governed by a MIT license that can
  3. // be found in the LICENSE file.
  4. package termui
  5. import (
  6. "image"
  7. "testing"
  8. )
  9. func TestAlignArea(t *testing.T) {
  10. p := image.Rect(0, 0, 100, 100)
  11. c := image.Rect(10, 10, 20, 20)
  12. nc := AlignArea(p, c, AlignLeft)
  13. if nc.Min.X != 0 || nc.Max.Y != 20 {
  14. t.Errorf("AlignLeft failed:\n%+v", nc)
  15. }
  16. nc = AlignArea(p, c, AlignCenter)
  17. if nc.Min.X != 45 || nc.Max.Y != 55 {
  18. t.Error("AlignCenter failed")
  19. }
  20. nc = AlignArea(p, c, AlignBottom|AlignRight)
  21. if nc.Min.X != 90 || nc.Max.Y != 100 {
  22. t.Errorf("AlignBottom|AlignRight failed\n%+v", nc)
  23. }
  24. }
  25. func TestMoveArea(t *testing.T) {
  26. a := image.Rect(10, 10, 20, 20)
  27. a = MoveArea(a, 5, 10)
  28. if a.Min.X != 15 || a.Min.Y != 20 || a.Max.X != 25 || a.Max.Y != 30 {
  29. t.Error("MoveArea failed")
  30. }
  31. }