bug 1419782, .inc files only use one whitespace to separate key and value, r=stas
authorAxel Hecht <axel@pike.org>
Wed, 22 Nov 2017 16:37:15 +0100
changeset 378 bcb7487741d704009e9e51111c02734a29e7ba59
parent 376 29f31c246afcf0658678a8e241245db6e85692d8
child 379 3b8f6fe771648219abe02206f17e2b5b1478bc5f
push id132
push useraxel@mozilla.com
push dateThu, 23 Nov 2017 09:29:09 +0000
reviewersstas
bugs1419782
bug 1419782, .inc files only use one whitespace to separate key and value, r=stas MozReview-Commit-ID: GpSf7ScN7Rl
compare_locales/parser.py
compare_locales/tests/test_defines.py
--- a/compare_locales/parser.py
+++ b/compare_locales/parser.py
@@ -481,18 +481,20 @@ class DefinesParser(Parser):
     capabilities = CAN_COPY
     reWhitespace = re.compile('\n+', re.M)
 
     EMPTY_LINES = 1 << 0
     PAST_FIRST_LINE = 1 << 1
 
     def __init__(self):
         self.reComment = re.compile('(?:^# .*?\n)*(?:^# [^\n]*)', re.M)
+        # corresponds to
+        # https://hg.mozilla.org/mozilla-central/file/72ee4800d4156931c89b58bd807af4a3083702bb/python/mozbuild/mozbuild/preprocessor.py#l561  # noqa
         self.reKey = re.compile(
-            '#define[ \t]+(?P<key>\w+)(?:[ \t]+(?P<val>[^\n]*))?', re.M)
+            '#define[ \t]+(?P<key>\w+)(?:[ \t](?P<val>[^\n]*))?', re.M)
         self.rePI = re.compile('#(?P<val>\w+[ \t]+[^\n]+)', re.M)
         Parser.__init__(self)
 
     def getNext(self, ctx, offset):
         contents = ctx.contents
 
         m = self.reWhitespace.match(contents, offset)
         if m:
--- a/compare_locales/tests/test_defines.py
+++ b/compare_locales/tests/test_defines.py
@@ -164,11 +164,28 @@ class TestDefinesParser(ParserTestMixin,
 
         defines.inc are interesting that way, as their
         content is added to the generated file.
         '''
         self._test('\n', (('Junk', '\n'),))
         self._test('\n\n', (('Junk', '\n\n'),))
         self._test(' \n\n', (('Junk', ' \n\n'),))
 
+    def test_whitespace_value(self):
+        '''Test that there's only one whitespace between key and value
+        '''
+        # funny formatting of trailing whitespace to make it explicit
+        # and flake-8 happy
+        self._test('''\
+#define one \n\
+#define two  \n\
+#define tre   \n\
+''', (
+            ('one', ''),
+            ('Whitespace', '\n'),
+            ('two', ' '),
+            ('Whitespace', '\n'),
+            ('tre', '  '),
+            ('Whitespace', '\n'),))
+
 
 if __name__ == '__main__':
     unittest.main()