Skip to content

Commit

Permalink
feat(amber): indent multiline strings, close #193
Browse files Browse the repository at this point in the history
  • Loading branch information
Noah Negin-Ulster committed Apr 17, 2020
1 parent 1750d03 commit 80468e7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/syrupy/extensions/amber.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ def serialize_string(
if "\n" in data:
return (
cls.with_indent("'\n", depth)
+ str(data)
+ "".join(
cls.with_indent(line, depth + 1 if depth else depth)
for line in str(data).splitlines(keepends=True)
)
+ "\n"
+ cls.with_indent("'", depth)
)
Expand Down
15 changes: 13 additions & 2 deletions tests/__snapshots__/test_extension_amber.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@
'd': ...,
}
---
# name: test_deeply_nested_list_in_dict
<class 'dict'> {
'value_a': <class 'dict'> {
'value_b': '
line 1
line 2
line 3
',
},
}
---
# name: test_dict[actual0]
<class 'dict'> {
'a': <class 'dict'> {
Expand Down Expand Up @@ -142,8 +153,8 @@
# name: test_list_in_dict
<class 'dict'> {
'value': '
line 1
line 2
line 1
line 2
',
}
---
Expand Down
6 changes: 6 additions & 0 deletions tests/test_extension_amber.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ def test_list_in_dict(snapshot):
assert {"value": lines} == snapshot


def test_deeply_nested_list_in_dict(snapshot):
lines = "\n".join(["line 1", "line 2", "line 3"])
d = {"value_a": {"value_b": lines}}
assert d == snapshot


@pytest.mark.parametrize("actual", [False, True])
def test_bool(actual, snapshot):
assert actual == snapshot
Expand Down

0 comments on commit 80468e7

Please sign in to comment.