summaryrefslogtreecommitdiffstats
path: root/PRESUBMIT_test.py
diff options
context:
space:
mode:
authordbeam@chromium.org <dbeam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-18 04:35:41 +0000
committerdbeam@chromium.org <dbeam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-18 04:35:41 +0000
commita817dd22fa288770d7397447536eb8dc193385a1 (patch)
treee941420ff50ac6b69132ce7b61013465e3f0a087 /PRESUBMIT_test.py
parentb7a15072083c52f0f61bb47ccd6d6ce14677da6c (diff)
downloadchromium_src-a817dd22fa288770d7397447536eb8dc193385a1.zip
chromium_src-a817dd22fa288770d7397447536eb8dc193385a1.tar.gz
chromium_src-a817dd22fa288770d7397447536eb8dc193385a1.tar.bz2
Adds PRESUBMIT.py check to look for unprefixed string16.
R=maruel@chromium.org BUG=329295 TEST=PRESUBMIT_test.py NOTRY=true Review URL: https://codereview.chromium.org/98143005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@241485 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'PRESUBMIT_test.py')
-rwxr-xr-xPRESUBMIT_test.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/PRESUBMIT_test.py b/PRESUBMIT_test.py
index 1c7990c..9c455e9 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 = [