Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Unified Diff: PRESUBMIT_test.py

Issue 98143005: Adds PRESUBMIT.py check to look for unprefixed string16. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « PRESUBMIT.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: PRESUBMIT_test.py
diff --git a/PRESUBMIT_test.py b/PRESUBMIT_test.py
index 1c7990ce898bb824b1b7068d7787826b9250a0d1..9c455e90924cb3038e8e0873f50e6bb6513cfa41 100755
--- a/PRESUBMIT_test.py
+++ b/PRESUBMIT_test.py
@@ -393,6 +393,46 @@ class InvalidOSMacroNamesTest(unittest.TestCase):
self.assertEqual(0, len(errors))
+class String16Test(unittest.TestCase):
+ def testUnprefixedGivesWarnings(self):
+ lines = ['string16 GetName() const;',
+ 'void SetName(const string16& name) OVERRIDE {}',
+ 'const string16& GetNameRef() const = 0;',
+ 'string16 name;',
+ 'string16 foo = ASCIIToUTF16("bar");',
+ 'string16 blah(ASCIIToUTF16("blee"));',
+ 'std::vector<string16> names;',
+ 'string16 var_with_string16_in_name;']
+ warnings = PRESUBMIT._CheckForString16InFile(
+ MockInputApi(), MockFile('chrome/browser/name_getter_bad.cc', lines))
+ self.assertEqual(len(lines), len(warnings))
+
+ def testPrefixedSkipped(self):
+ lines = ['#include "base/strings/string16.h"',
+ 'void SetName(const base::string16& name) OVERRIDE {}',
+ 'const base::string16& GetNameRef() const = 0;',
+ 'base::string16 name;',
+ 'base::string16 foo = ASCIIToUTF16("bar");',
+ 'base::string16 blah(ASCIIToUTF16("blee"));',
+ 'std::vector<base::string16> names;',
+ 'base::string16 var_with_string16_in_name;']
+ warnings = PRESUBMIT._CheckForString16InFile(
+ MockInputApi(), MockFile('chrome/browser/name_getter_good.cc', lines))
+ self.assertEqual(0, len(warnings))
+
+ def testUsingYieldsNoWarnings(self):
+ lines = ['#include "base/strings/string16.h',
+ 'namespace {',
+ 'using base::string16;',
+ 'string16 SayHiOnlyToEd(const string16& name) {',
+ ' string16 first = name.substr(0, 2); // Only "Ed" gets a "Hi".',
+ ' return first == "Ed" ? first : string16();',
+ '}']
+ warnings = PRESUBMIT._CheckForString16InFile(
+ MockInputApi(), MockFile('chrome/browser/say_hi_to_ed.cc', lines))
+ self.assertEqual(0, len(warnings))
+
+
class CheckAddedDepsHaveTetsApprovalsTest(unittest.TestCase):
def testDepsFilesToCheck(self):
changed_lines = [
« no previous file with comments | « PRESUBMIT.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698