File tree Expand file tree Collapse file tree 2 files changed +17
-15
lines changed Expand file tree Collapse file tree 2 files changed +17
-15
lines changed Original file line number Diff line number Diff line change @@ -6,39 +6,44 @@ import (
66"github.com/stretchr/testify/require"
77)
88
9+ type Metadata struct {
10+ Tags []string
11+ }
12+
913type MyConfig struct {
1014Version int
1115Name string
12- Tags [] string
16+ Meta * Metadata
1317}
1418
1519var testTomlCfg = & MyConfig {
1620Version : 2 ,
1721Name : "go-toml" ,
18- Tags : []string {"go" , "toml" },
22+ Meta : & Metadata {
23+ Tags : []string {"go" , "toml" },
24+ },
1925}
2026
27+ var testTomlStr = `Version = 2
28+ Name = 'go-toml'
29+
30+ [Meta]
31+ Tags = ['go', 'toml']
32+ `
33+
2134func TestMarshalToml (t * testing.T ) {
2235req := require .New (t )
2336
2437bytes , err := Marshal (testTomlCfg , ".toml" )
2538req .NoError (err )
2639
27- expected := `Version = 2
28- Name = 'go-toml'
29- Tags = ['go', 'toml']
30- `
31- req .Equal (expected , string (bytes ))
40+ req .Equal (testTomlStr , string (bytes ))
3241}
3342
3443func TestUnmarshalToml (t * testing.T ) {
3544req := require .New (t )
36- tomlStr := `Version = 2
37- Name = 'go-toml'
38- Tags = ['go', 'toml']
39- `
4045cfg := & MyConfig {}
41- err := Unmarshal ([]byte (tomlStr ), ".toml" , cfg )
46+ err := Unmarshal ([]byte (testTomlStr ), ".toml" , cfg )
4247req .NoError (err )
4348req .Equal (testTomlCfg , cfg )
4449}
Original file line number Diff line number Diff line change 77"github.com/pelletier/go-toml/v2"
88)
99
10- // TODO: consider using cue's JSON marshaller instead of
11- // "encoding/json" ... it might have extra functionality related
12- // to the cue language.
1310func MarshalToml (v interface {}) ([]byte , error ) {
1411return toml .Marshal (v )
1512}
You can’t perform that action at this time.
0 commit comments