todo: inline tables
This commit is contained in:
@@ -1887,11 +1887,9 @@ func TestUnmarshalMixedTypeArray(t *testing.T) {
|
|||||||
func TestUnmarshalArray(t *testing.T) {
|
func TestUnmarshalArray(t *testing.T) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
var actual1 arrayStruct
|
var actual arrayStruct
|
||||||
err = toml.Unmarshal(sliceTomlDemo, &actual1)
|
err = toml.Unmarshal(sliceTomlDemo, &actual)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Error("shound not err", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
expected := arrayStruct{
|
expected := arrayStruct{
|
||||||
Slice: [4]string{"Howdy", "Hey There"},
|
Slice: [4]string{"Howdy", "Hey There"},
|
||||||
@@ -1901,17 +1899,13 @@ func TestUnmarshalArray(t *testing.T) {
|
|||||||
StructSlice: [4]basicMarshalTestSubStruct{{"1"}, {"2"}},
|
StructSlice: [4]basicMarshalTestSubStruct{{"1"}, {"2"}},
|
||||||
StructSlicePtr: &[4]basicMarshalTestSubStruct{{"1"}, {"2"}},
|
StructSlicePtr: &[4]basicMarshalTestSubStruct{{"1"}, {"2"}},
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(actual1, expected) {
|
assert.Equal(t, expected, actual)
|
||||||
t.Errorf("Bad unmarshal: expected %v, got %v", expected, actual1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUnmarshalArrayFail(t *testing.T) {
|
func TestUnmarshalArrayFail(t *testing.T) {
|
||||||
var actual arrayTooSmallStruct
|
var actual arrayTooSmallStruct
|
||||||
err := toml.Unmarshal([]byte(`str_slice = ["Howdy", "Hey There"]`), &actual)
|
err := toml.Unmarshal([]byte(`str_slice = ["Howdy", "Hey There"]`), &actual)
|
||||||
if err.Error() != "(0, 0): unmarshal: TOML array length (2) exceeds destination array length (1)" {
|
assert.Error(t, err)
|
||||||
t.Error("expect err:(0, 0): unmarshal: TOML array length (2) exceeds destination array length (1) but got ", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUnmarshalArrayFail2(t *testing.T) {
|
func TestUnmarshalArrayFail2(t *testing.T) {
|
||||||
@@ -1919,9 +1913,7 @@ func TestUnmarshalArrayFail2(t *testing.T) {
|
|||||||
|
|
||||||
var actual arrayTooSmallStruct
|
var actual arrayTooSmallStruct
|
||||||
err := toml.Unmarshal([]byte(doc), &actual)
|
err := toml.Unmarshal([]byte(doc), &actual)
|
||||||
if err.Error() != "(1, 1): unmarshal: TOML array length (2) exceeds destination array length (1)" {
|
assert.Error(t, err)
|
||||||
t.Error("expect err:(1, 1): unmarshal: TOML array length (2) exceeds destination array length (1) but got ", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUnmarshalArrayFail3(t *testing.T) {
|
func TestUnmarshalArrayFail3(t *testing.T) {
|
||||||
@@ -1932,9 +1924,7 @@ String2="2"`
|
|||||||
|
|
||||||
var actual arrayTooSmallStruct
|
var actual arrayTooSmallStruct
|
||||||
err := toml.Unmarshal([]byte(doc), &actual)
|
err := toml.Unmarshal([]byte(doc), &actual)
|
||||||
if err.Error() != "(3, 1): unmarshal: TOML array length (2) exceeds destination array length (1)" {
|
assert.Error(t, err)
|
||||||
t.Error("expect err:(3, 1): unmarshal: TOML array length (2) exceeds destination array length (1) but got ", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDecoderStrict(t *testing.T) {
|
func TestDecoderStrict(t *testing.T) {
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ type builder interface {
|
|||||||
ArrayBegin()
|
ArrayBegin()
|
||||||
ArrayEnd()
|
ArrayEnd()
|
||||||
Assignation()
|
Assignation()
|
||||||
|
InlineTableBegin()
|
||||||
|
InlineTableEnd()
|
||||||
|
|
||||||
StringValue(v []byte)
|
StringValue(v []byte)
|
||||||
BoolValue(b bool)
|
BoolValue(b bool)
|
||||||
@@ -249,6 +251,9 @@ func (p parser) parseInlineTable(b []byte) ([]byte, error) {
|
|||||||
//inline-table-sep = ws %x2C ws ; , Comma
|
//inline-table-sep = ws %x2C ws ; , Comma
|
||||||
//inline-table-keyvals = keyval [ inline-table-sep inline-table-keyvals ]
|
//inline-table-keyvals = keyval [ inline-table-sep inline-table-keyvals ]
|
||||||
|
|
||||||
|
p.builder.InlineTableBegin()
|
||||||
|
defer p.builder.InlineTableEnd()
|
||||||
|
|
||||||
b = b[1:]
|
b = b[1:]
|
||||||
|
|
||||||
first := true
|
first := true
|
||||||
@@ -273,6 +278,7 @@ func (p parser) parseInlineTable(b []byte) ([]byte, error) {
|
|||||||
|
|
||||||
first = false
|
first = false
|
||||||
}
|
}
|
||||||
|
|
||||||
return expect('}', b)
|
return expect('}', b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -121,6 +121,23 @@ func (u *unmarshaler) ArrayTableEnd() {
|
|||||||
u.arrayTableKey = u.arrayTableKey[:0]
|
u.arrayTableKey = u.arrayTableKey[:0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *unmarshaler) InlineTableBegin() {
|
||||||
|
if u.skipping() || u.err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *unmarshaler) InlineTableEnd() {
|
||||||
|
if u.skipping() || u.err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
func (u *unmarshaler) KeyValBegin() {
|
func (u *unmarshaler) KeyValBegin() {
|
||||||
if u.skipKeyValCount > 0 {
|
if u.skipKeyValCount > 0 {
|
||||||
u.skipKeyValCount++
|
u.skipKeyValCount++
|
||||||
|
|||||||
Reference in New Issue
Block a user