aboutsummaryrefslogtreecommitdiff
path: root/internal/cli/liturgy_test.go
blob: 02f02c4f96b5d9f93feeb8991511d670cea73dd9 (plain) (blame)
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
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 TestRunLiturgyTraditionalGuarded(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("traditional config should be guarded, not computed as OF:\n%s", buf.String())
	}
	if !strings.Contains(strings.ToLower(buf.String()), "ordinary form") {
		t.Errorf("expected an EF-not-implemented notice:\n%s", buf.String())
	}
}

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())
	}
}