tests for history searching
This commit is contained in:
parent
31dcb13836
commit
1523fef000
@ -474,4 +474,41 @@ func TestHistory(t *testing.T) {
|
|||||||
test(ActionHistoryNext, "a", "")
|
test(ActionHistoryNext, "a", "")
|
||||||
test(ActionHistoryNext, "a", "")
|
test(ActionHistoryNext, "a", "")
|
||||||
|
|
||||||
|
ah := func(before_cursor, after_cursor string) {
|
||||||
|
ab := rl.text_upto_cursor_pos()
|
||||||
|
aa := rl.text_after_cursor_pos()
|
||||||
|
if diff := cmp.Diff(before_cursor, ab); diff != "" {
|
||||||
|
t.Fatalf("Text before cursor not as expected:\n%s", diff)
|
||||||
|
}
|
||||||
|
if diff := cmp.Diff(after_cursor, aa); diff != "" {
|
||||||
|
t.Fatalf("Text before cursor not as expected:\n%s", diff)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_item("xyz1")
|
||||||
|
add_item("xyz2")
|
||||||
|
add_item("xyz11")
|
||||||
|
rl.perform_action(ActionHistoryIncrementalSearchBackwards, 1)
|
||||||
|
ah("", "")
|
||||||
|
|
||||||
|
rl.text_to_be_added = "z"
|
||||||
|
rl.perform_action(ActionAddText, 1)
|
||||||
|
ah("xy", "z11")
|
||||||
|
rl.text_to_be_added = "2"
|
||||||
|
rl.perform_action(ActionAddText, 1)
|
||||||
|
ah("xy", "z2")
|
||||||
|
rl.text_to_be_added = "m"
|
||||||
|
rl.perform_action(ActionAddText, 1)
|
||||||
|
ah("No matches for: z2m", "")
|
||||||
|
rl.perform_action(ActionBackspace, 1)
|
||||||
|
ah("xy", "z2")
|
||||||
|
rl.perform_action(ActionBackspace, 1)
|
||||||
|
ah("xy", "z2")
|
||||||
|
rl.perform_action(ActionHistoryIncrementalSearchBackwards, 1)
|
||||||
|
ah("xy", "z1")
|
||||||
|
rl.perform_action(ActionHistoryIncrementalSearchBackwards, 1)
|
||||||
|
ah("xy", "z1")
|
||||||
|
rl.perform_action(ActionHistoryIncrementalSearchForwards, 1)
|
||||||
|
ah("xy", "z2")
|
||||||
|
rl.perform_action(ActionTerminateHistorySearchAndRestore, 1)
|
||||||
|
ah("a", "")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -297,8 +297,8 @@ func (self *Readline) add_text_to_history_search(text string) {
|
|||||||
self.history_search.items = []*HistoryItem{}
|
self.history_search.items = []*HistoryItem{}
|
||||||
} else {
|
} else {
|
||||||
items := make([]*HistoryItem, len(self.history.items))
|
items := make([]*HistoryItem, len(self.history.items))
|
||||||
for i, x := range self.history.items {
|
for i := range self.history.items {
|
||||||
items[i] = &x
|
items[i] = &self.history.items[i]
|
||||||
}
|
}
|
||||||
for _, token := range self.history_search.tokens {
|
for _, token := range self.history_search.tokens {
|
||||||
matches := make([]*HistoryItem, 0, len(items))
|
matches := make([]*HistoryItem, 0, len(items))
|
||||||
@ -319,7 +319,11 @@ func (self *Readline) add_text_to_history_search(text string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if idx == -1 {
|
if idx == -1 {
|
||||||
|
if self.history_search.backwards {
|
||||||
idx = len(self.history_search.items) - 1
|
idx = len(self.history_search.items) - 1
|
||||||
|
} else {
|
||||||
|
idx = 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
self.history_search.current_idx = utils.Max(0, idx)
|
self.history_search.current_idx = utils.Max(0, idx)
|
||||||
self.markup_history_search()
|
self.markup_history_search()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user