@@ -1585,3 +1585,75 @@ func TestPythonMultiline_EOF(t *testing.T) {
15851585 require .NoError (t , err )
15861586 assert .Equal (t , "some text here\n \t some more text here 2" , testData .Value1 )
15871587}
1588+
1589+ func Test_NestedValuesSpanningSections (t * testing.T ) {
1590+ t .Run ("basic nested value" , func (t * testing.T ) {
1591+ f , err := LoadSources (LoadOptions {
1592+ AllowNestedValues : true ,
1593+ }, []byte (`
1594+ [section]
1595+ key1 = value1
1596+ key2 =
1597+ nested1 = nestedvalue1
1598+ ` ))
1599+ require .NoError (t , err )
1600+ require .NotNil (t , f )
1601+
1602+ assert .Equal (t , "value1" , f .Section ("section" ).Key ("key1" ).String ())
1603+ assert .Equal (t , "" , f .Section ("section" ).Key ("key2" ).String ())
1604+ assert .Equal (t , []string {"nested1 = nestedvalue1" }, f .Section ("section" ).Key ("key2" ).NestedValues ())
1605+ })
1606+
1607+ t .Run ("no nested values" , func (t * testing.T ) {
1608+ f , err := LoadSources (LoadOptions {
1609+ AllowNestedValues : true ,
1610+ }, []byte (`
1611+ [section]
1612+ key1 = value1
1613+ key2 =
1614+ ` ))
1615+ require .NoError (t , err )
1616+ require .NotNil (t , f )
1617+
1618+ assert .Equal (t , "value1" , f .Section ("section" ).Key ("key1" ).String ())
1619+ assert .Equal (t , "" , f .Section ("section" ).Key ("key2" ).String ())
1620+ })
1621+
1622+ t .Run ("no nested values and following sections" , func (t * testing.T ) {
1623+ f , err := LoadSources (LoadOptions {
1624+ AllowNestedValues : true ,
1625+ }, []byte (`
1626+ [section]
1627+ key1 = value1
1628+ key2 =
1629+
1630+ [section2]
1631+ key3 = value3
1632+ ` ))
1633+ require .NoError (t , err )
1634+ require .NotNil (t , f )
1635+
1636+ assert .Equal (t , "value1" , f .Section ("section" ).Key ("key1" ).String ())
1637+ assert .Equal (t , "" , f .Section ("section" ).Key ("key2" ).String ())
1638+ assert .Equal (t , "value3" , f .Section ("section2" ).Key ("key3" ).String ())
1639+ })
1640+
1641+ t .Run ("no nested values and following sections with indentation" , func (t * testing.T ) {
1642+ f , err := LoadSources (LoadOptions {
1643+ AllowNestedValues : true ,
1644+ }, []byte (`
1645+ [section]
1646+ key1 = value1
1647+ key2 =
1648+
1649+ [section2]
1650+ key3 = value3
1651+ ` ))
1652+ require .NoError (t , err )
1653+ require .NotNil (t , f )
1654+
1655+ assert .Equal (t , "value1" , f .Section ("section" ).Key ("key1" ).String ())
1656+ assert .Equal (t , "" , f .Section ("section" ).Key ("key2" ).String ())
1657+ assert .Equal (t , "value3" , f .Section ("section2" ).Key ("key3" ).String ())
1658+ })
1659+ }
0 commit comments