Commit 001d80b0 authored by Nate Fischer's avatar Nate Fischer Committed by Commit Bot

Android: treat WebView like one word for java_cpp_utils

This lets java_cpp_enum and java_cpp_strings treat "WebView" like one
word. This also fixes an existing test in java_cpp_strings_tests.py.

Fixed: 1112005
Test: vpython build/android/gyp/java_cpp_strings_tests.py
Change-Id: Id9f1ca904b4d6c90ccc1a810033c5614a0514492
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2337735Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Commit-Queue: Nate Fischer <ntfschr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796445}
parent 0b7e4ced
...@@ -73,7 +73,7 @@ const char kInvalidLineBreak[] = ...@@ -73,7 +73,7 @@ const char kInvalidLineBreak[] =
"invalid-line-break"; "invalid-line-break";
""".split('\n') """.split('\n')
strings = java_cpp_strings.StringFileParser(test_data).Parse() strings = java_cpp_strings.StringFileParser(test_data).Parse()
self.assertEqual(5, len(strings)) self.assertEqual(6, len(strings))
self.assertEqual('A_STRING', strings[0].name) self.assertEqual('A_STRING', strings[0].name)
self.assertEqual('"a-value"', strings[0].value) self.assertEqual('"a-value"', strings[0].value)
self.assertEqual('NO_COMMENT', strings[1].name) self.assertEqual('NO_COMMENT', strings[1].name)
...@@ -91,6 +91,20 @@ const char kInvalidLineBreak[] = ...@@ -91,6 +91,20 @@ const char kInvalidLineBreak[] =
self.assertEqual('"a-string-with-a-very-long-name-that-will-have-to-wrap2"', self.assertEqual('"a-string-with-a-very-long-name-that-will-have-to-wrap2"',
strings[5].value) strings[5].value)
def testTreatWebViewLikeOneWord(self):
test_data = """
const char kSomeWebViewSwitch[] = "some-webview-switch";
const char kWebViewOtherSwitch[] = "webview-other-switch";
const char kSwitchWithPluralWebViews[] = "switch-with-plural-webviews";
""".split('\n')
strings = java_cpp_strings.StringFileParser(test_data).Parse()
self.assertEqual('SOME_WEBVIEW_SWITCH', strings[0].name)
self.assertEqual('"some-webview-switch"', strings[0].value)
self.assertEqual('WEBVIEW_OTHER_SWITCH', strings[1].name)
self.assertEqual('"webview-other-switch"', strings[1].value)
self.assertEqual('SWITCH_WITH_PLURAL_WEBVIEWS', strings[2].name)
self.assertEqual('"switch-with-plural-webviews"', strings[2].value)
def testTemplateParsing(self): def testTemplateParsing(self):
test_data = """ test_data = """
// Copyright {YEAR} The Chromium Authors. All rights reserved. // Copyright {YEAR} The Chromium Authors. All rights reserved.
......
...@@ -25,6 +25,8 @@ def KCamelToShouty(s): ...@@ -25,6 +25,8 @@ def KCamelToShouty(s):
return s return s
# Strip the leading k. # Strip the leading k.
s = re.sub(r'^k', '', s) s = re.sub(r'^k', '', s)
# Treat "WebView" like one word.
s = re.sub(r'WebView', r'Webview', s)
# Add _ between title words and anything else. # Add _ between title words and anything else.
s = re.sub(r'([^_])([A-Z][^A-Z_0-9]+)', r'\1_\2', s) s = re.sub(r'([^_])([A-Z][^A-Z_0-9]+)', r'\1_\2', s)
# Add _ between lower -> upper transitions. # Add _ between lower -> upper transitions.
......
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