bump(github.com/BurntSushi/toml): da57f3b4c85ec56cf139d7dc05396fa98a040773

This commit is contained in:
Ben Johnson
2013-12-23 16:01:51 -07:00
parent 4acfc26c5e
commit 9ebac0b9fd
3 changed files with 317 additions and 20 deletions

View File

@ -1,6 +1,7 @@
package toml
import (
"encoding/json"
"fmt"
"log"
"reflect"
@ -63,6 +64,53 @@ func TestDecode(t *testing.T) {
testf("%v\n", val)
}
func TestDecodeEmbedded(t *testing.T) {
type Dog struct{ Name string }
tests := map[string]struct {
input string
decodeInto interface{}
wantDecoded interface{}
}{
"embedded struct": {
input: `Name = "milton"`,
decodeInto: &struct{ Dog }{},
wantDecoded: &struct{ Dog }{Dog{"milton"}},
},
"embedded non-nil pointer to struct": {
input: `Name = "milton"`,
decodeInto: &struct{ *Dog }{},
wantDecoded: &struct{ *Dog }{&Dog{"milton"}},
},
"embedded nil pointer to struct": {
input: ``,
decodeInto: &struct{ *Dog }{},
wantDecoded: &struct{ *Dog }{nil},
},
}
for label, test := range tests {
_, err := Decode(test.input, test.decodeInto)
if err != nil {
t.Fatal(err)
}
want, got := jsonstr(test.wantDecoded), jsonstr(test.decodeInto)
if want != got {
t.Errorf("%s: want decoded == %+v, got %+v", label, want, got)
}
}
}
// jsonstr allows comparison of deeply nested structs with pointer members.
func jsonstr(o interface{}) string {
s, err := json.MarshalIndent(o, "", " ")
if err != nil {
panic(err.Error())
}
return string(s)
}
var tomlTableArrays = `
[[albums]]
name = "Born to Run"
@ -124,8 +172,6 @@ tOpdate = 2006-01-02T15:04:05Z
tOparray = [ "array" ]
Match = "i should be in Match only"
MatcH = "i should be in MatcH only"
Field = "neat"
FielD = "messy"
once = "just once"
[nEst.eD]
nEstedString = "another string"
@ -140,7 +186,6 @@ type Insensitive struct {
TopArray []string
Match string
MatcH string
Field string
Once string
OncE string
Nest InsensitiveNest
@ -168,9 +213,8 @@ func TestCase(t *testing.T) {
TopArray: []string{"array"},
MatcH: "i should be in MatcH only",
Match: "i should be in Match only",
Field: "neat", // encoding/json would store "messy" here
Once: "just once",
OncE: "just once", // wait, what?
OncE: "",
Nest: InsensitiveNest{
Ed: InsensitiveEd{NestedString: "another string"},
},