Browse Source

Initial panel testing.

Steve Thielemann 3 years ago
parent
commit
53f647248f
1 changed files with 34 additions and 0 deletions
  1. 34 0
      door/panel_test.go

+ 34 - 0
door/panel_test.go

@@ -0,0 +1,34 @@
+package door
+
+import (
+	"strings"
+	"testing"
+)
+
+func TestPanel(t *testing.T) {
+	p := 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"})
+
+	expected := Goto(5, 7) + "╔Test══════╗" + Goto(5, 8) + "║1234567890║" + Goto(5, 9) + "║abcdefghij║" + Goto(5, 10) + "╚══════════╝"
+	got := p.Output()
+
+	es := strings.SplitAfter(expected, "5H")
+	gs := strings.SplitAfter(got, "5H")
+
+	for idx, exp := range es {
+		g := 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])
+	}
+}