-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview_test.go
159 lines (123 loc) · 3.94 KB
/
view_test.go
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package vimtea
import (
"strings"
"testing"
"github.com/charmbracelet/x/ansi"
"github.com/stretchr/testify/assert"
)
func TestViewRenderBasics(t *testing.T) {
editor := NewEditor(WithContent("Line 1\nLine 2\nLine 3\n"))
model := editor.(*editorModel)
// Set up viewport size
model.width = 40
model.height = 10
model.viewport.Width = 40
model.viewport.Height = 10
model.cursor = newCursor(3, 0)
// Render view
view := model.View()
// Basic content checks
assert.Contains(t, view, "Line 1", "View should contain 'Line 1'")
assert.Contains(t, view, "Line 2", "View should contain 'Line 2'")
assert.Contains(t, view, "Line 3", "View should contain 'Line 3'")
// Status line should be present
assert.Contains(t, strings.ToLower(view), "normal", "View should contain mode indicator 'NORMAL'")
}
func TestViewLineNumbers(t *testing.T) {
// Create editor with content
editor := NewEditor(
WithContent("Line A\nLine B\nLine C\nLine D\nLine E"),
)
model := editor.(*editorModel)
// Set up viewport size
model.width = 40
model.height = 10
model.viewport.Width = 40
model.viewport.Height = 10
// Render view
view := model.View()
// Check for line numbers
assert.True(t,
strings.Contains(view, "1") &&
strings.Contains(view, "2") &&
strings.Contains(view, "3"),
"View should contain line numbers when enabled")
// Test relative line numbers
model.relativeNumbers = true
model.cursor.Row = 2 // Set cursor to line 3
view = model.View()
lines := strings.Split(view, "\n")
lineNumber := string(strings.TrimSpace(ansi.Strip(lines[2]))[0])
// Check for relative line numbers (current line should be absolute)
assert.Equal(t, lineNumber, "3", "Current line should show absolute line number 3")
}
func TestViewCommandBuffer(t *testing.T) {
editor := NewEditor()
model := editor.(*editorModel)
// Set up command mode
model.mode = ModeCommand
model.commandBuffer = "test"
// Set up viewport
model.width = 40
model.height = 10
model.viewport.Width = 40
model.viewport.Height = 10
view := model.View()
// Command should be shown in status area
assert.Contains(t, view, ":test", "View should show command buffer in command mode")
}
func TestViewStatusMessages(t *testing.T) {
editor := NewEditor()
model := editor.(*editorModel)
// Set status message
model.statusMessage = "Test status message"
// Set up viewport
model.width = 40
model.height = 10
model.viewport.Width = 40
model.viewport.Height = 10
view := model.View()
// Status message should be displayed
assert.Contains(t, view, "Test status message", "View should show status message")
}
func TestViewSyntaxHighlighting(t *testing.T) {
// Create Go code
goCode := "package main\n\nfunc main() {\n\t// Comment\n\tfmt.Println(\"Hello\")\n}"
editor := NewEditor(
WithContent(goCode),
WithFileName("test.go"),
)
model := editor.(*editorModel)
// Set up viewport
model.width = 40
model.height = 10
model.viewport.Width = 40
model.viewport.Height = 10
view := model.View()
// Syntax highlighting should add ANSI codes
assert.Contains(t, view, "\033[", "View should contain ANSI codes for syntax highlighting")
}
func TestViewLongContent(t *testing.T) {
// Create content with many lines
var content strings.Builder
for i := 1; i <= 100; i++ {
content.WriteString("Line ")
content.WriteString(string(rune('0' + i%10)))
content.WriteString("\n")
}
editor := NewEditor(WithContent(content.String()))
model := editor.(*editorModel)
// Set up viewport with limited height
model.width = 40
model.height = 10
model.viewport.Width = 40
model.viewport.Height = 10
// Position cursor far down
model.cursor = newCursor(50, 0)
model.ensureCursorVisible()
view := model.View()
// View should contain content near cursor position
assert.Contains(t, view, "Line 0", "View should contain visible content near cursor")
// First lines should not be visible
assert.NotContains(t, view, "Line 1\nLine 2", "View should not contain content from beginning when scrolled down")
}