1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
package config
import (
"os"
"path/filepath"
"testing"
)
func TestLoadSeeds(t *testing.T) {
dir := t.TempDir()
t.Setenv("XDG_CONFIG_HOME", dir)
cfg, err := Load()
if err != nil {
t.Fatal(err)
}
if cfg.DefaultVersion != "pl" || cfg.Offline {
t.Errorf("defaults wrong: %+v", cfg)
}
if cfg.Lectionary != "new" {
t.Errorf("lectionary default wrong: %+v", cfg)
}
if _, err := os.Stat(filepath.Join(dir, "lectio", "config.toml")); err != nil {
t.Error("config not seeded")
}
}
func TestLoadOverride(t *testing.T) {
dir := t.TempDir()
t.Setenv("XDG_CONFIG_HOME", dir)
os.MkdirAll(filepath.Join(dir, "lectio"), 0o755)
os.WriteFile(filepath.Join(dir, "lectio", "config.toml"),
[]byte("offline = true\ndefault_version = \"wuj\"\n"), 0o644)
cfg, _ := Load()
if !cfg.Offline || cfg.DefaultVersion != "wuj" {
t.Errorf("override not applied: %+v", cfg)
}
}
func TestWebDefaults(t *testing.T) {
def := Default()
if def.WebTheme != "transfiguration" {
t.Errorf("WebTheme default wrong: got %q, want %q", def.WebTheme, "transfiguration")
}
if def.WebPort != 0 {
t.Errorf("WebPort default wrong: got %d, want 0", def.WebPort)
}
}
func TestWebLoadsFromSeed(t *testing.T) {
dir := t.TempDir()
t.Setenv("XDG_CONFIG_HOME", dir)
cfg, err := Load()
if err != nil {
t.Fatal(err)
}
if cfg.WebTheme != "transfiguration" {
t.Errorf("WebTheme from seed wrong: got %q, want %q", cfg.WebTheme, "transfiguration")
}
if cfg.WebPort != 0 {
t.Errorf("WebPort from seed wrong: got %d, want 0", cfg.WebPort)
}
if cfg.WebDisplay != "horizontal" {
t.Errorf("WebDisplay from seed wrong: got %q, want %q", cfg.WebDisplay, "horizontal")
}
}
func TestWebDisplayDefault(t *testing.T) {
def := Default()
if def.WebDisplay != "horizontal" {
t.Errorf("WebDisplay default wrong: got %q, want %q", def.WebDisplay, "horizontal")
}
}
func TestWebDisplayLoadsSetting(t *testing.T) {
dir := t.TempDir()
t.Setenv("XDG_CONFIG_HOME", dir)
os.MkdirAll(filepath.Join(dir, "lectio"), 0o755)
os.WriteFile(filepath.Join(dir, "lectio", "config.toml"),
[]byte("web_display = \"vertical\"\n"), 0o644)
cfg, err := Load()
if err != nil {
t.Fatal(err)
}
if cfg.WebDisplay != "vertical" {
t.Errorf("WebDisplay = %q, want %q", cfg.WebDisplay, "vertical")
}
}
func TestWebDisplayNormalizesUnknown(t *testing.T) {
dir := t.TempDir()
t.Setenv("XDG_CONFIG_HOME", dir)
os.MkdirAll(filepath.Join(dir, "lectio"), 0o755)
os.WriteFile(filepath.Join(dir, "lectio", "config.toml"),
[]byte("web_display = \"bogus\"\n"), 0o644)
cfg, err := Load()
if err != nil {
t.Fatal(err)
}
if cfg.WebDisplay != "horizontal" {
t.Errorf("WebDisplay = %q, want %q (normalized from bogus)", cfg.WebDisplay, "horizontal")
}
}
func TestPartShown(t *testing.T) {
var empty Config
if !empty.PartShown("new", "psalm") {
t.Error("nil Parts: psalm should be shown")
}
if !empty.PartShown("new", "ewangelia") {
t.Error("nil Parts: ewangelia should be shown")
}
hidden := Config{Parts: map[string]map[string]bool{
"new": {"psalm": false},
}}
if hidden.PartShown("new", "psalm") {
t.Error("psalm explicitly false should be hidden")
}
if !hidden.PartShown("new", "ewangelia") {
t.Error("ewangelia not mentioned should still be shown")
}
}
|