After commit c018f5fd29 Fenrir is being switched over to go. If you do not want to be part of the testing process, please switch to master.

This commit is contained in:
Storm Dragon committed 2026-10-27 20:30:55 -04:00
1 parent c018f5fd29
commit 0e50de4c76
1047 files changed
+58364 -63747

No files matched your search

+111
View File
@@ -0,0 +1,111 @@
// Fenrir console screen reader.
// Copyright (c) 2026 Storm Dragon
// SPDX-License-Identifier: GPL-3.0-or-later
package punctuation
import (
"os"
"path/filepath"
"strings"
"testing"
)
func TestShippedProfilesAndLevels(t *testing.T) {
paths, err := filepath.Glob("../../config/punctuation/*.toml")
if err != nil || len(paths) != 7 {
t.Fatal(paths, err)
}
for _, path := range paths {
processor, _, err := Load([]string{path})
if err != nil {
t.Fatal(path, err)
}
for _, level := range Levels() {
if _, exists := processor.levels[level]; !exists {
t.Fatal(path, level)
}
}
if processor.Character('.') == "." {
t.Fatal("missing character name", path)
}
}
}
func TestTextLevelsPreservePausesAndDoNotReprocessNames(t *testing.T) {
processor, _, err := Load([]string{"../../config/punctuation/default.toml"})
if err != nil {
t.Fatal(err)
}
for _, testCase := range []struct{ level, input, want string }{
{"none", "don't 3.14 [X]mute a_b", "don't 3.14 X mute a b"},
{"some", "a/b#c!", "a slash b hash c!"},
{"most", "a,b!", "a comma, b bang! "},
{"all", "?", " question?? "},
{"all", "a b", "a space b"},
{"some", "é→Ω", "é→Ω"},
} {
if got := processor.Text(testCase.input, testCase.level); got != testCase.want {
t.Errorf("%s %q: %q, want %q", testCase.level, testCase.input, got, testCase.want)
}
}
if got := processor.Character('?'); got != "question?" {
t.Fatal(got)
}
if got := processor.Character('E'); got != "E" {
t.Fatal(got)
}
}
func TestCustomNamesAndInvalidProfiles(t *testing.T) {
data, err := os.ReadFile("../../config/punctuation/default.toml")
if err != nil {
t.Fatal(err)
}
custom := strings.Replace(string(data), `"/" = "slash"`, `"/" = "path/separator"`, 1)
processor, err := Decode([]byte(custom))
if err != nil {
t.Fatal(err)
}
if got := processor.Text("a/b", "some"); got != "a path/separator b" {
t.Fatal("recursive replacement", got)
}
for _, invalid := range []string{
strings.Replace(string(data), "version = 1", "version = 99", 1),
strings.Replace(string(data), `"none" = ""`, `"none" = "/"`, 1),
strings.Replace(string(data), `"/" = "slash"`, `"//" = "slash"`, 1),
strings.Replace(string(data), `"/" = "slash"`, `"/" = ""`, 1),
string(data) + "\n[unknown]\nkey = 1\n",
} {
if _, err := Decode([]byte(invalid)); err == nil {
t.Fatal("accepted malformed profile", invalid)
}
}
}
func TestProfileSelectionAndInvalidShadow(t *testing.T) {
home := t.TempDir()
paths, err := Paths("default", home, 1000, "bundle")
if err != nil || len(paths) != 3 || !strings.HasPrefix(paths[0], home) || paths[2] != filepath.Join("bundle", "default.toml") {
t.Fatal(paths, err)
}
paths, err = Paths("default.toml", home, 0, "bundle")
if err != nil || len(paths) != 2 || strings.HasPrefix(paths[0], home) {
t.Fatal(paths, err)
}
for _, name := range []string{"", ".", "..", "old.conf", "dir/profile", "\x00"} {
if _, err := Paths(name, home, 0, "bundle"); err == nil {
t.Fatal("accepted invalid selection", name)
}
}
shadow := filepath.Join(home, "bad.toml")
if err := os.WriteFile(shadow, []byte("not TOML"), 0600); err != nil {
t.Fatal(err)
}
if _, selected, err := Load([]string{shadow, "../../config/punctuation/default.toml"}); err == nil || selected != shadow {
t.Fatal("invalid shadow was skipped", selected, err)
}
if _, _, err := Load([]string{filepath.Join(home, "missing.toml"), "../../config/punctuation/default.toml"}); err != nil {
t.Fatal(err)
}
}