Files
cthulhu/internal/config/interruption_test.go

47 lines
1.7 KiB
Go

package config
import (
"path/filepath"
"reflect"
"testing"
"git.stormux.org/storm/cthulhu/internal/input"
)
func TestSpeechInterruptionPersistenceAndApplicationProfiles(t *testing.T) {
settings, err := Load(writeConfig(t, "schema-version = 2\nactive-profile = 'default'\n[profiles.default]\n"))
if err != nil || settings.SpeechInterruption.Mode != input.InterruptAllKeys {
t.Fatalf("omitted preference changed default: %+v, %v", settings.SpeechInterruption, err)
}
store, err := NewStore(filepath.Join(t.TempDir(), "settings.toml"))
if err != nil {
t.Fatal(err)
}
settings.SpeechInterruption = input.InterruptionSettings{Mode: input.InterruptCustomKeys, Keys: []string{"Tab", "Return", "Control_R"}}
if err := store.Save(settings); err != nil {
t.Fatal(err)
}
loaded, err := store.Load()
if err != nil || !reflect.DeepEqual(settings.SpeechInterruption, loaded.SpeechInterruption) {
t.Fatalf("saved keys = %+v, %v", loaded.SpeechInterruption, err)
}
application := cloneSettings(loaded)
application.SpeechInterruption.Mode = input.InterruptCommonKeys
if err := store.SaveForApplication("Editor", application); err != nil {
t.Fatal(err)
}
app, found, err := store.LoadForApplication("Editor")
if err != nil || !found || app.SpeechInterruption.Mode != input.InterruptCommonKeys {
t.Fatalf("application settings = %+v, %t, %v", app.SpeechInterruption, found, err)
}
global, err := store.Load()
if err != nil || global.SpeechInterruption.Mode != input.InterruptCustomKeys {
t.Fatalf("application altered global = %+v, %v", global.SpeechInterruption, err)
}
copy := cloneSettings(global)
copy.SpeechInterruption.Keys[0] = "Escape"
if global.SpeechInterruption.Keys[0] != "Tab" {
t.Fatal("settings snapshots share mutable keys")
}
}