From a641c3b4e7e23ff4130f24a97551322a0798a464 Mon Sep 17 00:00:00 2001 From: Ricardo Souza Date: Fri, 17 Aug 2018 21:11:21 -0300 Subject: [PATCH] Added test for index notation in keys --- viper_test.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/viper_test.go b/viper_test.go index be11f3e..d2d9887 100644 --- a/viper_test.go +++ b/viper_test.go @@ -1400,6 +1400,39 @@ func TestParseNested(t *testing.T) { assert.Equal(t, 200*time.Millisecond, items[0].Nested.Delay) } +func TestGetMapSliceItemWithIndex(t *testing.T) { + type duration struct { + Delay time.Duration + } + + type item struct { + Name string + Delay time.Duration + Nested duration + } + + config := `[[parent]] + delay="100ms" + [parent.nested] + delay="200ms" + + [[parent]] + delay="200ms" + [parent.nested] + delay="400ms" +` + initConfig("toml", config) + + firstNestedDelay := v.GetDuration("parent[0].delay") + + assert.Equal(t, 100*time.Millisecond, firstNestedDelay) + + secondNestedDelay := v.GetDuration("parent[1].nested.delay") + + assert.Equal(t, 400*time.Millisecond, secondNestedDelay) + +} + func doTestCaseInsensitive(t *testing.T, typ, config string) { initConfig(typ, config) Set("RfD", true)