summaryrefslogtreecommitdiff
path: root/internal/caldata/stack_test.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-07-27 13:19:29 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-07-27 13:19:29 +0200
commitacbba6b53df93de694abf1feb90ab401fd6a4580 (patch)
tree55a80c803f3699fd66526fa48bcb5ed2c73b40a6 /internal/caldata/stack_test.go
parentf96c7fcd319d7fe94a4dd8debe5d4d56a77ab2c9 (diff)
downloadlectio-acbba6b53df93de694abf1feb90ab401fd6a4580.tar.gz
lectio-acbba6b53df93de694abf1feb90ab401fd6a4580.zip
feat(caldata): export ParseLayer + LoadLayer + Stack (user calendar layers)
Diffstat (limited to 'internal/caldata/stack_test.go')
-rw-r--r--internal/caldata/stack_test.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/internal/caldata/stack_test.go b/internal/caldata/stack_test.go
new file mode 100644
index 0000000..b9d5bfb
--- /dev/null
+++ b/internal/caldata/stack_test.go
@@ -0,0 +1,56 @@
+package caldata
+
+import (
+ "os"
+ "path/filepath"
+ "testing"
+)
+
+func TestStack(t *testing.T) {
+ dir := t.TempDir()
+ os.WriteFile(filepath.Join(dir, "poland.ini"),
+ []byte("[layer]\nid = poland\ntype = national\n\n[our-lady-czestochowa]\ndate = 08-26\nrank = solemnity\nclass = bvm\ncolour = white\nname.pl = NMP Częstochowskiej\n"), 0o644)
+ os.WriteFile(filepath.Join(dir, "krakow.ini"),
+ []byte("[layer]\nid = krakow\ntype = diocesan\n\n[st-stanislaus]\ndate = 05-08\nrank = solemnity\nclass = saint\ncolour = red\nname.pl = Św. Stanisława\n"), 0o644)
+
+ layers, errs := Stack(dir, []string{"poland", "krakow"})
+ if len(errs) != 0 {
+ t.Fatalf("unexpected errors: %v", errs)
+ }
+ if len(layers) != 3 {
+ t.Fatalf("want 3 layers (universal+2), got %d", len(layers))
+ }
+ if layers[0].Type != "universal" || layers[1].ID != "poland" || layers[2].ID != "krakow" {
+ t.Errorf("order wrong: %q %q %q", layers[0].Type, layers[1].ID, layers[2].ID)
+ }
+ if _, ok := layers[1].Cels["our-lady-czestochowa"]; !ok {
+ t.Error("poland layer missing its celebration")
+ }
+}
+
+func TestStackMissingLayerSkips(t *testing.T) {
+ dir := t.TempDir()
+ os.WriteFile(filepath.Join(dir, "good.ini"),
+ []byte("[layer]\nid = good\n\n[x]\ndate = 01-02\nrank = memorial\nname.en = X\n"), 0o644)
+ layers, errs := Stack(dir, []string{"good", "missing"})
+ if len(errs) != 1 {
+ t.Fatalf("want 1 error for the missing layer, got %v", errs)
+ }
+ if len(layers) != 2 { // universal + good; missing skipped
+ t.Fatalf("want 2 layers, got %d", len(layers))
+ }
+}
+
+func TestLoadLayerDefaultsIDToStem(t *testing.T) {
+ dir := t.TempDir()
+ // no id in the [layer] header -> defaults to the stem
+ os.WriteFile(filepath.Join(dir, "myparish.ini"),
+ []byte("[layer]\ntype = particular\n\n[dedication]\ndate = 06-15\nrank = solemnity\nname.en = Dedication\n"), 0o644)
+ l, err := LoadLayer(filepath.Join(dir, "myparish.ini"), "myparish")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if l.ID != "myparish" {
+ t.Errorf("ID = %q, want myparish (from stem)", l.ID)
+ }
+}