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.

43 lines
889 B

2 years ago
package cview
import (
"testing"
)
const (
testButtonLabelA = "Hello, world!"
testButtonLabelB = "Goodnight, moon!"
)
func TestButton(t *testing.T) {
t.Parallel()
// Initialize
2 years ago
b := NewButton(testButtonLabelA)
2 years ago
if b.GetLabel() != testButtonLabelA {
2 years ago
t.Errorf("failed to initialize Button: incorrect label: expected %s, got %s", testButtonLabelA, b.GetLabel())
2 years ago
}
// Set label
2 years ago
b.SetLabel(testButtonLabelB)
if b.GetLabel() != testButtonLabelB {
t.Errorf("failed to update Button: incorrect label: expected %s, got %s", testButtonLabelB, b.GetLabel())
}
b.SetLabel(testButtonLabelA)
if b.GetLabel() != testButtonLabelA {
t.Errorf("failed to update Button: incorrect label: expected %s, got %s", testButtonLabelA, b.GetLabel())
}
// 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
}