Index: third_party/closure_compiler/runner/test/com/google/javascript/jscomp/ChromePassTest.java |
diff --git a/third_party/closure_compiler/runner/test/com/google/javascript/jscomp/ChromePassTest.java b/third_party/closure_compiler/runner/test/com/google/javascript/jscomp/ChromePassTest.java |
index 73675705e0a7ccf0d8791cc8df9efb9b429eeae5..4180e55483aa63122851bc215d07e8b496022db1 100644 |
--- a/third_party/closure_compiler/runner/test/com/google/javascript/jscomp/ChromePassTest.java |
+++ b/third_party/closure_compiler/runner/test/com/google/javascript/jscomp/ChromePassTest.java |
@@ -363,4 +363,104 @@ public class ChromePassTest extends CompilerTestCase { |
test("cr.exportPath();", null, ChromePass.CR_EXPORT_PATH_WRONG_NUMBER_OF_ARGUMENTS); |
} |
+ public void testCrMakePublicWorksOnOneMethod() throws Exception { |
+ test( |
+ "/** @constructor */\n" + |
+ "Class = function() {};\n" + |
+ "\n" + |
+ "Class.prototype = {\n" + |
+ " /** @return {number} */\n" + |
+ " method_: function() { return 42; }\n" + |
+ "};\n" + |
+ "\n" + |
+ "cr.makePublic(Class, ['method']);", |
+ "/** @constructor */\n" + |
+ "Class = function() {};\n" + |
+ "\n" + |
+ "Class.prototype = {\n" + |
+ " /** @return {number} */\n" + |
+ " method_: function() { return 42; }\n" + |
+ "};\n" + |
+ "\n" + |
+ "/** @return {number} */\n" + |
+ "Class.method;\n" + |
+ "\n" + |
+ "cr.makePublic(Class, ['method']);"); |
+ } |
+ |
+ public void testCrMakePublicWorksOnTwoMethods() throws Exception { |
+ test( |
+ "/** @constructor */\n" + |
+ "Class = function() {}\n" + |
+ "\n" + |
+ "Class.prototype = {\n" + |
+ " /** @return {number} */\n" + |
+ " m1_: function() { return 42; },\n" + |
+ "\n" + |
+ " /** @return {string} */\n" + |
+ " m2_: function() { return ''; }\n" + |
+ "};\n" + |
+ "\n" + |
+ "cr.makePublic(Class, ['m1', 'm2']);", |
+ "/** @constructor */\n" + |
+ "Class = function() {}\n" + |
+ "\n" + |
+ "Class.prototype = {\n" + |
+ " /** @return {number} */\n" + |
+ " m1_: function() { return 42; },\n" + |
+ "\n" + |
+ " /** @return {string} */\n" + |
+ " m2_: function() { return ''; }\n" + |
+ "}\n" + |
+ "\n" + |
+ "/** @return {number} */\n" + |
+ "Class.m1;\n" + |
+ "\n" + |
+ "/** @return {string} */\n" + |
+ "Class.m2;\n" + |
+ "\n" + |
+ "cr.makePublic(Class, ['m1', 'm2']);"); |
+ } |
+ |
+ public void testCrMakePublicRequiresMethodsToHaveJSDoc() throws Exception { |
+ test("/** @constructor */\n" + |
+ "Class = function() {}\n" + |
+ "\n" + |
+ "Class.prototype = {\n" + |
+ " method_: function() {}\n" + |
+ "}\n" + |
+ "\n" + |
+ "cr.makePublic(Class, ['method']);", null, ChromePass.CR_MAKE_PUBLIC_HAS_NO_JSDOC); |
+ } |
+ |
+ public void testCrMakePublicDoesNothingWithMethodsNotInAPI() throws Exception { |
+ test("/** @constructor */\n" + |
+ "Class = function() {}\n" + |
+ "\n" + |
+ "Class.prototype = {\n" + |
+ " method_: function() {}\n" + |
+ "}\n" + |
+ "\n" + |
+ "cr.makePublic(Class, []);", |
+ "/** @constructor */\n" + |
+ "Class = function() {}\n" + |
+ "\n" + |
+ "Class.prototype = {\n" + |
+ " method_: function() {}\n" + |
+ "}\n" + |
+ "\n" + |
+ "cr.makePublic(Class, []);"); |
+ } |
+ |
+ public void testCrMakePublicRequiresExportedMethodToBeDeclared() throws Exception { |
+ test("/** @constructor */\n" + |
+ "Class = function() {}\n" + |
+ "\n" + |
+ "Class.prototype = {\n" + |
+ "}\n" + |
+ "\n" + |
+ "cr.makePublic(Class, ['method']);", null, |
+ ChromePass.CR_MAKE_PUBLIC_MISSED_DECLARATION); |
+ } |
+ |
} |