bug 1419782, .inc files only use one whitespace to separate key and value, r=stas
MozReview-Commit-ID: GpSf7ScN7Rl
--- 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()