Add Box test

This commit is contained in:
Trevor Slocum 2020-04-27 21:49:12 -07:00
parent 2e583de86f
commit bf7fec9709
1 changed files with 59 additions and 0 deletions

59
box_test.go Normal file
View File

@ -0,0 +1,59 @@
package cview
import (
"testing"
"github.com/gdamore/tcell"
)
const (
testBoxTitleA = "Hello, world!"
testBoxTitleB = "Goodnight, moon!"
)
func TestBox(t *testing.T) {
t.Parallel()
b, sc, err := testBox()
if err != nil {
t.Error(err)
}
if b.GetTitle() != "" {
t.Errorf("failed to initalize Box: incorrect initial state: expected blank title, got %s", b.GetTitle())
} else if b.border {
t.Errorf("failed to initalize Box: incorrect initial state: expected no border, got border")
}
b.SetTitle(testBoxTitleA)
if b.GetTitle() != testBoxTitleA {
t.Errorf("failed to update Box: incorrect title: expected %s, got %s", testBoxTitleA, b.GetTitle())
}
b.SetTitle(testBoxTitleB)
if b.GetTitle() != testBoxTitleB {
t.Errorf("failed to update Box: incorrect title: expected %s, got %s", testBoxTitleB, b.GetTitle())
}
b.SetBorder(true)
if !b.border {
t.Errorf("failed to update Box: incorrect state: expected border, got no border")
}
b.SetBorder(false)
if b.border {
t.Errorf("failed to update Box: incorrect state: expected no border, got border")
}
b.Draw(sc)
}
func testBox() (*Box, tcell.Screen, error) {
b := NewBox()
sc := tcell.NewSimulationScreen("UTF-8")
sc.SetSize(80, 24)
_ = NewApplication().SetRoot(b, true).SetScreen(sc)
return b, sc, nil
}