63 lines
2.5 KiB
Go
63 lines
2.5 KiB
Go
// Copyright (c) 2026 Storm Dragon
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package app
|
|
|
|
import (
|
|
"context"
|
|
"reflect"
|
|
"testing"
|
|
|
|
"git.stormux.org/storm/fenrir/internal/command"
|
|
"git.stormux.org/storm/fenrir/internal/config"
|
|
"git.stormux.org/storm/fenrir/internal/input"
|
|
"git.stormux.org/storm/fenrir/internal/presentation"
|
|
"git.stormux.org/storm/fenrir/internal/screen"
|
|
)
|
|
|
|
func TestAdditionalReviewDispatchAndBlankCursorAnnouncement(t *testing.T) {
|
|
for _, soundsEnabled := range []bool{false, true} {
|
|
for _, trial := range []struct {
|
|
id command.ID
|
|
x int
|
|
text string
|
|
want []string
|
|
cue presentation.Cue
|
|
}{
|
|
{command.CursorLine, 2, "alphaomega", []string{"1", " text cursor line number"}, ""},
|
|
{command.CursorColumn, 2, "alphaomega", []string{"3", " text cursor column number"}, ""},
|
|
{command.LineToCursor, 2, "alphaomega", []string{"al", " text cursor "}, ""},
|
|
{command.LineFromCursor, 2, "alphaomega", []string{"pha", " text cursor "}, ""},
|
|
{command.LineToCursor, 0, "alphaomega", []string{"blank", " text cursor "}, presentation.Blank},
|
|
{command.LineFromCursor, 0, "blankomega", []string{"blank", " text cursor "}, ""},
|
|
{command.ScreenFirstChar, 2, "alphaomega", []string{"a first character in screen"}, ""},
|
|
{command.ScreenLastChar, 2, "alphaomega", []string{"a last character in screen"}, ""},
|
|
} {
|
|
t.Run(string(trial.id), func(t *testing.T) {
|
|
source := &fakeSource{snapshot: screen.Snapshot{Terminal: 2, Active: true, Rows: 2, Cols: 5, X: trial.x, Cells: []rune(trial.text)}}
|
|
voice, sounds := &fakeVoice{}, &fakeSounds{}
|
|
keys := &fakeKeys{poll: func(_ bool, handle func(input.Decision)) error {
|
|
voice.messages, sounds.cues = nil, nil
|
|
handle(input.Decision{Command: trial.id, Interrupt: true})
|
|
handle(input.Decision{Command: command.Quit})
|
|
return nil
|
|
}}
|
|
settings := config.Defaults()
|
|
settings.Presentation.Sound.Enabled = soundsEnabled
|
|
if err := run(context.Background(), source, keys, voice, nil, RunOptions{Settings: settings, Sounds: sounds}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
want := trial.want
|
|
var wantCues []presentation.Cue
|
|
if soundsEnabled && trial.cue != "" {
|
|
want = want[1:]
|
|
wantCues = []presentation.Cue{trial.cue}
|
|
}
|
|
if !reflect.DeepEqual(voice.messages, want) || !reflect.DeepEqual(sounds.cues, wantCues) || voice.interrupts != 1 {
|
|
t.Fatalf("speech=%q cues=%v interrupts=%d; want speech=%q cues=%v", voice.messages, sounds.cues, voice.interrupts, want, wantCues)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
}
|