From bf7fec9709e52cd360878a0c0245352afeca9ca6 Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Mon, 27 Apr 2020 21:49:12 -0700 Subject: [PATCH] Add Box test --- box_test.go | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 box_test.go diff --git a/box_test.go b/box_test.go new file mode 100644 index 0000000..7b75fab --- /dev/null +++ b/box_test.go @@ -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 +}