@@ -1217,15 +1217,58 @@ func TestTerminalOnA11yTabDispose(t *testing.T) {
12171217
12181218func TestTerminalOnA11yChar (t * testing.T ) {
12191219 t .Parallel ()
1220- // OnA11yChar emitter exists and is subscribable, even if not yet fired
1221- // by the current implementation. Verify the accessor returns a valid Disposable.
1222- term := newTestTerminal (80 , 24 )
1220+ term := New (WithCols (80 ), WithRows (24 ), WithScrollback (1000 ), WithScreenReaderMode (true ))
1221+ var chars []string
1222+ term .OnA11yChar (func (ch string ) {
1223+ chars = append (chars , ch )
1224+ })
1225+
1226+ term .WriteString ("ABC" )
1227+
1228+ if len (chars ) != 3 {
1229+ t .Fatalf ("expected 3 OnA11yChar events, got %d" , len (chars ))
1230+ }
1231+ want := []string {"A" , "B" , "C" }
1232+ for i , w := range want {
1233+ if chars [i ] != w {
1234+ t .Errorf ("OnA11yChar[%d] = %q, want %q" , i , chars [i ], w )
1235+ }
1236+ }
1237+ }
1238+
1239+ func TestTerminalOnA11yCharDisabled (t * testing.T ) {
1240+ t .Parallel ()
1241+ // When ScreenReaderMode is off, OnA11yChar must not fire.
1242+ term := New (WithCols (80 ), WithRows (24 ), WithScrollback (1000 ))
1243+ count := 0
1244+ term .OnA11yChar (func (string ) { count ++ })
1245+
1246+ term .WriteString ("ABC" )
1247+
1248+ if count != 0 {
1249+ t .Errorf ("OnA11yChar fired %d times with ScreenReaderMode disabled, want 0" , count )
1250+ }
1251+ }
1252+
1253+ func TestTerminalOnA11yCharDispose (t * testing.T ) {
1254+ t .Parallel ()
1255+ term := New (WithCols (80 ), WithRows (24 ), WithScrollback (1000 ), WithScreenReaderMode (true ))
12231256 count := 0
12241257 d := term .OnA11yChar (func (string ) { count ++ })
12251258 if d == nil {
12261259 t .Fatal ("OnA11yChar returned nil Disposable" )
12271260 }
1261+
1262+ term .WriteString ("A" )
1263+ if count != 1 {
1264+ t .Fatalf ("expected 1 OnA11yChar event, got %d" , count )
1265+ }
1266+
12281267 d .Dispose ()
1268+ term .WriteString ("B" )
1269+ if count != 1 {
1270+ t .Errorf ("OnA11yChar fired after Dispose: count = %d, want 1" , count )
1271+ }
12291272}
12301273
12311274func TestTerminalOnRequestColorSchemeQuery (t * testing.T ) {
0 commit comments