grid_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. "github.com/davecgh/go-spew/spew"
  8. )
  9. var r *Row
  10. func TestRowWidth(t *testing.T) {
  11. p0 := NewBlock()
  12. p0.Height = 1
  13. p1 := NewBlock()
  14. p1.Height = 1
  15. p2 := NewBlock()
  16. p2.Height = 1
  17. p3 := NewBlock()
  18. p3.Height = 1
  19. /* test against tree:
  20. r
  21. / \
  22. 0:w 1
  23. / \
  24. 10:w 11
  25. /
  26. 110:w
  27. /
  28. 1100:w
  29. */
  30. r = NewRow(
  31. NewCol(6, 0, p0),
  32. NewCol(6, 0,
  33. NewRow(
  34. NewCol(6, 0, p1),
  35. NewCol(6, 0, p2, p3))))
  36. r.assignWidth(100)
  37. if r.Width != 100 ||
  38. (r.Cols[0].Width) != 50 ||
  39. (r.Cols[1].Width) != 50 ||
  40. (r.Cols[1].Cols[0].Width) != 25 ||
  41. (r.Cols[1].Cols[1].Width) != 25 ||
  42. (r.Cols[1].Cols[1].Cols[0].Width) != 25 ||
  43. (r.Cols[1].Cols[1].Cols[0].Cols[0].Width) != 25 {
  44. t.Error("assignWidth fails")
  45. }
  46. }
  47. func TestRowHeight(t *testing.T) {
  48. spew.Dump()
  49. if (r.solveHeight()) != 2 ||
  50. (r.Cols[1].Cols[1].Height) != 2 ||
  51. (r.Cols[1].Cols[1].Cols[0].Height) != 2 ||
  52. (r.Cols[1].Cols[0].Height) != 1 {
  53. t.Error("solveHeight fails")
  54. }
  55. }
  56. func TestAssignXY(t *testing.T) {
  57. r.assignX(0)
  58. r.assignY(0)
  59. if (r.Cols[0].X) != 0 ||
  60. (r.Cols[1].Cols[0].X) != 50 ||
  61. (r.Cols[1].Cols[1].X) != 75 ||
  62. (r.Cols[1].Cols[1].Cols[0].X) != 75 ||
  63. (r.Cols[1].Cols[0].Y) != 0 ||
  64. (r.Cols[1].Cols[1].Cols[0].Y) != 0 ||
  65. (r.Cols[1].Cols[1].Cols[0].Cols[0].Y) != 1 {
  66. t.Error("assignXY fails")
  67. }
  68. }