summaryrefslogtreecommitdiff
path: root/_test/test_string.py
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2017-04-04 10:05:01 +0200
committerAnthon van der Neut <anthon@mnt.org>2017-04-04 10:05:01 +0200
commit334c46400c2334b3939c76ab7a7b5d9195b6d131 (patch)
tree1f92afaffb8689b508234157a179f40df3b84856 /_test/test_string.py
parent106d8df15be91d294b6a6efd4476fdc87c0a9b5d (diff)
downloadruamel.yaml-334c46400c2334b3939c76ab7a7b5d9195b6d131.tar.gz
fix issue #109 and #110
issue 109: None not represented round-trippable at top level, reported by Andrea Censi issue 110: .replace() on a ScalarString subclass would return a string instead of an instance of that subclass, reported by sandres23
Diffstat (limited to '_test/test_string.py')
-rw-r--r--_test/test_string.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/_test/test_string.py b/_test/test_string.py
index 13474b5..6b3070f 100644
--- a/_test/test_string.py
+++ b/_test/test_string.py
@@ -17,6 +17,7 @@ and the chomping modifiers:
import pytest
import platform
+import ruamel
# from ruamel.yaml.compat import ordereddict
from roundtrip import round_trip, dedent, round_trip_load, round_trip_dump # NOQA
@@ -124,3 +125,33 @@ class TestQuotedScalarString:
""", outp="""
a: abc
""")
+
+
+class TestReplace:
+ """inspired by issue 110 from sandres23"""
+ def test_replace_preserved_scalar_string(self):
+ s = dedent("""\
+ foo: |
+ foo
+ foo
+ bar
+ foo
+ """)
+ data = round_trip_load(s, preserve_quotes=True)
+ so = data['foo'].replace('foo', 'bar', 2)
+ assert isinstance(so, ruamel.yaml.scalarstring.PreservedScalarString)
+ assert so == dedent("""
+ bar
+ bar
+ bar
+ foo
+ """)
+
+ def test_replace_double_quoted_scalar_string(self):
+ s = dedent("""\
+ foo: "foo foo bar foo"
+ """)
+ data = round_trip_load(s, preserve_quotes=True)
+ so = data['foo'].replace('foo', 'bar', 2)
+ assert isinstance(so, ruamel.yaml.scalarstring.DoubleQuotedScalarString)
+ assert so == 'bar bar bar foo'