...
1 package cview
2
3 import (
4 "testing"
5 )
6
7 const (
8 testButtonLabelA = "Hello, world!"
9 testButtonLabelB = "Goodnight, moon!"
10 )
11
12 func TestButton(t *testing.T) {
13 t.Parallel()
14
15
16
17 b := NewButton(testButtonLabelA)
18 if b.GetLabel() != testButtonLabelA {
19 t.Errorf("failed to initialize Button: incorrect label: expected %s, got %s", testButtonLabelA, b.GetLabel())
20 }
21
22
23
24 b.SetLabel(testButtonLabelB)
25 if b.GetLabel() != testButtonLabelB {
26 t.Errorf("failed to update Button: incorrect label: expected %s, got %s", testButtonLabelB, b.GetLabel())
27 }
28
29 b.SetLabel(testButtonLabelA)
30 if b.GetLabel() != testButtonLabelA {
31 t.Errorf("failed to update Button: incorrect label: expected %s, got %s", testButtonLabelA, b.GetLabel())
32 }
33
34
35
36 app, err := newTestApp(b)
37 if err != nil {
38 t.Errorf("failed to initialize Application: %s", err)
39 }
40
41 b.Draw(app.screen)
42 }
43
View as plain text