-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathinline_accept_test.go
More file actions
72 lines (57 loc) · 2.03 KB
/
Copy pathinline_accept_test.go
File metadata and controls
72 lines (57 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package readline
import "testing"
// setLine replaces the shell's line buffer and puts the cursor at its end.
func setLine(rl *Shell, s string) {
rl.line.Set([]rune(s)...)
rl.cursor.Set(rl.line.Len())
}
func TestInlineSuggestAcceptFull(t *testing.T) {
rl := NewShell()
setLine(rl, "sta")
rl.SetInlineSuggestion("status --verbose")
rl.inlineSuggestAccept()
if got := string(*rl.line); got != "status --verbose" {
t.Fatalf("line after accept = %q, want %q", got, "status --verbose")
}
if got := rl.GetInlineSuggestion(); got != "" {
t.Fatalf("inline suggestion after accept = %q, want cleared", got)
}
}
func TestInlineSuggestAcceptWord(t *testing.T) {
rl := NewShell()
setLine(rl, "sta")
rl.SetInlineSuggestion("status --verbose")
rl.inlineSuggestAcceptWord()
if got := string(*rl.line); got != "status" {
t.Fatalf("line after word accept = %q, want %q", got, "status")
}
// Suggestion still extends the line, so it must not be cleared.
if got := rl.GetInlineSuggestion(); got != "status --verbose" {
t.Fatalf("inline suggestion after word accept = %q, want unchanged", got)
}
// A second word-accept consumes the remainder and clears the suggestion.
rl.inlineSuggestAcceptWord()
if got := string(*rl.line); got != "status --verbose" {
t.Fatalf("line after second word accept = %q, want %q", got, "status --verbose")
}
if got := rl.GetInlineSuggestion(); got != "" {
t.Fatalf("inline suggestion after full consumption = %q, want cleared", got)
}
}
func TestInlineSuggestAcceptNotApplicable(t *testing.T) {
rl := NewShell()
setLine(rl, "xyz") // suggestion does not extend the current line
rl.SetInlineSuggestion("status")
rl.inlineSuggestAccept()
if got := string(*rl.line); got != "xyz" {
t.Fatalf("line = %q, want unchanged %q", got, "xyz")
}
// Cursor not at end of line: must not accept.
setLine(rl, "sta")
rl.cursor.Set(1)
rl.SetInlineSuggestion("status")
rl.inlineSuggestAccept()
if got := string(*rl.line); got != "sta" {
t.Fatalf("line = %q, want unchanged %q (cursor not at end)", got, "sta")
}
}