123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- package door
- import (
- "fmt"
- "strings"
- "testing"
- )
- func TestPanel(t *testing.T) {
- var p Panel = Panel{X: 5, Y: 7, Width: 10, Style: DOUBLE, Title: "Test"}
- p.Lines = append(p.Lines, Line{Text: "1234567890"})
- p.Lines = append(p.Lines, Line{Text: "abcdefghij"})
- var expected string = Goto(5, 7) + "╔Test══════╗" + Goto(5, 8) + "║1234567890║" + Goto(5, 9) + "║abcdefghij║" + Goto(5, 10) + "╚══════════╝"
- var got string = p.Output()
- var es []string = strings.SplitAfter(expected, "5H")
- var gs []string = strings.SplitAfter(got, "5H")
- for idx, exp := range es {
- var g string = gs[idx]
- if g != exp {
- t.Errorf("Panel expected %#v, got %#v", exp, g)
- }
- }
- p.TitleOffset = 3
- got = p.Output()
- gs = strings.SplitAfter(got, "5H")
- es[0] = "╔═══Test═══╗" + Goto(5, 8)
- if gs[1] != es[0] {
- t.Errorf("Panel TitleOffset=3 expected %#v, got %#v", es[0], gs[1])
- }
- }
- func TestPanelSpacer(t *testing.T) {
- var p Panel = Panel{X: 1, Y: 1, Width: 5, Style: SINGLE}
- p.Lines = append(p.Lines, p.Spacer())
- var expected string = Goto(1, 1) + "┌─────┐" + Goto(1, 2) + "├─────┤" + Goto(1, 3) + "└─────┘"
- var got string = p.Output()
- if expected != got {
- t.Errorf("Panel Spacer expected %#v, got %#v", expected, got)
- }
- }
- func TestPanelUpdate(t *testing.T) {
- var TestX int = 2
- var TestY int = 2
- var p Panel = Panel{X: TestX, Y: TestY, Width: 3, Style: DOUBLE_SINGLE}
- var x int = 0
- var updater Updater = func() string {
- return fmt.Sprintf("%3d", x)
- }
- var l Line = Line{UpdateF: updater}
- l.Update()
- p.Lines = append(p.Lines, l)
- var expected string = Goto(TestX, TestY) + "╒═══╕" + Goto(TestX, TestY+1) + "│ 0│" + Goto(TestX, TestY+2) + "╘═══╛"
- var got string = p.Output()
- if expected != got {
- t.Errorf("Panel Update expected %#v, got %#v", expected, got)
- }
- x += 3
- got = p.Update()
- expected = Goto(TestX+1, TestY+1) + " 3"
- if expected != got {
- t.Errorf("Panel Update expected %#v, got %#v", expected, got)
- }
- got = p.Update()
- if got != "" {
- t.Errorf("Panel Update expected '', got %#v", got)
- }
- got = p.UpdateLine(0)
- if expected != got {
- t.Errorf("Panel UpdateLine expected %#v, got %#v", expected, got)
- }
- // Expected: Width = 3, Length = 1
- if p.Width != 3 {
- t.Errorf("Panel Width, expected %d, got %d\n", 3, p.Width)
- }
- if p.Length() != 1 {
- t.Errorf("Panel Length, expected %d, got %d\n", 1, p.Length())
- }
- got = p.GotoEnd()
- expected = Goto(p.X+p.Width+2, p.Y+p.Length()+2)
- if got != expected {
- t.Errorf("Panel GotoEnd expected %#v, got %#v", expected, got)
- }
- }
|