43 lines
1.3 KiB
Go
43 lines
1.3 KiB
Go
// Copyright (c) 2026 Storm Dragon
|
|
// Authors: Storm Dragon, Angus Kola
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
package config
|
|
|
|
import (
|
|
"git.stormux.org/storm/cthulhu/internal/input"
|
|
"path/filepath"
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestKeyBindingsSaveLoadAndIsolation(t *testing.T) {
|
|
store, err := NewStore(filepath.Join(t.TempDir(), "settings.toml"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
settings := DefaultSettings()
|
|
settings.KeyBindings = []input.BindingOverride{
|
|
{Layout: input.DesktopKeyboardLayout, Scope: "global", Command: input.Preferences, Keys: []string{"Cthulhu+Ctrl+F8"}},
|
|
{Layout: input.LaptopKeyboardLayout, Scope: "browse", Command: input.DocumentNextHeading, Keys: []string{}},
|
|
}
|
|
if err := store.Save(settings); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
loaded, err := store.Load()
|
|
if err != nil || !reflect.DeepEqual(settings.KeyBindings, loaded.KeyBindings) {
|
|
t.Fatalf("round trip: %+v %v", loaded.KeyBindings, err)
|
|
}
|
|
loaded.KeyBindings[0].Keys[0] = "F1"
|
|
if store.Current().KeyBindings[0].Keys[0] == "F1" {
|
|
t.Fatal("caller changed store bindings")
|
|
}
|
|
settings.KeyBindings = nil
|
|
if err := store.Save(settings); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
loaded, err = store.Load()
|
|
if err != nil || len(loaded.KeyBindings) != 0 {
|
|
t.Fatalf("reset failed: %+v %v", loaded.KeyBindings, err)
|
|
}
|
|
}
|