Index: PRESUBMIT_test.py |
diff --git a/PRESUBMIT_test.py b/PRESUBMIT_test.py |
index 7f3ee91a4bbdbd2d71952a974c6e0e810ffdb21e..d49841808792fa4b8d37f90e302e521317f6f364 100755 |
--- a/PRESUBMIT_test.py |
+++ b/PRESUBMIT_test.py |
@@ -13,6 +13,120 @@ from PRESUBMIT_test_mocks import MockInputApi, MockOutputApi |
_TEST_DATA_DIR = 'base/test/data/presubmit' |
+class IncludeImportTest(unittest.TestCase): |
+ def testDetectObjectiveCHeaderInterface(self): |
+ content = ['# Copyright line', |
+ '', |
+ '@interface Class'] |
+ mock_input_api = MockInputApi() |
+ mock_name = 'some/ios/foo.h' |
+ mock_file = MockFile(mock_name, content) |
+ (detection_ok, is_objc) = \ |
+ PRESUBMIT._CheckHeaderIsObjectiveC(mock_input_api, mock_name, mock_file) |
+ self.assertEqual(detection_ok, True) |
+ self.assertEqual(is_objc, True) |
+ |
+ def testDetectObjectiveCNotIosMacFile(self): |
+ content = ['# Copyright line', |
+ '', |
+ '@interface Class'] |
+ mock_input_api = MockInputApi() |
+ mock_name = 'some/bar/foo.h' |
+ mock_file = MockFile(mock_name, content) |
+ (detection_ok, is_objc) = \ |
+ PRESUBMIT._CheckHeaderIsObjectiveC(mock_input_api, mock_name, mock_file) |
+ self.assertEqual(detection_ok, False) |
+ self.assertEqual(is_objc, False) |
+ |
+ |
+ def testDetectObjectiveCBlock(self): |
+ content = ['# Copyright line', |
+ '', |
+ 'typedef void (^ProceduralBlock)(void);'] |
+ mock_input_api = MockInputApi() |
+ mock_name = 'some/path/foo_mac.h' |
+ mock_file = MockFile(mock_name, content) |
+ (detection_ok, is_objc) = \ |
+ PRESUBMIT._CheckHeaderIsObjectiveC(mock_input_api, mock_name, mock_file) |
+ self.assertEqual(detection_ok, True) |
+ self.assertEqual(is_objc, True) |
+ |
+ def testDetectObjectiveCImport(self): |
+ content = ['# Copyright line', |
+ '', |
+ '#include "foo.h', |
+ '#include "bar.h', |
+ '#import "example.h', |
+ '#include "chromium.h'] |
+ mock_input_api = MockInputApi() |
+ mock_name = 'some/mac/foo.h' |
+ mock_file = MockFile(mock_name, content) |
+ (detection_ok, is_objc) = \ |
+ PRESUBMIT._CheckHeaderIsObjectiveC(mock_input_api, mock_name, mock_file) |
+ self.assertEqual(detection_ok, True) |
+ self.assertEqual(is_objc, True) |
+ |
+ def testDetectObjectiveCHeaderCPlusPlus(self): |
+ content = ['# Copyright line', |
+ '', |
+ '#include <cstdio>', |
+ 'class Foo'] |
+ mock_input_api = MockInputApi() |
+ mock_name = 'some/path/foo_ios.h' |
+ mock_file = MockFile(mock_name, content) |
+ (detection_ok, is_objc) = \ |
+ PRESUBMIT._CheckHeaderIsObjectiveC(mock_input_api, mock_name, mock_file) |
+ self.assertEqual(detection_ok, True) |
+ self.assertEqual(is_objc, False) |
+ |
+ def testDetectObjectiveCHeaderCPlusPlus(self): |
+ content = ['# Copyright line', |
+ '', |
+ '#if !defined(__OBJC__)', |
+ '#error "ObjectiveC required"', |
+ '#endif', |
+ '', |
+ '#include <cstdio>', |
+ 'class Foo'] |
+ mock_input_api = MockInputApi() |
+ mock_name = 'ios/path/foo.h' |
+ mock_file = MockFile(mock_name, content) |
+ (detection_ok, is_objc) = \ |
+ PRESUBMIT._CheckHeaderIsObjectiveC(mock_input_api, mock_name, mock_file) |
+ self.assertEqual(detection_ok, True) |
+ self.assertEqual(is_objc, True) |
+ |
+ def testDetectObjectiveCNoObjcGuard(self): |
+ content = ['# Copyright line', |
+ '', |
+ '#if !defined(__OBJC__)', |
+ '#include "foo.h"', |
+ '#else', |
+ '#import "foo.h"', |
+ '#endif'] |
+ mock_input_api = MockInputApi() |
+ mock_name = 'mac/path/foo.h' |
+ mock_file = MockFile(mock_name, content) |
+ (detection_ok, is_objc) = \ |
+ PRESUBMIT._CheckHeaderIsObjectiveC(mock_input_api, mock_name, mock_file) |
+ self.assertEqual(detection_ok, False) |
+ |
+ |
+ def testDetectObjectiveCNoObjcGuard(self): |
+ content = ['# Copyright line', |
+ '', |
+ '#if defined(__OBJC__)', |
+ '#import "foo.h"', |
+ '#else', |
+ '#include "foo.h"', |
+ '#endif'] |
+ mock_input_api = MockInputApi() |
+ mock_name = 'some/path_ios/foo.h' |
+ mock_file = MockFile(mock_name, content) |
+ (detection_ok, is_objc) = \ |
+ PRESUBMIT._CheckHeaderIsObjectiveC(mock_input_api, mock_name, mock_file) |
+ self.assertEqual(detection_ok, False) |
+ |
class IncludeOrderTest(unittest.TestCase): |
def testSystemHeaderOrder(self): |
scope = [(1, '#include <csystem.h>'), |