rastrillo / abono Public

Clone
git clone https://amadan.net/rastrillo/abono

Plain git — no account needed to clone.

Download

Download this file

1package abono
2
3import (
4 "reflect"
5 "strings"
6 "testing"
7)
8
9func TestDecodeCatalog(t *testing.T) {
10 got, err := decodeCatalog([]byte("# a comment\n\nabono.a = \"One \\\"two\\\" {x}\" # trailing\nabono.b = 'lit\\eral'\r\nabono.c-d_e = \"é\"\n"))
11 if err != nil {
12 t.Fatal(err)
13 }
14 want := map[string]string{"abono.a": `One "two" {x}`, "abono.b": `lit\eral`, "abono.c-d_e": "é"}
15 if !reflect.DeepEqual(map[string]string(got), want) {
16 t.Errorf("got %v, want %v", got, want)
17 }
18}
19
20func TestDecodeCatalogRefuses(t *testing.T) {
21 for name, in := range map[string]string{
22 "table": "[abono]\n",
23 "no equals": "abono.a\n",
24 "bare value": "abono.a = 3\n",
25 "unterminated": "abono.a = \"x\n",
26 "trailing": "abono.a = \"x\" y\n",
27 "duplicate": "abono.a = \"x\"\nabono.a = \"y\"\n",
28 "empty key": " = \"x\"\n",
29 "bad escape": "abono.a = \"\\q\"\n",
30 } {
31 if _, err := decodeCatalog([]byte(in)); err == nil {
32 t.Errorf("%s: accepted %q", name, in)
33 }
34 }
35}
36
37// The shipped file decodes, and Catalog hands out a copy.
38func TestCatalogIsACopyOfTheShippedFile(t *testing.T) {
39 c := Catalog()
40 for k := range c {
41 if !strings.HasPrefix(k, "abono.") {
42 t.Errorf("key %q is not in abono's namespace", k)
43 }
44 }
45 c["abono.test.sentinel"] = "x"
46 if _, leaked := Catalog()["abono.test.sentinel"]; leaked {
47 t.Error("Catalog shares its table with the caller")
48 }
49}
50