36 lines
861 B
Go
36 lines
861 B
Go
package braille
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestLineComposesFocusedRegionWithoutChangingSpacing(t *testing.T) {
|
|
line := Line{Regions: []Region{
|
|
{Text: "Context "},
|
|
{Text: "é界", Cursor: 1},
|
|
{Text: " entry"},
|
|
}, Focus: 1}
|
|
frame, err := line.Frame()
|
|
if err != nil || !reflect.DeepEqual(frame, Frame{Text: "Context é界 entry", Cursor: 9}) {
|
|
t.Fatalf("frame=%+v err=%v", frame, err)
|
|
}
|
|
line.Focus = -1
|
|
frame, err = line.Frame()
|
|
if err != nil || frame.Cursor != -1 {
|
|
t.Fatalf("unfocused frame=%+v err=%v", frame, err)
|
|
}
|
|
}
|
|
|
|
func TestLineRejectsInvalidFocusAndCursor(t *testing.T) {
|
|
for _, line := range []Line{
|
|
{Focus: 0},
|
|
{Regions: []Region{{Text: "x"}}, Focus: -2},
|
|
{Regions: []Region{{Text: "x", Cursor: 2}}, Focus: 0},
|
|
} {
|
|
if _, err := line.Frame(); err == nil {
|
|
t.Fatalf("accepted invalid line %+v", line)
|
|
}
|
|
}
|
|
}
|