Redesign default tree controls
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package uiterm
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -15,6 +16,26 @@ func (i *cyclicItem) TreeItemStyle(fg, bg Attribute, active bool) (Attribute, At
|
||||
return fg, bg
|
||||
}
|
||||
|
||||
func TestTreePassesLeftRightAndBackspaceToFocusedItem(t *testing.T) {
|
||||
item := &cyclicItem{name: "user"}
|
||||
var received []Key
|
||||
tree := Tree{
|
||||
KeyListener: func(_ *Ui, _ *Tree, _ TreeItem, key Key) {
|
||||
received = append(received, key)
|
||||
},
|
||||
lines: []renderedTreeItem{{Item: item}},
|
||||
}
|
||||
tree.uiInitialize(New(nil))
|
||||
|
||||
for _, key := range []Key{KeyArrowLeft, KeyArrowRight, KeyBackspace, KeyBackspace2} {
|
||||
tree.uiKeyEvent(key)
|
||||
}
|
||||
want := []Key{KeyArrowLeft, KeyArrowRight, KeyBackspace, KeyBackspace2}
|
||||
if !reflect.DeepEqual(received, want) {
|
||||
t.Fatalf("tree keys = %v, want %v", received, want)
|
||||
}
|
||||
}
|
||||
|
||||
// Regression: rebuild_rec followed parent/child links with no depth limit, so
|
||||
// a cyclic channel graph recursed until the process ran out of memory. A
|
||||
// rebuild must now terminate and stay bounded.
|
||||
|
||||
Reference in New Issue
Block a user