MCPcopy
hub / github.com/spf13/viper / TestSliceIndexAccess

Function TestSliceIndexAccess

viper_test.go:2575–2597  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2573`)
2574
2575func TestSliceIndexAccess(t *testing.T) {
2576 v := New()
2577 v.SetConfigType("yaml")
2578 r := strings.NewReader(string(yamlDeepNestedSlices))
2579
2580 err := v.unmarshalReader(r, v.config)
2581 require.NoError(t, err)
2582
2583 assert.Equal(t, "The Expanse", v.GetString("tv.0.title"))
2584 assert.Equal(t, "February 1, 2017", v.GetString("tv.0.seasons.1.first_released"))
2585 assert.Equal(t, "Static", v.GetString("tv.0.seasons.1.episodes.2.title"))
2586 assert.Equal(t, "December 15, 2015", v.GetString("tv.0.seasons.0.episodes.1.air_date"))
2587
2588 // Test nested keys with capital letters
2589 assert.Equal(t, "The Expanse", v.GetString("tv.0.title_i18n.USA"))
2590 assert.Equal(t, "エクスパンス -巨獣めざめる-", v.GetString("tv.0.title_i18n.Japan"))
2591
2592 // Test for index out of bounds
2593 assert.Equal(t, "", v.GetString("tv.0.seasons.2.first_released"))
2594
2595 // Accessing multidimensional arrays
2596 assert.Equal(t, "Static", v.GetString("tv.0.episodes.1.2"))
2597}
2598
2599func TestIsPathShadowedInFlatMap(t *testing.T) {
2600 v := New()

Callers

nothing calls this directly

Calls 4

NewFunction · 0.85
SetConfigTypeMethod · 0.80
unmarshalReaderMethod · 0.80
GetStringMethod · 0.80

Tested by

no test coverage detected