Skip to content

Commit

Permalink
Add tests covering nested values
Browse files Browse the repository at this point in the history
  • Loading branch information
ravron committed Oct 29, 2021
1 parent 14e9811 commit 3099691
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions ini_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1562,3 +1562,75 @@ Eu feugiat pretium nibh ipsum consequat nisl vel pretium lectus. Habitant morbi
testData.Value3,
)
}

func Test_NestedValuesSpanningSections(t *testing.T) {
t.Run("basic nested value", func(t *testing.T) {
f, err := LoadSources(LoadOptions{
AllowNestedValues: true,
}, []byte(`
[section]
key1 = value1
key2 =
nested1 = nestedvalue1
`))
require.NoError(t, err)
require.NotNil(t, f)

assert.Equal(t, "value1", f.Section("section").Key("key1").String())
assert.Equal(t, "", f.Section("section").Key("key2").String())
assert.Equal(t, []string{"nested1 = nestedvalue1"}, f.Section("section").Key("key2").NestedValues())
})

t.Run("no nested values", func(t *testing.T) {
f, err := LoadSources(LoadOptions{
AllowNestedValues: true,
}, []byte(`
[section]
key1 = value1
key2 =
`))
require.NoError(t, err)
require.NotNil(t, f)

assert.Equal(t, "value1", f.Section("section").Key("key1").String())
assert.Equal(t, "", f.Section("section").Key("key2").String())
})

t.Run("no nested values and following sections", func(t *testing.T) {
f, err := LoadSources(LoadOptions{
AllowNestedValues: true,
}, []byte(`
[section]
key1 = value1
key2 =
[section2]
key3 = value3
`))
require.NoError(t, err)
require.NotNil(t, f)

assert.Equal(t, "value1", f.Section("section").Key("key1").String())
assert.Equal(t, "", f.Section("section").Key("key2").String())
assert.Equal(t, "value3", f.Section("section2").Key("key3").String())
})

t.Run("no nested values and following sections with indentation", func(t *testing.T) {
f, err := LoadSources(LoadOptions{
AllowNestedValues: true,
}, []byte(`
[section]
key1 = value1
key2 =
[section2]
key3 = value3
`))
require.NoError(t, err)
require.NotNil(t, f)

assert.Equal(t, "value1", f.Section("section").Key("key1").String())
assert.Equal(t, "", f.Section("section").Key("key2").String())
assert.Equal(t, "value3", f.Section("section2").Key("key3").String())
})
}

0 comments on commit 3099691

Please sign in to comment.