def testStringValues(self): test_data = """ // Single line string constants. const char kAString[] = "a-value"; const char kNoComment[] = "no-comment"; // Single line switch with a big space. const char kAStringWithSpace[] = "a-value"; // Wrapped constant definition. const char kAStringWithAVeryLongNameThatWillHaveToWrap[] = "a-string-with-a-very-long-name-that-will-have-to-wrap"; // This is erroneous and should be ignored. const char kInvalidLineBreak[] = "invalid-line-break"; """.split('\n') strings = java_cpp_strings.StringFileParser(test_data).Parse() self.assertEqual(4, len(strings)) self.assertEqual('A_STRING', strings[0].name) self.assertEqual('"a-value"', strings[0].value) self.assertEqual('NO_COMMENT', strings[1].name) self.assertEqual('"no-comment"', strings[1].value) self.assertEqual('A_STRING_WITH_SPACE', strings[2].name) self.assertEqual('"a-value"', strings[2].value) self.assertEqual('A_STRING_WITH_A_VERY_LONG_NAME_THAT_WILL_HAVE_TO_WRAP', strings[3].name) self.assertEqual('"a-string-with-a-very-long-name-that-will-have-to-wrap"', strings[3].value)
def testParseComments(self): test_data = """ /** * This should be ignored as well. */ // Comment followed by a blank line. // Comment followed by unrelated code. int foo() { return 3; } // Real comment. const char kASwitch[] = "a-value"; // Real comment that spans // multiple lines. const char kAnotherSwitch[] = "another-value"; // Comment followed by nothing. """.split('\n') strings = java_cpp_strings.StringFileParser(test_data).Parse() self.assertEqual(2, len(strings)) self.assertEqual('A_SWITCH', strings[0].name) self.assertEqual('"a-value"', strings[0].value) self.assertEqual(1, len(strings[0].comments.split('\n'))) self.assertEqual('ANOTHER_SWITCH', strings[1].name) self.assertEqual('"another-value"', strings[1].value) self.assertEqual(2, len(strings[1].comments.split('\n')))
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 testStringValues(self): test_data = r""" // Single line string constants. const char kAString[] = "a-value"; const char kNoComment[] = "no-comment"; namespace myfeature { const char kMyFeatureNoComment[] = "myfeature.no-comment"; } // Single line switch with a big space. const char kAStringWithSpace[] = "a-value"; // Wrapped constant definition. const char kAStringWithAVeryLongNameThatWillHaveToWrap[] = "a-string-with-a-very-long-name-that-will-have-to-wrap"; // This one has no comment before it. const char kAStringWithAVeryLongNameThatWillHaveToWrap2[] = "a-string-with-a-very-long-name-that-will-have-to-wrap2"; const char kStringWithEscapes[] = "tab\tquote\"newline\n"; const char kStringWithEscapes2[] = "tab\tquote\"newline\n"; const char kEmptyString[] = ""; // These are valid C++ but not currently supported by the script. const char kInvalidLineBreak[] = "invalid-line-break"; const char kConcatenateMultipleStringLiterals[] = "first line" "second line"; """.split('\n') strings = java_cpp_strings.StringFileParser(test_data).Parse() self.assertEqual(9, len(strings)) self.assertEqual('A_STRING', strings[0].name) self.assertEqual('"a-value"', strings[0].value) self.assertEqual('NO_COMMENT', strings[1].name) self.assertEqual('"no-comment"', strings[1].value) self.assertEqual('MY_FEATURE_NO_COMMENT', strings[2].name) self.assertEqual('"myfeature.no-comment"', strings[2].value) self.assertEqual('A_STRING_WITH_SPACE', strings[3].name) self.assertEqual('"a-value"', strings[3].value) self.assertEqual('A_STRING_WITH_A_VERY_LONG_NAME_THAT_WILL_HAVE_TO_WRAP', strings[4].name) self.assertEqual('"a-string-with-a-very-long-name-that-will-have-to-wrap"', strings[4].value) self.assertEqual('A_STRING_WITH_A_VERY_LONG_NAME_THAT_WILL_HAVE_TO_WRAP2', strings[5].name) self.assertEqual('"a-string-with-a-very-long-name-that-will-have-to-wrap2"', strings[5].value) self.assertEqual('STRING_WITH_ESCAPES', strings[6].name) self.assertEqual(r'"tab\tquote\"newline\n"', strings[6].value) self.assertEqual('STRING_WITH_ESCAPES2', strings[7].name) self.assertEqual(r'"tab\tquote\"newline\n"', strings[7].value) self.assertEqual('EMPTY_STRING', strings[8].name) self.assertEqual('""', strings[8].value)