todo: inline tables

This commit is contained in:
Thomas Pelletier
2021-03-08 21:59:43 -05:00
parent a1c9b661b4
commit 93a74fca35
3 changed files with 30 additions and 17 deletions
@@ -1887,11 +1887,9 @@ func TestUnmarshalMixedTypeArray(t *testing.T) {
func TestUnmarshalArray(t *testing.T) {
var err error
var actual1 arrayStruct
err = toml.Unmarshal(sliceTomlDemo, &actual1)
if err != nil {
t.Error("shound not err", err)
}
var actual arrayStruct
err = toml.Unmarshal(sliceTomlDemo, &actual)
require.NoError(t, err)
expected := arrayStruct{
Slice: [4]string{"Howdy", "Hey There"},
@@ -1901,17 +1899,13 @@ func TestUnmarshalArray(t *testing.T) {
StructSlice: [4]basicMarshalTestSubStruct{{"1"}, {"2"}},
StructSlicePtr: &[4]basicMarshalTestSubStruct{{"1"}, {"2"}},
}
if !reflect.DeepEqual(actual1, expected) {
t.Errorf("Bad unmarshal: expected %v, got %v", expected, actual1)
}
assert.Equal(t, expected, actual)
}
func TestUnmarshalArrayFail(t *testing.T) {
var actual arrayTooSmallStruct
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)" {
t.Error("expect err:(0, 0): unmarshal: TOML array length (2) exceeds destination array length (1) but got ", err)
}
assert.Error(t, err)
}
func TestUnmarshalArrayFail2(t *testing.T) {
@@ -1919,9 +1913,7 @@ func TestUnmarshalArrayFail2(t *testing.T) {
var actual arrayTooSmallStruct
err := toml.Unmarshal([]byte(doc), &actual)
if err.Error() != "(1, 1): unmarshal: TOML array length (2) exceeds destination array length (1)" {
t.Error("expect err:(1, 1): unmarshal: TOML array length (2) exceeds destination array length (1) but got ", err)
}
assert.Error(t, err)
}
func TestUnmarshalArrayFail3(t *testing.T) {
@@ -1932,9 +1924,7 @@ String2="2"`
var actual arrayTooSmallStruct
err := toml.Unmarshal([]byte(doc), &actual)
if err.Error() != "(3, 1): unmarshal: TOML array length (2) exceeds destination array length (1)" {
t.Error("expect err:(3, 1): unmarshal: TOML array length (2) exceeds destination array length (1) but got ", err)
}
assert.Error(t, err)
}
func TestDecoderStrict(t *testing.T) {
+6
View File
@@ -23,6 +23,8 @@ type builder interface {
ArrayBegin()
ArrayEnd()
Assignation()
InlineTableBegin()
InlineTableEnd()
StringValue(v []byte)
BoolValue(b bool)
@@ -249,6 +251,9 @@ func (p parser) parseInlineTable(b []byte) ([]byte, error) {
//inline-table-sep = ws %x2C ws ; , Comma
//inline-table-keyvals = keyval [ inline-table-sep inline-table-keyvals ]
p.builder.InlineTableBegin()
defer p.builder.InlineTableEnd()
b = b[1:]
first := true
@@ -273,6 +278,7 @@ func (p parser) parseInlineTable(b []byte) ([]byte, error) {
first = false
}
return expect('}', b)
}
+17
View File
@@ -121,6 +121,23 @@ func (u *unmarshaler) ArrayTableEnd() {
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() {
if u.skipKeyValCount > 0 {
u.skipKeyValCount++