summaryrefslogtreecommitdiff
path: root/internal/ini/ini_test.go
blob: 16aef7bf7c69c0de7127e4578b30c54baa42ddcb (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
package ini

import "testing"

func TestParseSectionsAndPairs(t *testing.T) {
	in := []byte(`
# a full-line comment
; another full-line comment
lectionary = new

[assumption]
date = 08-15
name.pl = Wniebowzięcie
rank= solemnity
reading.first = Rev 11:19; 12:1-6.10

[assumption/vigil]
reading.gospel = Łk 11,27-28
`)
	secs, err := Parse(in)
	if err != nil {
		t.Fatal(err)
	}
	// top-level pairs land in a section with empty name, first.
	if secs[0].Name != "" || len(secs[0].Pairs) != 1 || secs[0].Pairs[0] != (Pair{"lectionary", "new"}) {
		t.Fatalf("top-level = %+v", secs[0])
	}
	if secs[1].Name != "assumption" || secs[1].Pairs[1] != (Pair{"name.pl", "Wniebowzięcie"}) {
		t.Fatalf("assumption = %+v", secs[1])
	}
	if secs[1].Pairs[2] != (Pair{"rank", "solemnity"}) {
		t.Fatalf("no-space key = %+v", secs[1].Pairs[2])
	}
	// a semicolon inside a value (scripture citation) is preserved, not treated
	// as a comment.
	if got := secs[1].Pairs[3]; got != (Pair{"reading.first", "Rev 11:19; 12:1-6.10"}) {
		t.Fatalf("citation with ';' mangled: %+v", got)
	}
	if secs[2].Name != "assumption/vigil" {
		t.Fatalf("subsection = %q", secs[2].Name)
	}
}

func TestList(t *testing.T) {
	got := List("bt, wuj ,, vul")
	want := []string{"bt", "wuj", "vul"}
	if len(got) != len(want) {
		t.Fatalf("List = %v", got)
	}
	for i := range want {
		if got[i] != want[i] {
			t.Fatalf("List[%d] = %q want %q", i, got[i], want[i])
		}
	}
}