From ebcc662f6650a1a3f613857d8e27f90390e37e72 Mon Sep 17 00:00:00 2001 From: xukesong Date: Sun, 23 Jul 2023 01:09:26 +0800 Subject: [PATCH] Add "IsPathShadowedInFlatMap" method unit test --- viper_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/viper_test.go b/viper_test.go index e0bfc57..34faf53 100644 --- a/viper_test.go +++ b/viper_test.go @@ -2679,6 +2679,31 @@ func TestSliceIndexAccess(t *testing.T) { assert.Equal(t, "Static", v.GetString("tv.0.episodes.1.2")) } +func TestIsPathShadowedInFlatMap(t *testing.T) { + v := New() + + stringMap := map[string]string{ + "foo": "value", + } + + flagMap := map[string]FlagValue{ + "foo": pflagValue{}, + } + + path1 := []string{"foo", "bar"} + expected1 := "foo" + + // "foo.bar" should shadowed by"foo" + assert.Equal(t, expected1, v.isPathShadowedInFlatMap(path1, stringMap)) + assert.Equal(t, expected1, v.isPathShadowedInFlatMap(path1, flagMap)) + + path2 := []string{"bar", "foo"} + expected2 := "" + // "bar.foo" should not shadowed by "foo" + assert.Equal(t, expected2, v.isPathShadowedInFlatMap(path2, stringMap)) + assert.Equal(t, expected2, v.isPathShadowedInFlatMap(path2, flagMap)) +} + func BenchmarkGetBool(b *testing.B) { key := "BenchmarkGetBool" v = New()