Commit b75f8eca authored by Ben Pastene's avatar Ben Pastene Committed by Commit Bot

gn_helpers: Correctly handle comments followed by whitespace lines.

Without the fix, the modified unittest fails with:
"GNError: Expected an identifier"

With the fix, the unittest passes.

Bug: 1091082, 937821
Change-Id: I32591c64945dd918dfc341c8327fd530058b90ce
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2231286Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarDirk Pranke <dpranke@chromium.org>
Commit-Queue: Ben Pastene <bpastene@chromium.org>
Cr-Commit-Position: refs/heads/master@{#775299}
parent dc458d28
......@@ -284,6 +284,7 @@ class GNValueParser(object):
val = self._ParseAllowTrailing()
self.ConsumeWhitespace()
self.ConsumeComment()
self.ConsumeWhitespace()
d[ident] = val
return d
......
......@@ -93,10 +93,15 @@ class UnitTest(unittest.TestCase):
gn_args_lines = [
'# Top-level comment.',
'foo = true',
'bar = 1 # In-line comment.',
'bar = 1 # In-line comment followed by whitespace.',
' ',
'baz = false',
]
self.assertEqual(gn_helpers.FromGNArgs('\n'.join(gn_args_lines)),
{'foo': True, 'bar': 1})
self.assertEqual(gn_helpers.FromGNArgs('\n'.join(gn_args_lines)), {
'foo': True,
'bar': 1,
'baz': False
})
# Lists should work.
self.assertEqual(gn_helpers.FromGNArgs('foo=[1, 2, 3]'),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment