File: checkbox_test.go

package info (click to toggle)
golang-code.rocketnine-tslocum-cview 1.5.4-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 3,396 kB
  • sloc: makefile: 40
file content (56 lines) | stat: -rw-r--r-- 1,301 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package cview

import (
	"testing"
)

const (
	testCheckBoxLabelA = "Hello, world!"
	testCheckBoxLabelB = "Goodnight, moon!"
)

func TestCheckBox(t *testing.T) {
	t.Parallel()

	// Initialize

	c := NewCheckBox()
	if c.IsChecked() {
		t.Errorf("failed to initialize CheckBox: incorrect initial state: expected unchecked, got checked")
	} else if c.GetLabel() != "" {
		t.Errorf("failed to initialize CheckBox: incorrect label: expected '', got %s", c.GetLabel())
	}

	// Set label

	c.SetLabel(testCheckBoxLabelA)
	if c.GetLabel() != testCheckBoxLabelA {
		t.Errorf("failed to set CheckBox label: incorrect label: expected %s, got %s", testCheckBoxLabelA, c.GetLabel())
	}

	c.SetLabel(testCheckBoxLabelB)
	if c.GetLabel() != testCheckBoxLabelB {
		t.Errorf("failed to set CheckBox label: incorrect label: expected %s, got %s", testCheckBoxLabelB, c.GetLabel())
	}

	// Set checked

	c.SetChecked(true)
	if !c.IsChecked() {
		t.Errorf("failed to update CheckBox state: incorrect state: expected checked, got unchecked")
	}

	c.SetChecked(false)
	if c.IsChecked() {
		t.Errorf("failed to update CheckBox state: incorrect state: expected unchecked, got checked")
	}

	// Draw

	app, err := newTestApp(c)
	if err != nil {
		t.Errorf("failed to initialize Application: %s", err)
	}

	c.Draw(app.screen)
}