Cthulhu is no longer a fork. Now it is a screen reader written in Golang.
This commit is contained in:
1 parent
a998fe67de
commit
069fc674dc
708 files changed
+112482
-532
No files matched your search
@@ -0,0 +1,52 @@
|
||||
// Copyright (c) 2026 Storm Dragon
|
||||
// Authors: Storm Dragon, Angus Kola
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestClipboardWorkerAnnouncesContentAndAccessError(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
read func(context.Context) (string, error)
|
||||
wantText string
|
||||
}{
|
||||
{"text", func(context.Context) (string, error) {
|
||||
return "Text in clipboard sample", nil
|
||||
}, "Text in clipboard sample"},
|
||||
{"error", func(context.Context) (string, error) {
|
||||
return "", errors.New("unavailable")
|
||||
}, "Error accessing clipboard"},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
requests := make(chan struct{}, 1)
|
||||
speech := &fakeSpeechQueue{spoken: make(chan string, 1), interrupt: make(chan struct{}, 1)}
|
||||
done := runClipboardWorker(ctx, requests, speech, test.read)
|
||||
requests <- struct{}{}
|
||||
select {
|
||||
case got := <-speech.spoken:
|
||||
if got != test.wantText {
|
||||
t.Fatalf("speech = %q, want %q", got, test.wantText)
|
||||
}
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("clipboard announcement missing")
|
||||
}
|
||||
if len(speech.interrupt) != 1 {
|
||||
t.Fatal("clipboard announcement did not interrupt prior speech")
|
||||
}
|
||||
cancel()
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("clipboard worker did not stop")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user