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

Unified Diff: third_party/closure_compiler/coding_conventions_test.py

Issue 421253006: Add ChromeCodingConvention.java to Closure Compiler to preserve getInstance() type (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@A_typechecking_about
Patch Set: final fixes Created 6 years, 5 months 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
Index: third_party/closure_compiler/coding_conventions_test.py
diff --git a/third_party/closure_compiler/coding_conventions_test.py b/third_party/closure_compiler/coding_conventions_test.py
new file mode 100755
index 0000000000000000000000000000000000000000..cc91231cee942f449b50d659d4a5554b401fc6df
--- /dev/null
+++ b/third_party/closure_compiler/coding_conventions_test.py
@@ -0,0 +1,52 @@
+#!/usr/bin/env python
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import unittest
+
+from checker import Checker, FileCache
+
+
+class CodingConventionTest(unittest.TestCase):
+ def __init__(self, *args, **kwargs):
+ unittest.TestCase.__init__(self, *args, **kwargs)
+ self.maxDiff = None
+
+ def setUp(self):
+ self._checker = Checker(verbose=False, exit_on_fatal=False)
+
+ def testGetInstance(self):
+ test_name = "getInstance"
+ file_content = """
+var cr = {
+ /** @param {!Function} ctor */
+ addSingletonGetter: function(ctor) {
+ ctor.getInstance = function() {
+ return ctor.instance_ || (ctor.instance_ = new ctor());
+ };
+ }
+};
+
+/** @constructor */
+function Class() {
+ /** @param {number} num */
+ this.needsNumber = function(num) {};
+}
+
+cr.addSingletonGetter(Class);
+Class.getInstance().needsNumber("wrong type");
+"""
+ expected_chunk = "WARNING - actual parameter 1 of Class.needsNumber does not match formal parameter"
+
+ file_path = "/script.js"
+ FileCache._cache[file_path] = file_content
+ _, output = self._checker.check(file_path)
+
+ self.assertTrue(expected_chunk in output,
+ msg="%s\n\nExpected chunk: \n%s\n\nOutput:\n%s\n" % (
+ test_name, expected_chunk, output))
+
+
+if __name__ == "__main__":
+ unittest.main()

Powered by Google App Engine
This is Rietveld 408576698