All checks were successful
Run Test Suite / test (push) Successful in 42s
Updated lots of pieces with this, but it looks good.
87 lines
2.1 KiB
Go
87 lines
2.1 KiB
Go
package editor
|
|
|
|
import (
|
|
"regexp"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.gophernest.net/azpect/TextEditor/internal/core"
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
)
|
|
|
|
var ansiPattern = regexp.MustCompile(`\x1b\[[0-9;]*m`)
|
|
|
|
func stripANSI(s string) string {
|
|
return ansiPattern.ReplaceAllString(s, "")
|
|
}
|
|
|
|
func firstViewLine(view string) string {
|
|
lines := strings.Split(view, "\n")
|
|
if len(lines) == 0 {
|
|
return ""
|
|
}
|
|
return stripANSI(lines[0])
|
|
}
|
|
|
|
func TestHorizontalScrollRender(t *testing.T) {
|
|
line := "0123456789abcdef"
|
|
tm := newTestModelWithTermSize(t, []string{line}, core.Position{Line: 0, Col: 0}, 12, 10)
|
|
|
|
for range 10 {
|
|
sendKeys(tm, "l")
|
|
}
|
|
|
|
m := getFinalModel(t, tm)
|
|
if m.ActiveWindow().ScrollX != 4 {
|
|
t.Fatalf("ScrollX() = %d, want 4", m.ActiveWindow().ScrollX)
|
|
}
|
|
|
|
visible := firstViewLine(m.View())
|
|
if !strings.Contains(visible, "456789a") {
|
|
t.Fatalf("first visible line = %q, want it to contain %q", visible, "456789a")
|
|
}
|
|
}
|
|
|
|
func TestHorizontalScrollRenderReturnsWhenMovingLeft(t *testing.T) {
|
|
line := "0123456789abcdef"
|
|
tm := newTestModelWithTermSize(t, []string{line}, core.Position{Line: 0, Col: 0}, 12, 10)
|
|
|
|
for range 10 {
|
|
sendKeys(tm, "l")
|
|
}
|
|
for range 10 {
|
|
sendKeys(tm, "h")
|
|
}
|
|
|
|
m := getFinalModel(t, tm)
|
|
if m.ActiveWindow().ScrollX != 0 {
|
|
t.Fatalf("ScrollX() after moving back left = %d, want 0", m.ActiveWindow().ScrollX)
|
|
}
|
|
|
|
visible := firstViewLine(m.View())
|
|
if !strings.Contains(visible, "0123456") {
|
|
t.Fatalf("first visible line after moving back left = %q, want it to contain %q", visible, "0123456")
|
|
}
|
|
}
|
|
|
|
func TestHorizontalScrollResizeClampWithRunes(t *testing.T) {
|
|
line := "abécdefghij"
|
|
tm := newTestModelWithTermSize(t, []string{line}, core.Position{Line: 0, Col: 0}, 10, 10)
|
|
|
|
for range 10 {
|
|
sendKeys(tm, "l")
|
|
}
|
|
|
|
tm.Send(tea.WindowSizeMsg{Width: 12, Height: 10})
|
|
|
|
m := getFinalModel(t, tm)
|
|
if m.ActiveWindow().ScrollX != 5 {
|
|
t.Fatalf("ScrollX() after resize = %d, want 5", m.ActiveWindow().ScrollX)
|
|
}
|
|
|
|
visible := firstViewLine(m.View())
|
|
if !strings.Contains(visible, "efghij") {
|
|
t.Fatalf("first visible line after resize = %q, want it to contain %q", visible, "efghij")
|
|
}
|
|
}
|