2020-04-28 14:57:50 +00:00
|
|
|
package cview
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
listTextA = "Hello, world!"
|
|
|
|
listTextB = "Goodnight, moon!"
|
|
|
|
listTextC = "Hello, Dolly!"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestList(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
2020-04-28 21:58:37 +00:00
|
|
|
// Initialize
|
|
|
|
|
2020-04-28 14:57:50 +00:00
|
|
|
l := NewList()
|
|
|
|
if l.GetItemCount() != 0 {
|
|
|
|
t.Errorf("failed to initialize List: expected item count 0, got %d", l.GetItemCount())
|
|
|
|
} else if l.GetCurrentItem() != 0 {
|
|
|
|
t.Errorf("failed to initialize List: expected current item 0, got %d", l.GetCurrentItem())
|
|
|
|
}
|
|
|
|
|
2020-04-28 21:58:37 +00:00
|
|
|
// Add item 0
|
|
|
|
|
2020-04-28 14:57:50 +00:00
|
|
|
l.AddItem(listTextA, listTextB, 'a', nil)
|
|
|
|
if l.GetItemCount() != 1 {
|
|
|
|
t.Errorf("failed to update List: expected item count 1, got %d", l.GetItemCount())
|
|
|
|
} else if l.GetCurrentItem() != 0 {
|
|
|
|
t.Errorf("failed to update List: expected current item 0, got %d", l.GetCurrentItem())
|
|
|
|
}
|
|
|
|
|
2020-04-28 21:58:37 +00:00
|
|
|
// Get item 0 text
|
|
|
|
|
2020-04-28 14:57:50 +00:00
|
|
|
mainText, secondaryText := l.GetItemText(0)
|
|
|
|
if mainText != listTextA {
|
|
|
|
t.Errorf("failed to update List: expected main text %s, got %s", listTextA, mainText)
|
|
|
|
} else if secondaryText != listTextB {
|
|
|
|
t.Errorf("failed to update List: expected secondary text %s, got %s", listTextB, secondaryText)
|
|
|
|
}
|
|
|
|
|
2020-04-28 21:58:37 +00:00
|
|
|
// Add item 1
|
|
|
|
|
2020-04-28 14:57:50 +00:00
|
|
|
l.AddItem(listTextB, listTextC, 'a', nil)
|
|
|
|
if l.GetItemCount() != 2 {
|
|
|
|
t.Errorf("failed to update List: expected item count 1, got %v", l.GetItemCount())
|
|
|
|
} else if l.GetCurrentItem() != 0 {
|
|
|
|
t.Errorf("failed to update List: expected current item 0, got %v", l.GetCurrentItem())
|
|
|
|
}
|
|
|
|
|
2020-04-28 21:58:37 +00:00
|
|
|
// Get item 1 text
|
|
|
|
|
2020-04-28 14:57:50 +00:00
|
|
|
mainText, secondaryText = l.GetItemText(1)
|
|
|
|
if mainText != listTextB {
|
|
|
|
t.Errorf("failed to update List: expected main text %s, got %s", listTextB, mainText)
|
|
|
|
} else if secondaryText != listTextC {
|
|
|
|
t.Errorf("failed to update List: expected secondary text %s, got %s", listTextC, secondaryText)
|
|
|
|
}
|
|
|
|
|
2020-04-28 21:58:37 +00:00
|
|
|
// Draw
|
|
|
|
|
2020-04-28 14:57:50 +00:00
|
|
|
app, err := newTestApp(l)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to initialize Application: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
l.Draw(app.screen)
|
|
|
|
}
|