...

Source file src/code.rocketnine.space/tslocum/cview/checkbox_test.go

Documentation: code.rocketnine.space/tslocum/cview

     1  package cview
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  const (
     8  	testCheckBoxLabelA = "Hello, world!"
     9  	testCheckBoxLabelB = "Goodnight, moon!"
    10  )
    11  
    12  func TestCheckBox(t *testing.T) {
    13  	t.Parallel()
    14  
    15  	// Initialize
    16  
    17  	c := NewCheckBox()
    18  	if c.IsChecked() {
    19  		t.Errorf("failed to initialize CheckBox: incorrect initial state: expected unchecked, got checked")
    20  	} else if c.GetLabel() != "" {
    21  		t.Errorf("failed to initialize CheckBox: incorrect label: expected '', got %s", c.GetLabel())
    22  	}
    23  
    24  	// Set label
    25  
    26  	c.SetLabel(testCheckBoxLabelA)
    27  	if c.GetLabel() != testCheckBoxLabelA {
    28  		t.Errorf("failed to set CheckBox label: incorrect label: expected %s, got %s", testCheckBoxLabelA, c.GetLabel())
    29  	}
    30  
    31  	c.SetLabel(testCheckBoxLabelB)
    32  	if c.GetLabel() != testCheckBoxLabelB {
    33  		t.Errorf("failed to set CheckBox label: incorrect label: expected %s, got %s", testCheckBoxLabelB, c.GetLabel())
    34  	}
    35  
    36  	// Set checked
    37  
    38  	c.SetChecked(true)
    39  	if !c.IsChecked() {
    40  		t.Errorf("failed to update CheckBox state: incorrect state: expected checked, got unchecked")
    41  	}
    42  
    43  	c.SetChecked(false)
    44  	if c.IsChecked() {
    45  		t.Errorf("failed to update CheckBox state: incorrect state: expected unchecked, got checked")
    46  	}
    47  
    48  	// Draw
    49  
    50  	app, err := newTestApp(c)
    51  	if err != nil {
    52  		t.Errorf("failed to initialize Application: %s", err)
    53  	}
    54  
    55  	c.Draw(app.screen)
    56  }
    57  

View as plain text