aboutsummaryrefslogtreecommitdiff
path: root/internal/render/render_test.go
blob: 1b338a04e9913f0b4c9b76c84220da17656b7032 (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
74
75
76
77
78
79
80
81
82
83
84
package render

import (
	"strings"
	"testing"

	"github.com/lukaszkasprzak/lectio/internal/liturgy"
)

func TestGatherPLDedup(t *testing.T) {
	sec := liturgy.Section{
		Heading:    "Psalm (Ps 1)",
		Paragraphs: [][]string{{"stanza one"}, {"refrain"}, {"stanza two"}, {"refrain"}},
	}
	_, blocks := GatherVersion("pl", sec, "new")
	n := 0
	for _, b := range blocks {
		if b == "refrain" {
			n++
		}
	}
	if n != 1 {
		t.Errorf("refrain appears %d times, want 1 (deduped)", n)
	}
}

func TestGatherBible(t *testing.T) {
	sec := liturgy.Section{Heading: "Ewangelia (J 20, 1. 11-18)"}
	label, blocks := GatherVersion("wuj", sec, "new")
	if !strings.Contains(label, "Wujek") {
		t.Errorf("label = %q", label)
	}
	if len(blocks) == 0 || !strings.HasPrefix(blocks[0], "20:1") {
		t.Errorf("first block = %q", blocks)
	}
}

func TestGatherTraditional(t *testing.T) {
	sec := liturgy.Section{Citation: "Luke 7:36-50"}
	_, blocks := GatherVersion("vul", sec, "traditional")
	if len(blocks) == 0 || !strings.HasPrefix(blocks[0], "7:36") {
		t.Errorf("first block = %q", blocks)
	}
}

func TestOfflineVersions(t *testing.T) {
	got := OfflineVersions([]string{"pl", "wuj", "vul"})
	for _, v := range got {
		if v == "pl" {
			t.Error("pl not dropped offline")
		}
	}
}

func TestGatherVersesBible(t *testing.T) {
	sec := liturgy.Section{Heading: "Ewangelia (J 20, 1. 11-18)"}
	label, verses, versified := GatherVerses("wuj", sec, "new")
	if !strings.Contains(label, "Wujek") {
		t.Errorf("label = %q", label)
	}
	if !versified {
		t.Error("versified = false, want true for wuj with a resolvable citation")
	}
	if len(verses) == 0 {
		t.Fatal("verses empty")
	}
	if verses[0].Chapter != 20 || verses[0].Verse != 1 || verses[0].Text == "" {
		t.Errorf("verses[0] = %+v", verses[0])
	}
}

func TestGatherVersesPL(t *testing.T) {
	sec := liturgy.Section{
		Heading:    "Psalm (Ps 1)",
		Paragraphs: [][]string{{"stanza one"}},
	}
	_, verses, versified := GatherVerses("pl", sec, "new")
	if versified {
		t.Error("versified = true, want false for pl (paragraph text, no verse numbers)")
	}
	if verses != nil {
		t.Errorf("verses = %+v, want nil for pl", verses)
	}
}