From a577df2dbbb34a5049ecce78c67c2b385f215345 Mon Sep 17 00:00:00 2001 From: Thomas Pelletier Date: Thu, 18 Mar 2021 17:19:50 -0400 Subject: [PATCH] wip --- targets.go | 7 ++++- unmarshaler_test.go | 70 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/targets.go b/targets.go index 17e45f2..0b0401d 100644 --- a/targets.go +++ b/targets.go @@ -240,7 +240,12 @@ func scopeTableTarget(append bool, t target, name string) (target, error) { case reflect.Map: return scopeMap(x, name) case reflect.Slice: - return scopeSlice(append, t) + t, err := scopeSlice(append, t) + if err != nil { + return t, err + } + append = false + return scopeTableTarget(append, t, name) default: panic(fmt.Errorf("can't scope on a %s", x.Kind())) } diff --git a/unmarshaler_test.go b/unmarshaler_test.go index b061147..0a21132 100644 --- a/unmarshaler_test.go +++ b/unmarshaler_test.go @@ -452,6 +452,76 @@ B = "data"`, } }, }, + { + desc: "sub-table in array table", + input: `[[Fruits]] + Name = "apple" + + [Fruits.Physical] # subtable + Color = "red" + Shape = "round"`, + gen: func() test { + return test{ + target: &map[string]interface{}{}, + expected: &map[string]interface{}{ + "Fruits": []interface{}{ + map[string]interface{}{ + "Name": "apple", + "Physical": map[string]interface{}{ + "Color": "red", + "Shape": "round", + }, + }, + }, + }, + } + }, + }, + { + desc: "multiple sub-table in array tables", + input: `[[Fruits]] + Name = "apple" + + [[Fruits.Varieties]] # nested array of tables + Name = "red delicious" + + [[Fruits.Varieties]] + Name = "granny smith" + + [[Fruits]] + Name = "banana" + + [[Fruits.Varieties]] + Name = "plantain"`, + gen: func() test { + return test{ + target: &map[string]interface{}{}, + expected: &map[string]interface{}{ + "Fruits": []interface{}{ + map[string]interface{}{ + "Name": "apple", + "Varieties": []interface{}{ + map[string]interface{}{ + "Name": "red delicious", + }, + map[string]interface{}{ + "Name": "granny smith", + }, + }, + }, + map[string]interface{}{ + "Name": "banana", + "Varieties": []interface{}{ + map[string]interface{}{ + "Name": "plantain", + }, + }, + }, + }, + }, + } + }, + }, } for _, e := range examples {