Browse Source

Add comments to tests

tablepad
Trevor Slocum 2 years ago
parent
commit
233de43609
  1. 8
      box_test.go
  2. 6
      button_test.go
  3. 8
      checkbox_test.go
  4. 12
      list_test.go
  5. 8
      progressbar_test.go
  6. 12
      treeview_test.go

8
box_test.go

@ -12,6 +12,8 @@ const (
func TestBox(t *testing.T) {
t.Parallel()
// Initialize
b := NewBox()
if b.GetTitle() != "" {
t.Errorf("failed to initialize Box: incorrect initial state: expected blank title, got %s", b.GetTitle())
@ -19,6 +21,8 @@ func TestBox(t *testing.T) {
t.Errorf("failed to initialize Box: incorrect initial state: expected no border, got border")
}
// Set title
b.SetTitle(testBoxTitleA)
if b.GetTitle() != testBoxTitleA {
t.Errorf("failed to update Box: incorrect title: expected %s, got %s", testBoxTitleA, b.GetTitle())
@ -29,6 +33,8 @@ func TestBox(t *testing.T) {
t.Errorf("failed to update Box: incorrect title: expected %s, got %s", testBoxTitleB, b.GetTitle())
}
// Set border
b.SetBorder(true)
if !b.border {
t.Errorf("failed to update Box: incorrect state: expected border, got no border")
@ -39,6 +45,8 @@ func TestBox(t *testing.T) {
t.Errorf("failed to update Box: incorrect state: expected no border, got border")
}
// Draw
app, err := newTestApp(b)
if err != nil {
t.Errorf("failed to initialize Application: %s", err)

6
button_test.go

@ -12,11 +12,15 @@ const (
func TestButton(t *testing.T) {
t.Parallel()
// Initialize
b := NewButton(testButtonLabelA)
if b.GetLabel() != testButtonLabelA {
t.Errorf("failed to initialize Button: incorrect label: expected %s, got %s", testButtonLabelA, b.GetLabel())
}
// Set label
b.SetLabel(testButtonLabelB)
if b.GetLabel() != testButtonLabelB {
t.Errorf("failed to update Button: incorrect label: expected %s, got %s", testButtonLabelB, b.GetLabel())
@ -27,6 +31,8 @@ func TestButton(t *testing.T) {
t.Errorf("failed to update Button: incorrect label: expected %s, got %s", testButtonLabelA, b.GetLabel())
}
// Draw
app, err := newTestApp(b)
if err != nil {
t.Errorf("failed to initialize Application: %s", err)

8
checkbox_test.go

@ -12,6 +12,8 @@ const (
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")
@ -19,6 +21,8 @@ func TestCheckBox(t *testing.T) {
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())
@ -29,6 +33,8 @@ func TestCheckBox(t *testing.T) {
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")
@ -39,6 +45,8 @@ func TestCheckBox(t *testing.T) {
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)

12
list_test.go

@ -13,6 +13,8 @@ const (
func TestList(t *testing.T) {
t.Parallel()
// Initialize
l := NewList()
if l.GetItemCount() != 0 {
t.Errorf("failed to initialize List: expected item count 0, got %d", l.GetItemCount())
@ -20,6 +22,8 @@ func TestList(t *testing.T) {
t.Errorf("failed to initialize List: expected current item 0, got %d", l.GetCurrentItem())
}
// Add item 0
l.AddItem(listTextA, listTextB, 'a', nil)
if l.GetItemCount() != 1 {
t.Errorf("failed to update List: expected item count 1, got %d", l.GetItemCount())
@ -27,6 +31,8 @@ func TestList(t *testing.T) {
t.Errorf("failed to update List: expected current item 0, got %d", l.GetCurrentItem())
}
// Get item 0 text
mainText, secondaryText := l.GetItemText(0)
if mainText != listTextA {
t.Errorf("failed to update List: expected main text %s, got %s", listTextA, mainText)
@ -34,6 +40,8 @@ func TestList(t *testing.T) {
t.Errorf("failed to update List: expected secondary text %s, got %s", listTextB, secondaryText)
}
// Add item 1
l.AddItem(listTextB, listTextC, 'a', nil)
if l.GetItemCount() != 2 {
t.Errorf("failed to update List: expected item count 1, got %v", l.GetItemCount())
@ -41,6 +49,8 @@ func TestList(t *testing.T) {
t.Errorf("failed to update List: expected current item 0, got %v", l.GetCurrentItem())
}
// Get item 1 text
mainText, secondaryText = l.GetItemText(1)
if mainText != listTextB {
t.Errorf("failed to update List: expected main text %s, got %s", listTextB, mainText)
@ -48,6 +58,8 @@ func TestList(t *testing.T) {
t.Errorf("failed to update List: expected secondary text %s, got %s", listTextC, secondaryText)
}
// Draw
app, err := newTestApp(l)
if err != nil {
t.Errorf("failed to initialize Application: %s", err)

8
progressbar_test.go

@ -7,6 +7,8 @@ import (
func TestProgressBar(t *testing.T) {
t.Parallel()
// Initialize
p := NewProgressBar()
if p.GetProgress() != 0 {
t.Errorf("failed to initialize ProgressBar: incorrect initial state: expected 0 progress, got %d", p.GetProgress())
@ -16,6 +18,8 @@ func TestProgressBar(t *testing.T) {
t.Errorf("failed to initialize ProgressBar: incorrect initial state: expected incomplete, got complete")
}
// Add progress
p.AddProgress(25)
if p.GetProgress() != 25 {
t.Errorf("failed to update ProgressBar: incorrect state: expected 25 progress, got %d", p.GetProgress())
@ -44,6 +48,8 @@ func TestProgressBar(t *testing.T) {
t.Errorf("failed to update ProgressBar: incorrect state: expected complete, got incomplete")
}
// Reset progress
p.SetProgress(0)
if p.GetProgress() != 0 {
t.Errorf("failed to update ProgressBar: incorrect state: expected 0 progress, got %d", p.GetProgress())
@ -51,6 +57,8 @@ func TestProgressBar(t *testing.T) {
t.Errorf("failed to update ProgressBar: incorrect state: expected incomplete, got complete")
}
// Draw
app, err := newTestApp(p)
if err != nil {
t.Errorf("failed to initialize Application: %s", err)

12
treeview_test.go

@ -12,6 +12,8 @@ const (
func TestTreeView(t *testing.T) {
t.Parallel()
// Initialize
tr := NewTreeView()
if tr.GetRoot() != nil {
t.Errorf("failed to initialize TreeView: expected nil root node, got %v", tr.GetRoot())
@ -26,11 +28,15 @@ func TestTreeView(t *testing.T) {
t.Errorf("failed to initialize Application: %s", err)
}
// Create root node
rootNode := NewTreeNode(treeViewTextA)
if rootNode.GetText() != treeViewTextA {
t.Errorf("failed to update TreeView: incorrect node text: expected %s, got %s", treeViewTextA, rootNode.GetText())
}
// Add root node
tr.SetRoot(rootNode)
tr.Draw(app.screen)
if tr.GetRoot() != rootNode {
@ -39,16 +45,22 @@ func TestTreeView(t *testing.T) {
t.Errorf("failed to initialize TreeView: incorrect row count: expected 1, got %d", tr.GetRowCount())
}
// Set current node
tr.SetCurrentNode(rootNode)
if tr.GetCurrentNode() != rootNode {
t.Errorf("failed to initialize TreeView: expected current node A, got %v", tr.GetCurrentNode())
}
// Create child node
childNode := NewTreeNode(treeViewTextB)
if childNode.GetText() != treeViewTextB {
t.Errorf("failed to update TreeView: incorrect node text: expected %s, got %s", treeViewTextB, childNode.GetText())
}
// Add child node
rootNode.AddChild(childNode)
tr.Draw(app.screen)
if tr.GetRoot() != rootNode {

Loading…
Cancel
Save