panel_test.go 872 B

12345678910111213141516171819202122232425262728293031323334
  1. package door
  2. import (
  3. "strings"
  4. "testing"
  5. )
  6. func TestPanel(t *testing.T) {
  7. p := Panel{X: 5, Y: 7, Width: 10, Style: DOUBLE, Title: "Test"}
  8. p.Lines = append(p.Lines, Line{Text: "1234567890"})
  9. p.Lines = append(p.Lines, Line{Text: "abcdefghij"})
  10. expected := Goto(5, 7) + "╔Test══════╗" + Goto(5, 8) + "║1234567890║" + Goto(5, 9) + "║abcdefghij║" + Goto(5, 10) + "╚══════════╝"
  11. got := p.Output()
  12. es := strings.SplitAfter(expected, "5H")
  13. gs := strings.SplitAfter(got, "5H")
  14. for idx, exp := range es {
  15. g := gs[idx]
  16. if g != exp {
  17. t.Errorf("Panel expected %#v, got %#v", exp, g)
  18. }
  19. }
  20. p.TitleOffset = 3
  21. got = p.Output()
  22. gs = strings.SplitAfter(got, "5H")
  23. es[0] = "╔═══Test═══╗" + Goto(5, 8)
  24. if gs[1] != es[0] {
  25. t.Errorf("Panel TitleOffset=3 expected %#v, got %#v", es[0], gs[1])
  26. }
  27. }