Ver Fonte

Panel Update is working. Fixed update.

Steve Thielemann há 3 anos atrás
pai
commit
353d71b2eb
2 ficheiros alterados com 47 adições e 3 exclusões
  1. 3 3
      door/panel.go
  2. 44 0
      door/panel_test.go

+ 3 - 3
door/panel.go

@@ -90,10 +90,10 @@ func (p *Panel) Update() string {
 		col++
 	}
 
-	for _, line := range p.Lines {
-		if line.Update() {
+	for idx, _ := range p.Lines {
+		if p.Lines[idx].Update() {
 			// Yes, line was updated
-			output += Goto(col, row) + line.Output()
+			output += Goto(col, row) + p.Lines[idx].Output()
 		}
 		row++
 	}

+ 44 - 0
door/panel_test.go

@@ -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)
+	}
+
+}