package cli import ( "bytes" "os" "path/filepath" "strings" "testing" "github.com/lukaszkasprzak/lectio/internal/bible" "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 TestVernacularVersionResolver(t *testing.T) { if got := vernacularVersion(config.Config{ReadingVersion: "drb"}); got != "drb" { t.Fatalf("explicit: %q", got) } if got := vernacularVersion(config.Config{UILanguage: "pl"}); got != "vul" { t.Fatalf("pl should fall back to Latin: %q", got) } if got := vernacularVersion(config.Config{UILanguage: "en"}); got != "drb" { t.Fatalf("en should be drb: %q", got) } } func TestVersionDisplayNameFallsBackToCorpusMeta(t *testing.T) { bible.SetUserCorporaDir("../bible/testdata/corpora") t.Cleanup(func() { bible.SetUserCorporaDir("") }) // "good" is a user fixture with no i18n entry; its sidecar Name must // surface instead of the bare code. if got := versionDisplayName("en", "good"); got != "Good Test Corpus" { t.Fatalf("expected sidecar Name fallback, got %q", got) } // a known i18n code still uses the localized chrome label. if got := versionDisplayName("en", "drb"); got == "drb" { t.Fatalf("expected localized label, got bare code %q", got) } // a totally unknown code with no sidecar falls back to the bare code. if got := versionDisplayName("en", "zzz-nope"); got != "zzz-nope" { t.Fatalf("expected bare-code fallback, got %q", got) } } 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()) } }