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]) } } }