block_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. "testing"
  7. )
  8. func TestBlockFloat(t *testing.T) {
  9. Init()
  10. defer Close()
  11. b := NewBlock()
  12. b.X = 10
  13. b.Y = 20
  14. b.Float = AlignCenter
  15. b.Align()
  16. }
  17. func TestBlockInnerBounds(t *testing.T) {
  18. Init()
  19. defer Close()
  20. b := NewBlock()
  21. b.X = 10
  22. b.Y = 11
  23. b.Width = 12
  24. b.Height = 13
  25. assert := func(name string, x, y, w, h int) {
  26. t.Log(name)
  27. area := b.InnerBounds()
  28. cx := area.Min.X
  29. cy := area.Min.Y
  30. cw := area.Dx()
  31. ch := area.Dy()
  32. if cx != x {
  33. t.Errorf("expected x to be %d but got %d", x, cx)
  34. }
  35. if cy != y {
  36. t.Errorf("expected y to be %d but got %d\n%+v", y, cy, area)
  37. }
  38. if cw != w {
  39. t.Errorf("expected width to be %d but got %d", w, cw)
  40. }
  41. if ch != h {
  42. t.Errorf("expected height to be %d but got %d", h, ch)
  43. }
  44. }
  45. b.Border = false
  46. assert("no border, no padding", 10, 11, 12, 13)
  47. b.Border = true
  48. assert("border, no padding", 11, 12, 10, 11)
  49. b.PaddingBottom = 2
  50. assert("border, 2b padding", 11, 12, 10, 9)
  51. b.PaddingTop = 3
  52. assert("border, 2b 3t padding", 11, 15, 10, 6)
  53. b.PaddingLeft = 4
  54. assert("border, 2b 3t 4l padding", 15, 15, 6, 6)
  55. b.PaddingRight = 5
  56. assert("border, 2b 3t 4l 5r padding", 15, 15, 1, 6)
  57. }