aboutsummaryrefslogtreecommitdiff
path: root/internal/cli/cli_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/cli/cli_test.go')
-rw-r--r--internal/cli/cli_test.go87
1 files changed, 55 insertions, 32 deletions
diff --git a/internal/cli/cli_test.go b/internal/cli/cli_test.go
index c76d61c..bc7dfdb 100644
--- a/internal/cli/cli_test.go
+++ b/internal/cli/cli_test.go
@@ -9,6 +9,7 @@ import (
"strings"
"testing"
+ "github.com/lukaszkasprzak/lectio/internal/bible"
"github.com/lukaszkasprzak/lectio/internal/liturgy"
)
@@ -268,64 +269,86 @@ func TestExtractDateDefaultsToday(t *testing.T) {
}
}
-func TestListEN(t *testing.T) {
+func TestRefSingle(t *testing.T) {
+ var out, errb bytes.Buffer
+ code := Run([]string{"-p", "Jn 3:16", "-b", "vul"}, nil, &out, &errb)
+ if code != 0 {
+ t.Fatalf("ref code=%d stderr=%q", code, errb.String())
+ }
+ if s := out.String(); !strings.Contains(s, "3:16") {
+ t.Errorf("ref output missing verse 3:16:\n%s", s)
+ }
+}
+
+func TestRefNotFound(t *testing.T) {
var out, errb bytes.Buffer
- if code := Run([]string{"--list-en"}, nil, &out, &errb); code != 0 {
- t.Fatalf("--list-en code=%d stderr=%q", code, errb.String())
+ // An unknown book -> ParseRef fails to resolve it in the dialect -> exit 2.
+ if code := Run([]string{"-p", "Zzz 9:9", "-b", "vul"}, nil, &out, &errb); code != 2 {
+ t.Errorf("ref unknown-book code=%d want 2 (stderr=%q)", code, errb.String())
+ }
+}
+
+func TestRunListEnglish(t *testing.T) {
+ tbl, _ := bible.LoadBookTable(nil)
+ var out bytes.Buffer
+ if code := runList(tbl, "en", &out); code != 0 {
+ t.Fatalf("runList en code=%d", code)
}
- s := out.String()
- if !strings.Contains(s, "John") || !strings.Contains(s, "Genesis") {
- t.Errorf("--list-en missing expected books:\n%s", s)
+ if s := out.String(); !strings.Contains(s, "Jn") || !strings.Contains(s, "John") {
+ t.Errorf("en list missing Jn/John:\n%s", s)
}
- // abbrev-then-name, one book per line; expect a J -> John line.
- if !strings.Contains(s, "J") {
- t.Errorf("--list-en missing John abbrev")
+}
+
+func TestRunListPolish(t *testing.T) {
+ tbl, _ := bible.LoadBookTable(nil)
+ var out bytes.Buffer
+ runList(tbl, "pl", &out)
+ if s := out.String(); !strings.Contains(s, "Jana") || !strings.Contains(s, "Rodzaju") {
+ t.Errorf("pl list missing Jana/Rodzaju:\n%s", s)
}
}
-func TestListPL(t *testing.T) {
+func TestListFlag(t *testing.T) {
var out, errb bytes.Buffer
- if code := Run([]string{"--list-pl"}, nil, &out, &errb); code != 0 {
- t.Fatalf("--list-pl code=%d stderr=%q", code, errb.String())
+ if code := Run([]string{"--list"}, nil, &out, &errb); code != 0 {
+ t.Fatalf("--list code=%d stderr=%q", code, errb.String())
}
- if s := out.String(); !strings.Contains(s, "Jan") || !strings.Contains(s, "Rodzaju") {
- t.Errorf("--list-pl missing Polish names:\n%s", s)
+ if n := strings.Count(strings.TrimSpace(out.String()), "\n") + 1; n < 73 {
+ t.Errorf("--list printed %d lines, want >=73", n)
}
}
-func TestRefSingle(t *testing.T) {
+func TestRefEnglishDialect(t *testing.T) {
var out, errb bytes.Buffer
- code := Run([]string{"-p", "J 3:16", "-b", "vul"}, nil, &out, &errb)
- if code != 0 {
+ if code := Run([]string{"-p", "Jn 3:16", "-b", "vul"}, nil, &out, &errb); code != 0 {
t.Fatalf("ref code=%d stderr=%q", code, errb.String())
}
- if s := out.String(); !strings.Contains(s, "3:16") {
- t.Errorf("ref output missing verse 3:16:\n%s", s)
+ if !strings.Contains(out.String(), "3:16") {
+ t.Errorf("ref output missing 3:16:\n%s", out.String())
+ }
+}
+
+func TestRefRejectsPolishAbbrevInEnglish(t *testing.T) {
+ var out, errb bytes.Buffer
+ // English dialect (default): the Polish abbrev "Łk" must not resolve.
+ if code := Run([]string{"-p", "Łk 3:16", "-b", "vul"}, nil, &out, &errb); code != 2 {
+ t.Errorf("Łk in en dialect code=%d want 2 (stderr=%q)", code, errb.String())
}
}
func TestRefRejectsBT(t *testing.T) {
var out, errb bytes.Buffer
- if code := Run([]string{"-p", "J 3:16", "-b", "bt"}, nil, &out, &errb); code != 2 {
+ if code := Run([]string{"-p", "Jn 3:16", "-b", "bt"}, nil, &out, &errb); code != 2 {
t.Errorf("ref -b bt code=%d want 2 (stderr=%q)", code, errb.String())
}
}
func TestRefCompare(t *testing.T) {
var out, errb bytes.Buffer
- code := Run([]string{"-p", "J 3:16", "-c", "vul,drb"}, nil, &out, &errb)
- if code != 0 {
+ if code := Run([]string{"-p", "Jn 3:16", "-c", "vul,drb"}, nil, &out, &errb); code != 0 {
t.Fatalf("ref compare code=%d stderr=%q", code, errb.String())
}
- if s := out.String(); !strings.Contains(s, "3:16") {
- t.Errorf("ref compare missing verse:\n%s", s)
- }
-}
-
-func TestRefNotFound(t *testing.T) {
- var out, errb bytes.Buffer
- // A book/verse the corpus won't have text for -> exit 1.
- if code := Run([]string{"-p", "Zzz 9:9", "-b", "vul"}, nil, &out, &errb); code != 1 {
- t.Errorf("ref not-found code=%d want 1 (stderr=%q)", code, errb.String())
+ if !strings.Contains(out.String(), "3:16") {
+ t.Errorf("ref compare missing verse:\n%s", out.String())
}
}