summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2018-08-12 17:35:24 +0200
committerAnthon van der Neut <anthon@mnt.org>2018-08-12 17:35:24 +0200
commitbf95947e11492f1060819036694daed38237d10e (patch)
tree10379f559c2192fb07809579799dc9225d2a8521
parent21ddf0cc5db2ef31a2852308f6c5926521b5b3a7 (diff)
downloadruamel.yaml-bf95947e11492f1060819036694daed38237d10e.tar.gz
fix issue #163 comment disappearing in list before flow mapping
should be fixed in 0.15.54 *When this change indeed resolves your problem, please **Close** this issue*. *(You can do so usingthe WorkFlow pull-down (close to the top right of this page)*
-rw-r--r--_test/test_issues.py15
-rw-r--r--parser.py9
-rw-r--r--tokens.py4
3 files changed, 22 insertions, 6 deletions
diff --git a/_test/test_issues.py b/_test/test_issues.py
index 1793edb..7e95857 100644
--- a/_test/test_issues.py
+++ b/_test/test_issues.py
@@ -46,7 +46,7 @@ class TestIssues:
""")
for comment in ['', ' # no-newline', ' # some comment\n', '\n', ]:
s = yaml_str.format(comment)
- res = round_trip(s)
+ res = round_trip(s) # NOQA
def test_issue_161a(self):
yaml_str = dedent("""\
@@ -56,7 +56,12 @@ class TestIssues:
""")
for comment in ['\n# between']:
s = yaml_str.format(comment)
- res = round_trip(s)
- # print(s)
- # print('------------')
- # assert False
+ res = round_trip(s) # NOQA
+
+ def test_issue_163(self):
+ s = dedent("""\
+ some-list:
+ # List comment
+ - {}
+ """)
+ x = round_trip(s, preserve_quotes=True) # NOQA
diff --git a/parser.py b/parser.py
index 0707761..61ff673 100644
--- a/parser.py
+++ b/parser.py
@@ -434,9 +434,16 @@ class Parser(object):
)
self.state = self.parse_flow_sequence_first_entry
elif self.scanner.check_token(FlowMappingStartToken):
+ pt = self.scanner.peek_token()
end_mark = self.scanner.peek_token().end_mark
event = MappingStartEvent(
- anchor, tag, implicit, start_mark, end_mark, flow_style=True
+ anchor,
+ tag,
+ implicit,
+ start_mark,
+ end_mark,
+ flow_style=True,
+ comment=pt.comment,
)
self.state = self.parse_flow_mapping_first_key
elif block and self.scanner.check_token(BlockSequenceStartToken):
diff --git a/tokens.py b/tokens.py
index 72c4f48..5176520 100644
--- a/tokens.py
+++ b/tokens.py
@@ -27,6 +27,10 @@ class Token(object):
arguments += u', line: ' + str(self.start_mark.line)
except: # NOQA
pass
+ try:
+ arguments += u', comment: ' + str(self._comment)
+ except: # NOQA
+ pass
return u'{}({})'.format(self.__class__.__name__, arguments)
def add_post_comment(self, comment):