diff options
author | Anthon van der Neut <anthon@mnt.org> | 2018-08-20 12:40:40 +0200 |
---|---|---|
committer | Anthon van der Neut <anthon@mnt.org> | 2018-08-20 12:40:40 +0200 |
commit | ac0f2679a72d301c5d3bd4e5ad405e8c4728e910 (patch) | |
tree | 4f77620c2ba176786e16b05a5bb8ffad10a77b5f /_test | |
parent | 4135c567d24f4e152b7d1580a81031a034e2f5b6 (diff) | |
download | ruamel.yaml-ac0f2679a72d301c5d3bd4e5ad405e8c4728e910.tar.gz |
update and extend walk_tree, cover with test
Diffstat (limited to '_test')
-rw-r--r-- | _test/test_string.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/_test/test_string.py b/_test/test_string.py index e6449ac..5aba3ef 100644 --- a/_test/test_string.py +++ b/_test/test_string.py @@ -173,3 +173,43 @@ class TestReplace: so = data['foo'].replace('foo', 'bar', 2) assert isinstance(so, ruamel.yaml.scalarstring.DoubleQuotedScalarString) assert so == 'bar bar bar foo' + + +class TestWalkTree: + def test_basic(self): + from ruamel.yaml.comments import CommentedMap + from ruamel.yaml.scalarstring import walk_tree + data = CommentedMap() + data[1] = 'a' + data[2] = 'with\nnewline\n' + walk_tree(data) + exp = """\ + 1: a + 2: | + with + newline + """ + assert round_trip_dump(data) == dedent(exp) + + def test_map(self): + from ruamel.yaml.compat import ordereddict + from ruamel.yaml.comments import CommentedMap + from ruamel.yaml.scalarstring import walk_tree, preserve_literal + from ruamel.yaml.scalarstring import DoubleQuotedScalarString as dq + from ruamel.yaml.scalarstring import SingleQuotedScalarString as sq + data = CommentedMap() + data[1] = 'a' + data[2] = 'with\nnew : line\n' + data[3] = '${abc}' + data[4] = 'almost:mapping' + m = ordereddict([('\n', preserve_literal), ('${', sq), (':', dq)]) + walk_tree(data, map=m) + exp = """\ + 1: a + 2: | + with + new : line + 3: '${abc}' + 4: "almost:mapping" + """ + assert round_trip_dump(data) == dedent(exp) |