aboutsummaryrefslogtreecommitdiff
path: root/internal/config/config_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/config/config_test.go')
-rw-r--r--internal/config/config_test.go82
1 files changed, 54 insertions, 28 deletions
diff --git a/internal/config/config_test.go b/internal/config/config_test.go
index 4d172c0..b1f3ddd 100644
--- a/internal/config/config_test.go
+++ b/internal/config/config_test.go
@@ -4,8 +4,22 @@ import (
"os"
"path/filepath"
"testing"
+
+ "github.com/lukaszkasprzak/lectio/internal/bible"
)
+// requireCorpus skips the test when corpus `code` is not embedded in this
+// build. The optional corpora (wuj, drb, grb) compile in only with
+// `-tags fullbible` (or when dropped into the user corpora dir); mirrors the
+// helper in internal/bible so these tests run under fullbible and skip -- not
+// fail -- on the default vul-only build.
+func requireCorpus(t *testing.T, code string) {
+ t.Helper()
+ if _, ok := bible.Meta(code); !ok {
+ t.Skipf("corpus %q not embedded; build with -tags fullbible", code)
+ }
+}
+
func TestLoadSeeds(t *testing.T) {
dir := t.TempDir()
t.Setenv("XDG_CONFIG_HOME", dir)
@@ -16,26 +30,32 @@ func TestLoadSeeds(t *testing.T) {
if cfg.DefaultVersion != "vul" || cfg.Offline {
t.Errorf("defaults wrong: %+v", cfg)
}
- // Versions defaults to the corpora actually available in this build, Vulgate
- // first then the rest sorted. Tests build with -tags fullbible, so all four
- // are present (see Makefile); a default vul-only binary would list just vul.
- wantVersions := []string{"vul", "drb", "grb", "wuj"}
- if len(cfg.Versions) != len(wantVersions) {
- t.Errorf("versions default = %v, want %v", cfg.Versions, wantVersions)
- } else {
- for i, v := range wantVersions {
- if cfg.Versions[i] != v {
- t.Errorf("versions default = %v, want %v", cfg.Versions, wantVersions)
- break
- }
- }
- }
if cfg.Lectionary != "new" {
t.Errorf("lectionary default wrong: %+v", cfg)
}
if _, err := os.Stat(filepath.Join(dir, "lectio", "config.ini")); err != nil {
t.Error("config not seeded")
}
+ // Versions defaults to the corpora actually available in this build, Vulgate
+ // first then the rest sorted. With -tags fullbible all four are present (see
+ // Makefile); a default vul-only binary would list just vul, so this
+ // assertion needs the optional corpora embedded.
+ t.Run("all corpora listed", func(t *testing.T) {
+ requireCorpus(t, "drb")
+ requireCorpus(t, "grb")
+ requireCorpus(t, "wuj")
+ wantVersions := []string{"vul", "drb", "grb", "wuj"}
+ if len(cfg.Versions) != len(wantVersions) {
+ t.Errorf("versions default = %v, want %v", cfg.Versions, wantVersions)
+ } else {
+ for i, v := range wantVersions {
+ if cfg.Versions[i] != v {
+ t.Errorf("versions default = %v, want %v", cfg.Versions, wantVersions)
+ break
+ }
+ }
+ }
+ })
}
// TestLoadMigratesBT checks a legacy config still carrying the retired "bt"
@@ -324,20 +344,26 @@ func TestPartShown(t *testing.T) {
}
func TestReadingCorpusResolution(t *testing.T) {
- // drb is an embedded corpus with lang=en.
- c := Config{ReadingVersion: "drb"}
- if got := c.ReadingCorpus(); got != "drb" {
- t.Fatalf("explicit reading_version: got %q", got)
- }
- c = Config{ReadingLang: "en"}
- if got := c.ReadingCorpus(); got != "drb" {
- t.Fatalf("reading_lang match: got %q", got)
- }
- c = Config{UILanguage: "en"}
- if got := c.ReadingCorpus(); got != "drb" {
- t.Fatalf("ui_language fallback: got %q", got)
- }
- c = Config{UILanguage: "pl"} // no pl corpus embedded
+ // The explicit-passthrough, reading_lang and ui_language cases all resolve to
+ // the embedded drb (lang=en) via bible.Meta/CorporaForLang, so they need drb.
+ t.Run("drb", func(t *testing.T) {
+ requireCorpus(t, "drb")
+ c := Config{ReadingVersion: "drb"}
+ if got := c.ReadingCorpus(); got != "drb" {
+ t.Fatalf("explicit reading_version: got %q", got)
+ }
+ c = Config{ReadingLang: "en"}
+ if got := c.ReadingCorpus(); got != "drb" {
+ t.Fatalf("reading_lang match: got %q", got)
+ }
+ c = Config{UILanguage: "en"}
+ if got := c.ReadingCorpus(); got != "drb" {
+ t.Fatalf("ui_language fallback: got %q", got)
+ }
+ })
+ // No pl corpus is autoselect-eligible, so pl resolves to "" on either build
+ // -- pure logic, keep it running.
+ c := Config{UILanguage: "pl"}
if got := c.ReadingCorpus(); got != "" {
t.Fatalf("no match should be empty: got %q", got)
}