-
-
Notifications
You must be signed in to change notification settings - Fork 476
Expand file tree
/
Copy pathvim_test.go
More file actions
113 lines (81 loc) · 3.47 KB
/
vim_test.go
File metadata and controls
113 lines (81 loc) · 3.47 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package main
import (
"testing"
"time"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/x/exp/teatest"
"github.com/muesli/termenv"
)
func init() {
lipgloss.SetColorProfile(termenv.ANSI)
}
func TestGotoLine(t *testing.T) {
tm := prepare(t, options{showLineNumbers: true})
tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune(":")})
tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("5")})
tm.Send(tea.KeyMsg{Type: tea.KeyEnter})
teatest.RequireEqualOutput(t, read(t, tm))
tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("q")})
tm.WaitFinished(t, teatest.WithFinalTimeout(time.Second))
}
func TestGotoLineCollapsed(t *testing.T) {
tm := prepare(t, options{showLineNumbers: true})
tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("E")})
tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune(":")})
tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("5")})
tm.Send(tea.KeyMsg{Type: tea.KeyEnter})
teatest.RequireEqualOutput(t, read(t, tm))
tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("q")})
tm.WaitFinished(t, teatest.WithFinalTimeout(time.Second))
}
func TestGotoLineInputInvalid(t *testing.T) {
tm := prepare(t, options{showLineNumbers: true})
tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("E")})
tm.Send(tea.KeyMsg{Type: tea.KeyDown})
tm.Send(tea.KeyMsg{Type: tea.KeyDown})
tm.Send(tea.KeyMsg{Type: tea.KeyDown})
tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune(":")})
tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("invalid")})
tm.Send(tea.KeyMsg{Type: tea.KeyEnter})
teatest.RequireEqualOutput(t, read(t, tm))
tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("q")})
tm.WaitFinished(t, teatest.WithFinalTimeout(time.Second))
}
func TestGotoLineInputGreaterThanTotalLines(t *testing.T) {
tm := prepare(t, options{showLineNumbers: true})
tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune(":")})
tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("500")})
tm.Send(tea.KeyMsg{Type: tea.KeyEnter})
teatest.RequireEqualOutput(t, read(t, tm))
tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("q")})
tm.WaitFinished(t, teatest.WithFinalTimeout(time.Second))
}
func TestGotoLineInputLessThanOne(t *testing.T) {
tm := prepare(t, options{showLineNumbers: true})
tm.Send(tea.KeyMsg{Type: tea.KeyDown})
tm.Send(tea.KeyMsg{Type: tea.KeyDown})
tm.Send(tea.KeyMsg{Type: tea.KeyDown})
tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune(":")})
tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("-2")})
tm.Send(tea.KeyMsg{Type: tea.KeyEnter})
teatest.RequireEqualOutput(t, read(t, tm))
tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("q")})
tm.WaitFinished(t, teatest.WithFinalTimeout(time.Second))
}
func TestGotoLineKeepsHistory(t *testing.T) {
tm := prepare(t, options{showLineNumbers: true})
tm.Send(tea.KeyMsg{Type: tea.KeyDown})
tm.Send(tea.KeyMsg{Type: tea.KeyDown})
tm.Send(tea.KeyMsg{Type: tea.KeyDown})
tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune(":")})
tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("4")})
tm.Send(tea.KeyMsg{Type: tea.KeyEnter})
tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune(":")})
tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("14")})
tm.Send(tea.KeyMsg{Type: tea.KeyEnter})
tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("[")})
teatest.RequireEqualOutput(t, read(t, tm))
tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("q")})
tm.WaitFinished(t, teatest.WithFinalTimeout(time.Second))
}