gilo/editor/document/row_test.go
Timothy Warren 3e8a08e454
All checks were successful
timw4mail/gilo/pipeline/head This commit looks good
Fix broken tests
2023-10-03 17:12:51 -04:00

75 lines
1.3 KiB
Go

package document
import "testing"
var doc = NewDocument()
func TestNewRow(t *testing.T) {
str := "abcdefg"
row := newRow(doc, str)
got := string(row.chars)
want := str
if got != want {
t.Errorf("Row chars not equal to original string. Row: %q, String: %q", row.chars, str)
}
}
func TestRowSize(t *testing.T) {
str := "abcdefg"
row := newRow(doc, str)
got := row.Size()
want := 7
if got != want {
t.Errorf("Row size not equal to number of runes in original string")
}
}
func TestRenderSize(t *testing.T) {
str := "\tabcdefg"
row := newRow(doc, str)
row.update()
got := row.RenderSize()
want := 11
if got != want {
t.Errorf("Row rsize not equal to number of runes in original string")
}
}
type insertRune struct {
initial string
ch rune
at int
}
var insertRuneTests = []insertRune{
{"abde", 'c', 2},
{"bcde", 'a', 0},
{"abcd", 'e', 4},
{"abcd", 'e', 17},
{"abcd", 'e', -2},
}
func TestInsertRune(t *testing.T) {
for _, test := range insertRuneTests {
row := newRow(doc, test.initial)
row.insertRune(test.ch, test.at)
if row.Size() != 5 {
t.Errorf("Row size after inserting rune at index [%d] is %d, should be %d", test.at, row.Size(), 5)
}
got := row.toString()
want := "abcde"
if got != want {
t.Errorf("Row after update is '%s', should be '%s'", got, want)
}
}
}