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

Unified Diff: third_party/closure_compiler/runner/test/com/google/javascript/jscomp/ChromePassTest.java

Issue 557633002: Add public API generation with cr.makePublic() and handle it in compiler pass (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@H_options_errors_3
Patch Set: manually handle exported methods declared in base class Created 6 years, 3 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/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..7c096b155e31bc72b0e294b35b274e571c4febbb 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,166 @@ public class ChromePassTest extends CompilerTestCase {
test("cr.exportPath();", null, ChromePass.CR_EXPORT_PATH_WRONG_NUMBER_OF_ARGUMENTS);
}
+ public void testCrMakePublicWorksOnOneMethodDefinedInPrototypeObject() throws Exception {
+ test(
+ "/** @constructor */\n" +
+ "Class = function() {};\n" +
Dan Beam 2014/09/10 19:26:27 why are you doing this with global assignment rath
Vitaly Pavlenko 2014/09/10 20:25:21 Done.
+ "\n" +
+ "Class.prototype = {\n" +
+ " /** @return {number} */\n" +
Dan Beam 2014/09/10 19:26:27 @private?
Vitaly Pavlenko 2014/09/10 20:25:21 You mean, we should remove @private declaration fr
+ " 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" +
Dan Beam 2014/09/10 19:26:27 ident off
Vitaly Pavlenko 2014/09/10 20:25:21 Done.
+ "\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);
+ }
+
+ public void testCrMakePublicWorksOnOneMethodDefinedDirectlyOnPrototype() throws Exception {
+ test(
+ "/** @constructor */\n" +
+ "Class = function() {}\n" +
+ "\n" +
+ "/** @return {number} */\n" +
+ "Class.prototype.method_ = function() {};\n" +
+ "\n" +
+ "cr.makePublic(Class, ['method']);",
+ "/** @constructor */\n" +
+ "Class = function() {}\n" +
+ "\n" +
+ "/** @return {number} */\n" +
+ "Class.prototype.method_ = function() {};\n" +
+ "\n" +
+ "/** @return {number} */\n" +
+ "Class.method;\n" +
+ "\n" +
+ "cr.makePublic(Class, ['method']);");
+ }
+
Dan Beam 2014/09/10 19:26:27 what about the case of: function Class() {
Vitaly Pavlenko 2014/09/10 20:25:21 Looks like there's no such case right now in Chrom
Dan Beam 2014/09/12 00:57:51 that's fine
Vitaly Pavlenko 2014/09/12 18:38:07 Acknowledged.
+ public void testCrMakePublicWorksOnDummyDeclaration() throws Exception {
+ test(
+ "/** @constructor */\n" +
+ "Class = function() {}\n" +
+ "\n" +
+ "/** @return {number} */\n" +
+ "Class.prototype.method_;\n" +
+ "\n" +
+ "cr.makePublic(Class, ['method']);",
+ "/** @constructor */\n" +
+ "Class = function() {}\n" +
+ "\n" +
+ "/** @return {number} */\n" +
+ "Class.prototype.method_;\n" +
+ "\n" +
+ "/** @return {number} */\n" +
+ "Class.method;\n" +
+ "\n" +
+ "cr.makePublic(Class, ['method']);");
+ }
+
+ public void testCrMakePublicReportsInvalidSecondArgumentMissing() throws Exception {
+ test(
+ "cr.makePublic(Class);", null,
+ ChromePass.CR_MAKE_PUBLIC_INVALID_SECOND_ARGUMENT);
+ }
+
+ public void testCrMakePublicReportsInvalidSecondArgumentNotAnArray() throws Exception {
+ test(
+ "cr.makePublic(Class, 42);", null,
+ ChromePass.CR_MAKE_PUBLIC_INVALID_SECOND_ARGUMENT);
+ }
+
+ public void testCrMakePublicReportsInvalidSecondArgumentArrayWithNotAString() throws Exception {
+ test(
+ "cr.makePublic(Class, [42]);", null,
+ ChromePass.CR_MAKE_PUBLIC_INVALID_SECOND_ARGUMENT);
+ }
+
}

Powered by Google App Engine
This is Rietveld 408576698