-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathfftoml_test.go
55 lines (50 loc) · 1.36 KB
/
fftoml_test.go
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 fftoml_test
import (
"testing"
"time"
"github.com/peterbourgon/ff/v4"
"github.com/peterbourgon/ff/v4/fftest"
"github.com/peterbourgon/ff/v4/fftoml"
)
func TestParser(t *testing.T) {
t.Parallel()
testcases := fftest.TestCases{
{
Name: "empty input",
ConfigFile: "testdata/empty.toml",
Want: fftest.Vars{},
},
{
Name: "basic KV pairs",
ConfigFile: "testdata/basic.toml",
Want: fftest.Vars{
S: "s",
I: 10,
F: 3.14e10,
B: true,
D: 5 * time.Second,
X: []string{"1", "a", "👍"},
},
},
{
Name: "bad TOML file",
ConfigFile: "testdata/bad.toml",
Want: fftest.Vars{WantParseErrorString: "invalid character at start of key"},
},
{
Name: "nested with '.'",
ConfigFile: "testdata/table.toml",
Default: fftest.Vars{I: 999},
Constructors: []fftest.Constructor{fftest.NewNestedConstructor(".")},
Want: fftest.Vars{S: "a string", I: 999, F: 1.23, X: []string{"one", "two", "three"}},
},
{
Name: "nested with '-'",
ConfigFile: "testdata/table.toml",
Constructors: []fftest.Constructor{fftest.NewNestedConstructor("-")},
Options: []ff.Option{ff.WithConfigFileParser(fftoml.Parser{Delimiter: "-"}.Parse)},
Want: fftest.Vars{S: "a string", F: 1.23, X: []string{"one", "two", "three"}},
},
}
testcases.Run(t)
}