From 93a74fca35a9a0706b67abeb7e8c2a3cad4eaad8 Mon Sep 17 00:00:00 2001 From: Thomas Pelletier Date: Mon, 8 Mar 2021 21:59:43 -0500 Subject: [PATCH] todo: inline tables --- .../imported_tests/unmarshal_imported_test.go | 24 ++++++------------- parser.go | 6 +++++ unmarshal.go | 17 +++++++++++++ 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/internal/imported_tests/unmarshal_imported_test.go b/internal/imported_tests/unmarshal_imported_test.go index 911c3a9..7a48324 100644 --- a/internal/imported_tests/unmarshal_imported_test.go +++ b/internal/imported_tests/unmarshal_imported_test.go @@ -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) { diff --git a/parser.go b/parser.go index 081b179..8ea8b11 100644 --- a/parser.go +++ b/parser.go @@ -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) } diff --git a/unmarshal.go b/unmarshal.go index 58cdfac..84ee28d 100644 --- a/unmarshal.go +++ b/unmarshal.go @@ -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++