cview/box_test.go

57 lines
1.2 KiB
Go
Raw Normal View History

2020-04-28 04:49:12 +00:00
package cview
import (
"testing"
)
const (
testBoxTitleA = "Hello, world!"
testBoxTitleB = "Goodnight, moon!"
)
func TestBox(t *testing.T) {
t.Parallel()
2020-04-28 21:58:37 +00:00
// Initialize
2020-04-28 14:57:37 +00:00
b := NewBox()
2020-04-28 04:49:12 +00:00
if b.GetTitle() != "" {
2020-04-28 14:57:37 +00:00
t.Errorf("failed to initialize Box: incorrect initial state: expected blank title, got %s", b.GetTitle())
2020-04-28 04:49:12 +00:00
} else if b.border {
2020-04-28 14:57:37 +00:00
t.Errorf("failed to initialize Box: incorrect initial state: expected no border, got border")
2020-04-28 04:49:12 +00:00
}
2020-04-28 21:58:37 +00:00
// Set title
2020-04-28 04:49:12 +00:00
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())
}
2020-04-28 21:58:37 +00:00
// Set border
2020-04-28 04:49:12 +00:00
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")
}
2020-04-28 21:58:37 +00:00
// Draw
2020-04-28 14:57:37 +00:00
app, err := newTestApp(b)
if err != nil {
t.Errorf("failed to initialize Application: %s", err)
}
2020-04-28 04:49:12 +00:00
2020-04-28 14:57:37 +00:00
b.Draw(app.screen)
2020-04-28 04:49:12 +00:00
}