|
@@ -1,6 +1,7 @@
|
|
|
package door
|
|
|
|
|
|
import (
|
|
|
+ "fmt"
|
|
|
"strings"
|
|
|
"testing"
|
|
|
)
|
|
@@ -32,3 +33,46 @@ func TestPanel(t *testing.T) {
|
|
|
t.Errorf("Panel TitleOffset=3 expected %#v, got %#v", es[0], gs[1])
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func TestPanelSpacer(t *testing.T) {
|
|
|
+ p := Panel{X: 1, Y: 1, Width: 5, Style: SINGLE}
|
|
|
+ p.Lines = append(p.Lines, p.Spacer())
|
|
|
+ expected := Goto(1, 1) + "┌─────┐" + Goto(1, 2) + "├─────┤" + Goto(1, 3) + "└─────┘"
|
|
|
+ got := p.Output()
|
|
|
+ if expected != got {
|
|
|
+ t.Errorf("Panel Spacer expected %#v, got %#v", expected, got)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func TestPanelUpdate(t *testing.T) {
|
|
|
+ p := Panel{X: 2, Y: 2, Width: 3, Style: DOUBLE_SINGLE}
|
|
|
+ var x int = 0
|
|
|
+ updater := func() string {
|
|
|
+ return fmt.Sprintf("%3d", x)
|
|
|
+ }
|
|
|
+ l := Line{UpdateF: updater}
|
|
|
+ l.Update()
|
|
|
+ p.Lines = append(p.Lines, l)
|
|
|
+
|
|
|
+ expected := Goto(2, 2) + "╒═══╕" + Goto(2, 3) + "│ 0│" + Goto(2, 4) + "╘═══╛"
|
|
|
+ got := p.Output()
|
|
|
+
|
|
|
+ if expected != got {
|
|
|
+ t.Errorf("Panel Update expected %#v, got %#v", expected, got)
|
|
|
+ }
|
|
|
+
|
|
|
+ x += 3
|
|
|
+ got = p.Update()
|
|
|
+ expected = Goto(3, 3) + " 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)
|
|
|
+ }
|
|
|
+
|
|
|
+}
|