From f6b4286f18990ed7f98e99858cded9c0d504d97d Mon Sep 17 00:00:00 2001 From: Vladimir Markelov Date: Wed, 23 Dec 2015 15:52:05 -0800 Subject: [PATCH] add listbox test --- listbox_test.go | 64 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 listbox_test.go diff --git a/listbox_test.go b/listbox_test.go new file mode 100644 index 0000000..e355077 --- /dev/null +++ b/listbox_test.go @@ -0,0 +1,64 @@ +package clui + +import ( + "testing" +) + +func TestListBox(t *testing.T) { + width, height := 10, 5 + lbox := NewListBox(nil, nil, width, height, DoNotScale) + + w, h := lbox.Size() + if w != width { + t.Errorf("Width invalid: %v instead of %v", w, width) + } + if h != height { + t.Errorf("Width invalid: %v instead of %v", height, height) + } + + lbox.AddItem("Item1") + lbox.AddItem("Item2") + lbox.AddItem("Item3") + + if lbox.ItemCount() != 3 { + t.Errorf("Item count must be %v instead of %v", 3, lbox.ItemCount()) + } + + n := lbox.FindItem("Item2", false) + if n != 1 { + t.Errorf("Item2 is not found") + } + n = lbox.FindItem("item2", true) + if n != 1 { + t.Errorf("item2 is not found") + } + lbox.SelectItem(n) + str := lbox.SelectedItemText() + if str != "Item2" { + t.Errorf("The second item text must be %v, found %v", "Item2", str) + } + n = lbox.FindItem("item4", false) + if n != -1 { + t.Errorf("item4 should not be found") + } + lbox.RemoveItem(1) + if lbox.ItemCount() != 2 { + t.Errorf("After deleting an item the list box item count should decrease (%v)", lbox.ItemCount()) + } + str = lbox.SelectedItemText() + if str != "Item3" { + t.Errorf("The second item text must be %v, found %v", "Item3", str) + } + n = lbox.FindItem("Item2", false) + if n != -1 { + t.Errorf("Item2 should not be found") + } + n = lbox.FindItem("item3", true) + if n != 1 { + t.Errorf("Item3 should #%v instead of %v", 1, n) + } + lbox.Clear() + if lbox.ItemCount() != 0 { + t.Errorf("Clear failed") + } +}