Debian Codegraph @

parsers/nestedtext/nt_test.go

raw
1 package nestedtext_test
2
3 import (
4 "testing"
5
6 "github.com/knadh/koanf/parsers/nestedtext"
7 )
8
9 func TestParser(t *testing.T) {
10 // test input in NestedText format
11 ntsource := `ports:
12 - 6483
13 - 8020
14 - 9332
15 timeout: 20
16 `
17 // Test decoder
18 nt := nestedtext.Parser()
19 c, err := nt.Unmarshal([]byte(ntsource))
20 if err != nil {
21 t.Fatal("Unmarshal of NestedText input failed")
22 }
23 timeout := c["timeout"]
24 if timeout != "20" {
25 t.Logf("config-tree: %#v", c)
26 t.Errorf("expected timeout-parameter to be 20, is %q", timeout)
27 }
28
29 // test encoder
30 out, err := nt.Marshal(c)
31 if err != nil {
32 t.Fatal("Marshal of config to NestedText failed")
33 }
34 if string(out) != ntsource {
35 t.Logf("config-text: %q", string(out))
36 t.Errorf("expected output of Marshal(…) to equal input to Unmarshal(…); didn't")
37 }
38 }