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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
package web
import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/lukaszkasprzak/lectio/internal/liturgy"
)
func TestRenderReadings(t *testing.T) {
secs := []liturgy.Section{{Heading: "Ewangelia (J 20, 1. 11-18)", PartID: "ewangelia"}}
html := string(RenderReadings(secs, []string{"wuj"}, "new", "horizontal", "pl"))
if !strings.Contains(html, "Ewangelia") || !strings.Contains(html, "class=") {
t.Errorf("reading pane missing heading/classes: %q", html[:min(200, len(html))])
}
}
func TestBuiltinThemes(t *testing.T) {
t.Setenv("XDG_CONFIG_HOME", t.TempDir()) // no user themes
for _, name := range []string{
"transfiguration", "desert_fathers", "benedictines", "franciscans",
"memento_mori", "dominicans", "advent", "nativity", "lent",
"easter", "pentecost", "ordinary", "epiphany", "marian",
} {
if b, err := themeCSS(name); err != nil || len(b) == 0 {
t.Errorf("built-in theme %s not embedded: %v", name, err)
}
}
}
func TestThemeCSSGuardRejectsInvalidNames(t *testing.T) {
t.Setenv("XDG_CONFIG_HOME", t.TempDir()) // no user themes
for _, name := range []string{"../../etc/passwd", "..", "a/b", ""} {
if _, err := themeCSS(name); err == nil {
t.Errorf("themeCSS(%q): expected error, got nil", name)
}
}
}
func TestRenderReadingsEscapesScriptText(t *testing.T) {
secs := []liturgy.Section{{
Heading: "Test",
PartID: "pierwsze_czytanie",
Paragraphs: [][]string{{"<script>alert(1)</script>"}},
}}
html := string(RenderReadings(secs, []string{"pl"}, "new", "horizontal", "pl"))
if strings.Contains(html, "<script>alert(1)</script>") {
t.Errorf("raw <script> leaked into rendered output: %q", html)
}
if !strings.Contains(html, "<script>alert(1)</script>") {
t.Errorf("expected escaped script tag in output: %q", html)
}
}
func TestRenderReadingsVertical(t *testing.T) {
secs := []liturgy.Section{{Heading: "Ewangelia (J 20, 1. 11-18)", PartID: "ewangelia"}}
html := string(RenderReadings(secs, []string{"wuj", "vul"}, "new", "vertical", "pl"))
if !strings.Contains(html, "display-vertical") {
t.Errorf("vertical output missing display-vertical container: %q", html[:min(300, len(html))])
}
if !strings.Contains(html, "vcol") {
t.Errorf("vertical output missing vcol columns: %q", html[:min(300, len(html))])
}
if !strings.Contains(html, "Wujek") || !strings.Contains(html, "Wulgata") {
t.Errorf("vertical output missing both version labels: %q", html[:min(300, len(html))])
}
}
func TestRenderReadingsInterlinear(t *testing.T) {
secs := []liturgy.Section{{Heading: "Ewangelia (J 20, 1. 11-18)", PartID: "ewangelia"}}
html := string(RenderReadings(secs, []string{"wuj", "vul"}, "new", "interlinear", "pl"))
if !strings.Contains(html, "ilverse") {
t.Errorf("interlinear output missing ilverse: %q", html[:min(300, len(html))])
}
if !strings.Contains(html, `class="vnum"`) {
t.Errorf("interlinear output missing vnum: %q", html[:min(300, len(html))])
}
// The first ilverse block should group both version labels under one key.
// Bound it by the next vnum span (each ilverse carries exactly one).
i := strings.Index(html, `class="vnum"`)
block := html[i:]
if j := strings.Index(html[i+1:], `class="vnum"`); j != -1 {
block = html[i : i+1+j]
}
if !strings.Contains(block, "Wujek") || !strings.Contains(block, "Wulgata") {
t.Errorf("first interlinear verse block missing both version labels: %q", block)
}
}
func TestRenderReadingsInterlinearExcludesPL(t *testing.T) {
secs := []liturgy.Section{{Heading: "Ewangelia (J 20, 1. 11-18)", PartID: "ewangelia"}}
html := string(RenderReadings(secs, []string{"pl", "vul"}, "new", "interlinear", "pl"))
if strings.Contains(html, "Polski (niedziela.pl)") {
t.Errorf("interlinear output should substitute wuj for pl, not carry pl's label: %q", html[:min(300, len(html))])
}
if !strings.Contains(html, "Wujek") {
t.Errorf("interlinear output should substitute wuj for pl: %q", html[:min(300, len(html))])
}
}
func TestRenderReadingsInterlinearNoVersifiedNote(t *testing.T) {
secs := []liturgy.Section{{Heading: "Bez odwołania", PartID: "ewangelia"}}
html := string(RenderReadings(secs, []string{"wuj"}, "new", "interlinear", "pl"))
if strings.Contains(html, "ilverse") {
t.Errorf("expected no ilverse blocks when nothing resolves: %q", html)
}
}
// TestRenderReadingsLocalizesEN checks that lang="en" localises both the
// version-column label (via render.GatherVersion) and the section heading's
// part-label word (via render.LocalizeHeading, brief §3b), while the
// citation stays exactly as scraped.
func TestRenderReadingsLocalizesEN(t *testing.T) {
secs := []liturgy.Section{{Heading: "Ewangelia (J 20, 1. 11-18)", PartID: "ewangelia"}}
html := string(RenderReadings(secs, []string{"vul"}, "new", "horizontal", "en"))
if !strings.Contains(html, "Gospel (J 20, 1. 11-18)") {
t.Errorf("en output missing localised heading: %q", html[:min(300, len(html))])
}
if !strings.Contains(html, "Vulgate (Latin)") {
t.Errorf("en output missing localised version label: %q", html[:min(300, len(html))])
}
if strings.Contains(html, "Ewangelia") {
t.Errorf("en output should not carry the Polish heading label: %q", html[:min(300, len(html))])
}
}
func TestUserTheme(t *testing.T) {
dir := t.TempDir()
t.Setenv("XDG_CONFIG_HOME", dir)
td := filepath.Join(dir, "lectio", "themes")
os.MkdirAll(td, 0o755)
os.WriteFile(filepath.Join(td, "mine.css"), []byte(".heading{color:#f00}"), 0o644)
found := false
for _, n := range Themes() {
if n == "mine" {
found = true
}
}
if !found {
t.Error("user theme 'mine' not listed by Themes()")
}
if b, err := themeCSS("mine"); err != nil || len(b) == 0 {
t.Errorf("user theme not read: %v", err)
}
}
|