//go:build brlapi && cgo package braille import "testing" func TestContractedWordWrapAndPartialSelection(t *testing.T) { v := viewport{width: 4} if err := v.setFrame(Frame{Text: "the cat", Cursor: -1, Contract: true, Table: "en-us-g2.ctb", WordWrap: true, Dots: []byte{0, 0x40, 0, 0, 0, 0, 0}}); err != nil { t.Fatal(err) } if v.frame() != "⠮⠀ " || v.displayDots()[0] != 0x40 { t.Fatalf("wrapped contraction=%q dots=%v", v.frame(), v.displayDots()) } if _, ok := v.route(RouteBase + 2); ok { t.Fatal("padding cell was routed into undisplayed text") } if !v.pan(PanRight) || v.frame() != "⠉⠁⠞ " || v.offset != 2 { t.Fatalf("panned word=%q offset=%d", v.frame(), v.offset) } if !v.pan(PanLeft) || v.offset != 0 { t.Fatal("wrapped pan left did not restore its page") } } func TestContractionMapsCursorAndRouting(t *testing.T) { for _, cursor := range []int{-1, 0, 4, len([]rune("the cat"))} { v := viewport{width: 4} if err := v.setFrame(Frame{ID: 7, Text: "the cat", Cursor: cursor, Contract: true, Table: "en-us-g2.ctb"}); err != nil { t.Fatal(err) } if cursor == -1 && (string(v.text) != "⠮⠀⠉⠁⠞" || v.inputPositions[0] != 0 || v.inputPositions[1] != 3) { t.Fatalf("unexpected translation %q, positions %v", string(v.text), v.inputPositions) } if cursor == -1 { if event, ok := v.route(RouteBase + 1); !ok || event != (RoutingEvent{ID: 7, Offset: 3}) { t.Fatalf("contracted route = %+v, %v", event, ok) } if !v.pan(PanRight) { t.Fatal("contracted line did not pan") } if event, ok := v.route(RouteBase); !ok || event != (RoutingEvent{ID: 7, Offset: 6}) { t.Fatalf("panned contracted route = %+v, %v", event, ok) } } if len(v.text) >= len([]rune("the cat")) && cursor < 0 { t.Fatalf("text was not contracted: %q", string(v.text)) } for cell, original := range v.inputPositions { if original < 0 || original > len([]rune("the cat")) { t.Fatalf("cell %d has invalid source offset %d", cell, original) } } if cursor == len([]rune("the cat")) && v.cursor != len(v.text)-1 { t.Fatalf("end cursor %d, text %q", v.cursor, string(v.text)) } } if _, _, _, err := translate("the", "missing-table.ctb", -1, false); err == nil { t.Fatal("missing table accepted") } plain, _, _, err := translate("the cat", "en-us-g2.ctb", 0, false) if err != nil { t.Fatal(err) } expanded, _, _, err := translate("the cat", "en-us-g2.ctb", 0, true) if err != nil { t.Fatal(err) } if plain == expanded { t.Fatalf("computer braille at cursor did not expand word: %q", expanded) } }