Files
kitty/tools/tui/readline/actions_test.go
2022-11-14 15:42:04 +05:30

42 lines
1014 B
Go

// License: GPLv3 Copyright: 2022, Kovid Goyal, <kovid at kovidgoyal.net>
package readline
import (
"fmt"
"kitty/tools/tui/loop"
"testing"
)
var _ = fmt.Print
func TestAddText(t *testing.T) {
lp, _ := loop.New()
dt := func(initial string, prepare func(rl *Readline), expected ...string) {
rl := New(lp, RlInit{})
rl.add_text(initial)
if prepare != nil {
prepare(rl)
}
if len(expected) > 0 {
if expected[0] != rl.text_upto_cursor_pos() {
t.Fatalf("Text upto cursor pos not as expected for: %#v\n%#v != %#v", initial, expected[0], rl.text_upto_cursor_pos())
}
}
if len(expected) > 1 {
if expected[1] != rl.text_after_cursor_pos() {
t.Fatalf("Text after cursor pos not as expected for: %#v\n%#v != %#v", initial, expected[1], rl.text_after_cursor_pos())
}
}
if len(expected) > 2 {
if expected[2] != rl.all_text() {
t.Fatalf("Text not as expected for: %#v\n%#v != %#v", initial, expected[2], rl.all_text())
}
}
}
dt("test", nil, "test", "", "test")
}