remote.braille requests and events carry a typed op under a braille-stream lease: the controller's width and gestures for a controlled reader, rendered cells back to its child, and cells, local geometry and display gestures for a controller. Direction is validated per role; a full mailbox revokes the lease. No display owner is attached yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
45 lines
1.7 KiB
Go
45 lines
1.7 KiB
Go
// Copyright (c) 2026 Storm Dragon
|
|
// Authors: Storm Dragon, Angus Kola
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package tentaclewire
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
func TestRemoteBrailleDirections(t *testing.T) {
|
|
size := RemoteBraille{Op: "size", Width: 40}
|
|
route := RemoteBraille{Op: "gesture", Gesture: "route", Index: 3}
|
|
cells := RemoteBraille{Op: "cells", Cells: []int{0, 255}}
|
|
query := RemoteBraille{Op: "geometry"}
|
|
answer := RemoteBraille{Op: "geometry", Width: 32}
|
|
for _, test := range []struct {
|
|
role string
|
|
request bool
|
|
value RemoteBraille
|
|
want bool
|
|
}{
|
|
{"controlled", true, size, true}, {"controlled", true, route, true}, {"controlled", true, cells, false},
|
|
{"controlled", false, cells, true}, {"controlled", false, route, false},
|
|
{"controller", true, cells, true}, {"controller", true, query, true}, {"controller", true, answer, false},
|
|
{"controller", true, size, false}, {"controller", false, route, true}, {"controller", false, answer, true},
|
|
{"controller", false, cells, false}, {"observer", true, size, false},
|
|
} {
|
|
if got := ValidRemoteBrailleFor(test.role, test.request, test.value); got != test.want {
|
|
t.Fatalf("%s request=%t %+v = %t", test.role, test.request, test.value, got)
|
|
}
|
|
}
|
|
for _, raw := range []string{
|
|
`{"op":"cells","cells":[]}`, `{"op":"cells","cells":[-1]}`, `{"op":"size","width":4097}`,
|
|
`{"op":"gesture","gesture":"route","index":4096}`, `{"op":"gesture","gesture":"script"}`,
|
|
`{"op":"gesture","gesture":"pan-left","index":1}`, `{"width":3}`, `{"op":"size","width":3,"text":"x"}`,
|
|
} {
|
|
var value RemoteBraille
|
|
if json.Unmarshal([]byte(raw), &value) == nil {
|
|
t.Fatal("invalid Braille decoded", raw)
|
|
}
|
|
}
|
|
}
|