From 68335d574e34d8ac42c9edc58995dd5617561a40 Mon Sep 17 00:00:00 2001 From: Ben Pastene Date: Thu, 4 Jun 2020 22:09:28 +0000 Subject: [PATCH] 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 Reviewed-by: Dirk Pranke Commit-Queue: Ben Pastene Cr-Original-Commit-Position: refs/heads/master@{#775299} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: b75f8eca53df514c5b9ff8ee3252793a32da92e3 --- gn_helpers.py | 1 + gn_helpers_unittest.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/gn_helpers.py b/gn_helpers.py index f003c4b1a..9e24c79ad 100644 --- a/gn_helpers.py +++ b/gn_helpers.py @@ -284,6 +284,7 @@ class GNValueParser(object): val = self._ParseAllowTrailing() self.ConsumeWhitespace() self.ConsumeComment() + self.ConsumeWhitespace() d[ident] = val return d diff --git a/gn_helpers_unittest.py b/gn_helpers_unittest.py index b2ba47eb0..9356f6aea 100644 --- a/gn_helpers_unittest.py +++ b/gn_helpers_unittest.py @@ -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]'),