Terminal-based user interface toolkit
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.2 KiB

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