Files
fenrir/internal/app/spellcheck_test.go

36 lines
1.1 KiB
Go

// Copyright (c) 2026 Storm Dragon
// SPDX-License-Identifier: GPL-3.0-or-later
package app
import (
"git.stormux.org/storm/fenrir/internal/config"
"git.stormux.org/storm/fenrir/internal/presentation"
"reflect"
"testing"
)
func TestMisspellingFeedbackIndependentChoicesAndSoundFallback(t *testing.T) {
for choices := range 8 {
for _, soundAvailable := range []bool{false, true} {
settings := config.Defaults().Reading
settings.SpellcheckReadWord = choices&1 != 0
settings.SpellcheckSayMisspelled = choices&2 != 0
settings.SpellcheckSound = choices&4 != 0
voice := &fakeVoice{}
var cues []presentation.Cue
present_misspelling("helo", settings, voice, func(cue presentation.Cue) bool { cues = append(cues, cue); return soundAvailable })
var want []string
if settings.SpellcheckReadWord {
want = append(want, "helo")
}
if settings.SpellcheckSayMisspelled || settings.SpellcheckSound && !soundAvailable {
want = append(want, "misspelled")
}
if !reflect.DeepEqual(voice.messages, want) || (len(cues) == 1) != settings.SpellcheckSound {
t.Fatal(choices, soundAvailable, voice.messages, cues)
}
}
}
}