Files
cthulhu/internal/config/text_preferences_test.go

38 lines
1.5 KiB
Go

package config
import (
"path/filepath"
"reflect"
"testing"
)
func TestTextPreferencesPersistAndInheritByApplication(t *testing.T) {
store, err := NewStore(filepath.Join(t.TempDir(), "settings.toml"))
if err != nil {
t.Fatal(err)
}
global := DefaultSettings()
global.Pronunciations = []PronunciationEntry{{Word: "SQL", Replacement: "sequel"}}
global.TextAttributes.Choices[0].Speak = false
global.TextAttributes.Choices[0].Braille = true
global.TextAttributes.Indicator = 0x40
if err := store.Save(global); err != nil {
t.Fatal(err)
}
loaded, err := store.Load()
if err != nil || !reflect.DeepEqual(loaded.Pronunciations, global.Pronunciations) || !reflect.DeepEqual(loaded.TextAttributes, global.TextAttributes) {
t.Fatalf("loaded preferences = %+v, %+v, %v", loaded.Pronunciations, loaded.TextAttributes, err)
}
app := cloneSettings(global)
app.Pronunciations = []PronunciationEntry{{Word: "SQL", Replacement: "S Q L"}}
app.TextAttributes.Choices[0], app.TextAttributes.Choices[1] = app.TextAttributes.Choices[1], app.TextAttributes.Choices[0]
app.TextAttributes.Indicator = 0xc0
if err := store.SaveForApplication("Editor", app); err != nil {
t.Fatal(err)
}
actual, found, err := store.LoadForApplication("Editor")
if err != nil || !found || !reflect.DeepEqual(actual.Pronunciations, app.Pronunciations) || !reflect.DeepEqual(actual.TextAttributes, app.TextAttributes) {
t.Fatalf("application preferences = %+v, %+v, %t, %v", actual.Pronunciations, actual.TextAttributes, found, err)
}
}