# HG changeset patch # User Franz Glasner # Date 1653912520 -7200 # Node ID b97e5f3bbc8eba0d4c69d3bfc13a46f8fdd27740 # Parent 6102b767fc696e1a7a40fb63ca12e5e53e957665 Test indexed list access in variable interpolations: ok. Also drop an extra note into the documentation. diff -r 6102b767fc69 -r b97e5f3bbc8e docs/introduction.rst --- a/docs/introduction.rst Mon May 30 13:23:53 2022 +0200 +++ b/docs/introduction.rst Mon May 30 14:08:40 2022 +0200 @@ -301,6 +301,8 @@ - Encode the index number to string format using the ``~INDEX~`` syntax and use :py:meth:`~.Configuration.getvar` and its friends. + This syntax is also supported for variable interpolations. + Negative indexes are supported with Python semantics. Examples: diff -r 6102b767fc69 -r b97e5f3bbc8e tests/data/index-access-for-jails.yml --- a/tests/data/index-access-for-jails.yml Mon May 30 13:23:53 2022 +0200 +++ b/tests/data/index-access-for-jails.yml Mon May 30 14:08:40 2022 +0200 @@ -9,3 +9,6 @@ - entry: 0 - entry: 1 - entry: 2 + +expand-me: '{{the-list.~1~.entry}}' +expand-me-2: '{{the-list.~-1~.entry}}' diff -r 6102b767fc69 -r b97e5f3bbc8e tests/test.py --- a/tests/test.py Mon May 30 13:23:53 2022 +0200 +++ b/tests/test.py Mon May 30 14:08:40 2022 +0200 @@ -981,6 +981,12 @@ 2, cfg.getvar_s(u"the-list.~%d~.entry" % (-1, ))) + def test53_expand_an_indexed_substitution(self): + cfg = self._load(os.path.join(TESTDATADIR, + "index-access-for-jails.yml")) + self.assertEqual(1, cfg.getvar_s(u"expand-me")) + self.assertEqual(2, cfg.getvar_s(u"expand-me-2")) + class T02LoadAndMerge(_T02MixinLoadAndMerge, unittest.TestCase):