Reset master to testing content
This commit is contained in:
1 parent
0f2587b719
commit
42afa2a56c
1483 files changed
+145308
-938069
No files matched your search
@@ -0,0 +1,86 @@
|
||||
// Copyright (c) 2026 Storm Dragon
|
||||
// Authors: Storm Dragon, Angus Kola
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestVoiceTypesPersistAndInheritAcrossApplications(t *testing.T) {
|
||||
settings := DefaultSettings()
|
||||
rate, pitch, gain := 62.0, 8.0, 4.0
|
||||
settings.DefaultVoice = Voice{Rate: &rate, AveragePitch: &pitch, Gain: &gain, Family: &VoiceFamily{Name: "Default person", Lang: "en"}}
|
||||
upper, link, system := 8.5, 3.0, 2.0
|
||||
settings.UppercaseVoice.AveragePitch = &upper
|
||||
settings.HyperlinkVoice.Rate = &link
|
||||
settings.SystemVoice.Gain = &system
|
||||
settings.Reading.IndentationPresentationMode = "both"
|
||||
store, err := NewStore(filepath.Join(t.TempDir(), "settings.toml"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := store.Save(settings); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
loaded, err := store.Load()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, kind := range []string{"uppercase", "hyperlink", "system"} {
|
||||
if !reflect.DeepEqual(EffectiveVoice(loaded, kind), EffectiveVoice(settings, kind)) {
|
||||
t.Fatalf("%s did not persist", kind)
|
||||
}
|
||||
}
|
||||
if loaded.Reading.IndentationPresentationMode != "both" {
|
||||
t.Fatal("indentation mode lost")
|
||||
}
|
||||
appSettings := loaded
|
||||
appPitch := 5.0
|
||||
appSettings.UppercaseVoice.AveragePitch = &appPitch
|
||||
if err := store.SaveForApplication("example-app", appSettings); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
application, found, err := store.LoadForApplication("example-app")
|
||||
if err != nil || !found || *EffectiveVoice(application, "uppercase").AveragePitch != 5 {
|
||||
t.Fatalf("application voice = %+v, %v", application.UppercaseVoice, err)
|
||||
}
|
||||
global, err := store.Load()
|
||||
if err != nil || *EffectiveVoice(global, "uppercase").AveragePitch != 8.5 {
|
||||
t.Fatal("application voice changed global voice")
|
||||
}
|
||||
*store.Current().UppercaseVoice.AveragePitch = 0
|
||||
if *store.Current().UppercaseVoice.AveragePitch != 8.5 {
|
||||
t.Fatal("voice snapshots alias")
|
||||
}
|
||||
appSettings.UppercaseVoice = Voice{}
|
||||
if err := store.SaveForApplication("example-app", appSettings); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
application, found, err = store.LoadForApplication("example-app")
|
||||
if err != nil || !found || application.UppercaseVoice.AveragePitch != nil || *EffectiveVoice(application, "uppercase").AveragePitch != 9 {
|
||||
t.Fatalf("application automatic pitch reset = %+v, %v", application.UppercaseVoice, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAutomaticUppercasePitchAndExplicitOverride(t *testing.T) {
|
||||
settings := DefaultSettings()
|
||||
for _, tc := range []struct{ normal, upper float64 }{{3, 7}, {5, 7}, {7, 9}, {8, 9}, {9, 9}} {
|
||||
settings.DefaultVoice.AveragePitch = &tc.normal
|
||||
if got := *EffectiveVoice(settings, "uppercase").AveragePitch; got != tc.upper {
|
||||
t.Fatalf("normal %g: uppercase %g, want %g", tc.normal, got, tc.upper)
|
||||
}
|
||||
}
|
||||
chosen := 6.0
|
||||
settings.UppercaseVoice.AveragePitch = &chosen
|
||||
if *EffectiveVoice(settings, "uppercase").AveragePitch != chosen {
|
||||
t.Fatal("explicit uppercase pitch ignored")
|
||||
}
|
||||
settings.Reading.IndentationPresentationMode = "invalid"
|
||||
if Validate(settings) == nil {
|
||||
t.Fatal("invalid indentation mode accepted")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user