24 lines
697 B
Go
24 lines
697 B
Go
package ocr
|
|
|
|
import "testing"
|
|
|
|
func TestCursorReadAllAndRoutingOffsets(t *testing.T) {
|
|
cursor := NewCursor(Result{Text: "é one\n\n猫 two"})
|
|
if _, ok := cursor.Set(2); !ok {
|
|
t.Fatal("valid rune offset rejected")
|
|
}
|
|
lines := cursor.LinesFrom()
|
|
if len(lines) != 2 || lines[0].Text != "one" || lines[0].Offset != 2 || lines[1].Text != "猫 two" || lines[1].Offset != 7 {
|
|
t.Fatalf("lines from cursor: %+v", lines)
|
|
}
|
|
if _, ok := cursor.Set(-1); ok {
|
|
t.Fatal("negative route accepted")
|
|
}
|
|
if _, ok := cursor.Set(cursor.Length() + 1); ok {
|
|
t.Fatal("out of range route accepted")
|
|
}
|
|
if got, ok := cursor.Slice(0, 1); !ok || got != "é" {
|
|
t.Fatalf("rune selection: %q %t", got, ok)
|
|
}
|
|
}
|