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/+/2231286
Reviewed-by: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: Dirk Pranke <dpranke@chromium.org>
Commit-Queue: Ben Pastene <bpastene@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#775299}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: b75f8eca53df514c5b9ff8ee3252793a32da92e3
This commit is contained in:
Ben Pastene 2020-06-04 22:09:28 +00:00 коммит произвёл Commit Bot
Родитель a718a6e94a
Коммит 68335d574e
2 изменённых файлов: 9 добавлений и 3 удалений

Просмотреть файл

@ -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]'),