Files
bbs/internal/textui/fsbuffer_test.go
T
Claude 094ad0561f Add a full-screen editor for ANSI terminals
Posts and mail on an ANSI terminal (40x12 or more, not a VT52 or a
Commodore) are written on the whole screen: the cursor and editing keys
(Term.EditKey reads them now, where other prompts still drop them),
words wrapping as typed, Backspace and Delete joining lines, ^Y
deleting one, ^Z (or /S on a line) saving, ^X giving up.  A reply's
quote is no longer put in the body to cut: ^Q opens a window of the
message replied to, and Enter takes a line from it.  Messages from
other nodes wait until the editor is left.

view.Draft gains Quote; the line editor and the 3270's editor begin the
body with it, as before.  The profile switches between the full-screen
and line editors (kept as the editor setting).

The editor's text is its own type, tested by itself; an SSH caller
posts, replies quoting and switches editors.  Writing-Messages is the
wiki page for the editors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AFQhReUqUc7F5srk2hViqr
2026-10-12 14:18:08 +00:00

92 lines
2.1 KiB
Go

package textui
import (
"reflect"
"testing"
)
func typeIn(b *fsBuffer, s string) {
for _, r := range s {
if r == '\r' {
b.Enter()
} else {
b.Insert(r)
}
}
}
func TestBufferWrap(t *testing.T) {
b := newBuffer(nil, 10, 100)
typeIn(b, "the quick brown fox")
if got := b.Text(); !reflect.DeepEqual(got, []string{"the quick", "brown fox"}) {
t.Errorf("wrapped %q", got)
}
if b.row != 1 || b.col != 9 {
t.Errorf("cursor %d,%d", b.row, b.col)
}
// one long word breaks where it must
b = newBuffer(nil, 5, 100)
typeIn(b, "abcdefgh")
if got := b.Text(); !reflect.DeepEqual(got, []string{"abcde", "fgh"}) {
t.Errorf("long word %q", got)
}
// a body given is wrapped too
b = newBuffer([]string{"one two three"}, 8, 100)
if got := b.Text(); !reflect.DeepEqual(got, []string{"one two", "three"}) {
t.Errorf("body %q", got)
}
}
func TestBufferEditing(t *testing.T) {
b := newBuffer(nil, 20, 100)
typeIn(b, "hello\rworld")
b.Move(KeyHome, 0)
b.Backspace() // joins
if got := b.Text(); !reflect.DeepEqual(got, []string{"helloworld"}) || b.col != 5 {
t.Errorf("joined %q at %d", got, b.col)
}
b.Insert(' ')
b.Move(KeyEnd, 0)
b.Enter()
typeIn(b, "x")
b.Move(KeyUp, 0)
b.Move(KeyEnd, 0)
b.Delete() // joins the next line on
if got := b.Text(); !reflect.DeepEqual(got, []string{"hello worldx"}) {
t.Errorf("deleted %q", got)
}
b.KillLine()
if got := b.Text(); len(got) != 0 {
t.Errorf("killed %q", got)
}
// moving past line ends
b = newBuffer([]string{"ab", "cd"}, 20, 100)
b.Move(KeyEnd, 0)
b.Move(KeyRight, 0)
if b.row != 1 || b.col != 0 {
t.Errorf("right %d,%d", b.row, b.col)
}
b.Move(KeyLeft, 0)
if b.row != 0 || b.col != 2 {
t.Errorf("left %d,%d", b.row, b.col)
}
}
func TestBufferQuoteAndLimit(t *testing.T) {
b := newBuffer(nil, 20, 4)
if n := b.InsertLines([]string{"> one", "> two"}); n != 2 {
t.Errorf("quoted %d", n)
}
typeIn(b, "mine")
if got := b.Text(); !reflect.DeepEqual(got, []string{"> one", "> two", "mine"}) {
t.Errorf("quoted %q", got)
}
b.Enter()
if b.Enter() {
t.Error("a fifth line")
}
if n := b.InsertLines([]string{"> three"}); n != 0 {
t.Errorf("quoted past the limit: %d", n)
}
}