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
|
package cli
import (
"bytes"
"os"
"path/filepath"
"strings"
"testing"
"github.com/lukaszkasprzak/lectio/internal/config"
)
func TestRunLiturgy(t *testing.T) {
dir := t.TempDir()
t.Setenv("LECTIO_CONFIG", filepath.Join(dir, "config.ini"))
cfg, err := config.Load()
if err != nil {
t.Fatal(err)
}
var buf bytes.Buffer
if code := runLiturgy(cfg, "2025-08-15", &buf, &buf); code != 0 {
t.Fatalf("exit code %d", code)
}
out := buf.String()
if !strings.Contains(out, "2025-08-15") {
t.Errorf("missing date:\n%s", out)
}
if !strings.Contains(strings.ToLower(out), "solemnity") || !strings.Contains(out, "Assumption") {
t.Errorf("2025-08-15 should be the Assumption solemnity:\n%s", out)
}
if !strings.Contains(out, "gospel (") {
t.Errorf("proper reading not shown:\n%s", out)
}
}
func TestRunLiturgyTraditionalComputesEF(t *testing.T) {
dir := t.TempDir()
t.Setenv("LECTIO_CONFIG", filepath.Join(dir, "config.ini"))
os.WriteFile(filepath.Join(dir, "config.ini"), []byte("lectionary = traditional\n"), 0o644)
cfg, err := config.Load()
if err != nil {
t.Fatal(err)
}
var buf bytes.Buffer
if code := runLiturgy(cfg, "2025-08-15", &buf, &buf); code != 0 {
t.Fatalf("EF compute failed (%d):\n%s", code, buf.String())
}
out := buf.String()
// EF: Assumption is I class, and 2025-08-15 is in Time after Pentecost (not OF "ordinary").
if !strings.Contains(out, "Assumption") || !strings.Contains(out, "I class") {
t.Errorf("expected EF Assumption (I class):\n%s", out)
}
if !strings.Contains(out, "time-after-pentecost") {
t.Errorf("expected EF season time-after-pentecost:\n%s", out)
}
}
func TestRunLiturgyUserLayer(t *testing.T) {
dir := t.TempDir()
t.Setenv("LECTIO_CONFIG", filepath.Join(dir, "config.ini"))
// a local layer adds a solemnity on 2025-08-11 (an ordinary Monday), and use it.
os.MkdirAll(filepath.Join(dir, "calendars"), 0o755)
os.WriteFile(filepath.Join(dir, "calendars", "local.ini"),
[]byte("[layer]\nid = local\ntype = particular\n\n[patron]\ndate = 08-11\nrank = solemnity\nclass = saint\ncolour = red\nname.en = Local Patron\n"), 0o644)
os.WriteFile(filepath.Join(dir, "config.ini"), []byte("use = local\n"), 0o644)
cfg, err := config.Load()
if err != nil {
t.Fatal(err)
}
var buf bytes.Buffer
if code := runLiturgy(cfg, "2025-08-11", &buf, &buf); code != 0 {
t.Fatalf("exit %d", code)
}
if !strings.Contains(buf.String(), "Local Patron") {
t.Fatalf("user layer's solemnity not observed:\n%s", buf.String())
}
}
|