cview/checkbox_test.go

57 lines
1.3 KiB
Go
Raw Normal View History

2020-04-26 23:46:43 +00:00
package cview
import (
"testing"
"github.com/gdamore/tcell"
)
const (
2020-04-26 23:55:45 +00:00
testCheckBoxLabelA = "Hello, world!"
testCheckBoxLabelB = "Goodnight, moon!"
2020-04-26 23:46:43 +00:00
)
2020-04-26 23:55:45 +00:00
func TestCheckBox(t *testing.T) {
2020-04-26 23:46:43 +00:00
t.Parallel()
2020-04-26 23:55:45 +00:00
c, sc, err := testCheckBox()
2020-04-26 23:46:43 +00:00
if err != nil {
t.Error(err)
}
if c.IsChecked() {
2020-04-26 23:55:45 +00:00
t.Errorf("failed to initalize CheckBox: incorrect initial state: expected unchecked, got checked")
} else if c.GetLabel() != testCheckBoxLabelA {
t.Errorf("failed to initalize CheckBox: incorrect label: expected %s, got %s", testCheckBoxLabelA, c.GetLabel())
2020-04-26 23:46:43 +00:00
}
2020-04-26 23:55:45 +00:00
c.SetLabel(testCheckBoxLabelB)
if c.GetLabel() != testCheckBoxLabelB {
t.Errorf("failed to set CheckBox label: incorrect label: expected %s, got %s", testCheckBoxLabelB, c.GetLabel())
2020-04-26 23:46:43 +00:00
}
c.SetChecked(true)
if !c.IsChecked() {
2020-04-26 23:55:45 +00:00
t.Errorf("failed to update CheckBox state: incorrect state: expected checked, got unchecked")
2020-04-26 23:46:43 +00:00
}
c.SetChecked(false)
if c.IsChecked() {
2020-04-26 23:55:45 +00:00
t.Errorf("failed to update CheckBox state: incorrect state: expected unchecked, got checked")
2020-04-26 23:46:43 +00:00
}
c.Draw(sc)
}
2020-04-26 23:55:45 +00:00
func testCheckBox() (*CheckBox, tcell.Screen, error) {
c := NewCheckBox()
2020-04-26 23:46:43 +00:00
sc := tcell.NewSimulationScreen("UTF-8")
sc.SetSize(80, 24)
_ = NewApplication().SetRoot(c, true).SetScreen(sc)
2020-04-26 23:55:45 +00:00
c.SetLabel(testCheckBoxLabelA)
2020-04-26 23:46:43 +00:00
return c, sc, nil
}