summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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):