Index: chrome/common/extensions/api/PRESUBMIT_test.py |
diff --git a/chrome/common/extensions/api/PRESUBMIT_test.py b/chrome/common/extensions/api/PRESUBMIT_test.py |
index f14ea7ed5d245ef860c833e8e9beb74b945d6e6b..2ed28e2e1541d3f95be7abc87dfbf89da8e1e552 100755 |
--- a/chrome/common/extensions/api/PRESUBMIT_test.py |
+++ b/chrome/common/extensions/api/PRESUBMIT_test.py |
@@ -3,6 +3,7 @@ |
# Use of this source code is governed by a BSD-style license that can be |
# found in the LICENSE file. |
+import glob |
import json |
import os |
import subprocess |
@@ -22,40 +23,58 @@ class MockInputApi(object): |
def PresubmitLocalPath(self): |
return os.path.dirname(__file__) |
+ def ReadFile(self, filename, mode='rU'): |
+ with open(filename, mode=mode) as f: |
+ s = f.read() |
+ return s |
not at google - send to devlin
2013/09/10 22:51:21
just return f.read()?
Haojian Wu
2013/09/11 01:10:22
Done.
|
+ |
class JSONParsingTest(unittest.TestCase): |
def testSuccess(self): |
input_api = MockInputApi() |
- input_json = ''' |
-// This is a comment. |
-{ |
- "key1": ["value1", "value2"], |
- "key2": 3 // This is an inline comment. |
-} |
-''' |
+ filename = 'test_presubmit/valid_json.json' |
+ self.assertEqual(None, |
+ PRESUBMIT._GetJSONParseError(input_api, filename)) |
+ |
+ def testFailure(self): |
+ input_api = MockInputApi() |
+ expected_errors = [ |
+ 'Expecting property name: line 8 column 3 (char 16)', |
+ 'Invalid control character at: line 8 column 19 (char 32)', |
+ 'Expecting property name: line 8 column 23 (char 36)', |
+ 'Expecting , delimiter: line 8 column 12 (char 25)', |
+ ] |
+ for (offset, filename) in enumerate( |
not at google - send to devlin
2013/09/10 22:51:21
you don't need the parens around this. however, a
Haojian Wu
2013/09/11 01:10:22
Done.
|
+ sorted(glob.glob('test_presubmit/invalid_*.json'))): |
+ error = PRESUBMIT._GetJSONParseError(input_api, filename) |
+ self.assertEqual(expected_errors[offset], str(error)) |
+ |
+ |
+class IDLParsingTest(unittest.TestCase): |
+ def testSuccess(self): |
+ input_api = MockInputApi() |
+ filename = 'test_presubmit/valid_idl_basics.idl' |
self.assertEqual(None, |
- PRESUBMIT._GetJSONParseError(input_api, input_json)) |
+ PRESUBMIT._GetIDLParseError(input_api, filename)) |
def testFailure(self): |
input_api = MockInputApi() |
- input_json = '{ x }' |
- self.assertEqual('Expecting property name: line 1 column 2 (char 2)', |
- str(PRESUBMIT._GetJSONParseError(input_api, input_json))) |
- |
- input_json = '{ "hello": "world }' |
- self.assertEqual( |
- 'Unterminated string starting at: line 1 column 11 (char 11)', |
- str(PRESUBMIT._GetJSONParseError(input_api, input_json))) |
- |
- input_json = '{ "a": "b", "c": "d", }' |
- self.assertEqual( |
- 'Expecting property name: line 1 column 22 (char 22)', |
- str(PRESUBMIT._GetJSONParseError(input_api, input_json))) |
- |
- input_json = '{ "a": "b" "c": "d" }' |
- self.assertEqual( |
- 'Expecting , delimiter: line 1 column 11 (char 11)', |
- str(PRESUBMIT._GetJSONParseError(input_api, input_json))) |
+ expected_errors = [ |
+ 'Unexpected "{" after keyword "dictionary".', |
+ 'Unexpected symbol DOMString after symbol a.', |
+ 'Unexpected symbol name2 after symbol name1.', |
+ 'Trailing comma in block.', |
+ 'Unexpected ";" after "(".', |
+ 'Unexpected ")" after symbol long.', |
+ 'Unexpected symbol Events after symbol interace.', |
+ 'Did not process Interface Interface(NotEvent)', |
+ 'Interface missing name.' |
+ ] |
+ |
+ for (offset, filename) in enumerate( |
+ sorted(glob.glob('test_presubmit/invalid_*.idl'))): |
+ error = PRESUBMIT._GetIDLParseError(input_api, filename) |
+ self.assertTrue(expected_errors[offset] in error) |
not at google - send to devlin
2013/09/10 22:51:21
ditto
Haojian Wu
2013/09/11 01:10:22
Done.
|
if __name__ == "__main__": |