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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package com.google.javascript.jscomp; 5 package com.google.javascript.jscomp;
6 6
7 /** 7 /**
8 * Tests {@link ChromePass}. 8 * Tests {@link ChromePass}.
9 */ 9 */
10 public class ChromePassTest extends CompilerTestCase { 10 public class ChromePassTest extends CompilerTestCase {
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 "cr.ui = cr.ui || {};\n" + 356 "cr.ui = cr.ui || {};\n" +
357 "cr.define('cr.ui', function() {\n" + 357 "cr.define('cr.ui', function() {\n" +
358 " return {};\n" + 358 " return {};\n" +
359 "});"); 359 "});");
360 } 360 }
361 361
362 public void testCrExportPathInvalidNumberOfArguments() throws Exception { 362 public void testCrExportPathInvalidNumberOfArguments() throws Exception {
363 test("cr.exportPath();", null, ChromePass.CR_EXPORT_PATH_WRONG_NUMBER_OF _ARGUMENTS); 363 test("cr.exportPath();", null, ChromePass.CR_EXPORT_PATH_WRONG_NUMBER_OF _ARGUMENTS);
364 } 364 }
365 365
366 public void testCrMakePublicWorksOnOneMethodDefinedInPrototypeObject() throw s Exception {
367 test(
368 "/** @constructor */\n" +
369 "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.
370 "\n" +
371 "Class.prototype = {\n" +
372 " /** @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
373 " method_: function() { return 42; }\n" +
374 "};\n" +
375 "\n" +
376 "cr.makePublic(Class, ['method']);",
377 "/** @constructor */\n" +
378 "Class = function() {};\n" +
379 "\n" +
380 "Class.prototype = {\n" +
381 " /** @return {number} */\n" +
382 " method_: function() { return 42; }\n" +
383 "};\n" +
384 "\n" +
385 "/** @return {number} */\n" +
386 "Class.method;\n" +
387 "\n" +
388 "cr.makePublic(Class, ['method']);");
389 }
390
391 public void testCrMakePublicWorksOnTwoMethods() throws Exception {
392 test(
393 "/** @constructor */\n" +
394 "Class = function() {}\n" +
395 "\n" +
396 "Class.prototype = {\n" +
397 " /** @return {number} */\n" +
398 " m1_: function() { return 42; },\n" +
399 "\n" +
400 " /** @return {string} */\n" +
401 " m2_: function() { return ''; }\n" +
402 "};\n" +
403 "\n" +
404 "cr.makePublic(Class, ['m1', 'm2']);",
405 "/** @constructor */\n" +
406 "Class = function() {}\n" +
407 "\n" +
408 "Class.prototype = {\n" +
409 " /** @return {number} */\n" +
410 " m1_: function() { return 42; },\n" +
411 "\n" +
412 " /** @return {string} */\n" +
413 " m2_: function() { return ''; }\n" +
414 "}\n" +
415 "\n" +
416 "/** @return {number} */\n" +
417 "Class.m1;\n" +
418 "\n" +
419 "/** @return {string} */\n" +
420 "Class.m2;\n" +
421 "\n" +
422 "cr.makePublic(Class, ['m1', 'm2']);");
423 }
424
425 public void testCrMakePublicRequiresMethodsToHaveJSDoc() throws Exception {
426 test("/** @constructor */\n" +
427 "Class = function() {}\n" +
Dan Beam 2014/09/10 19:26:27 ident off
Vitaly Pavlenko 2014/09/10 20:25:21 Done.
428 "\n" +
429 "Class.prototype = {\n" +
430 " method_: function() {}\n" +
431 "}\n" +
432 "\n" +
433 "cr.makePublic(Class, ['method']);", null, ChromePass.CR_MAKE_PU BLIC_HAS_NO_JSDOC);
434 }
435
436 public void testCrMakePublicDoesNothingWithMethodsNotInAPI() throws Exceptio n {
437 test(
438 "/** @constructor */\n" +
439 "Class = function() {}\n" +
440 "\n" +
441 "Class.prototype = {\n" +
442 " method_: function() {}\n" +
443 "}\n" +
444 "\n" +
445 "cr.makePublic(Class, []);",
446 "/** @constructor */\n" +
447 "Class = function() {}\n" +
448 "\n" +
449 "Class.prototype = {\n" +
450 " method_: function() {}\n" +
451 "}\n" +
452 "\n" +
453 "cr.makePublic(Class, []);");
454 }
455
456 public void testCrMakePublicRequiresExportedMethodToBeDeclared() throws Exce ption {
457 test(
458 "/** @constructor */\n" +
459 "Class = function() {}\n" +
460 "\n" +
461 "Class.prototype = {\n" +
462 "}\n" +
463 "\n" +
464 "cr.makePublic(Class, ['method']);", null,
465 ChromePass.CR_MAKE_PUBLIC_MISSED_DECLARATION);
466 }
467
468 public void testCrMakePublicWorksOnOneMethodDefinedDirectlyOnPrototype() thr ows Exception {
469 test(
470 "/** @constructor */\n" +
471 "Class = function() {}\n" +
472 "\n" +
473 "/** @return {number} */\n" +
474 "Class.prototype.method_ = function() {};\n" +
475 "\n" +
476 "cr.makePublic(Class, ['method']);",
477 "/** @constructor */\n" +
478 "Class = function() {}\n" +
479 "\n" +
480 "/** @return {number} */\n" +
481 "Class.prototype.method_ = function() {};\n" +
482 "\n" +
483 "/** @return {number} */\n" +
484 "Class.method;\n" +
485 "\n" +
486 "cr.makePublic(Class, ['method']);");
487 }
488
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.
489 public void testCrMakePublicWorksOnDummyDeclaration() throws Exception {
490 test(
491 "/** @constructor */\n" +
492 "Class = function() {}\n" +
493 "\n" +
494 "/** @return {number} */\n" +
495 "Class.prototype.method_;\n" +
496 "\n" +
497 "cr.makePublic(Class, ['method']);",
498 "/** @constructor */\n" +
499 "Class = function() {}\n" +
500 "\n" +
501 "/** @return {number} */\n" +
502 "Class.prototype.method_;\n" +
503 "\n" +
504 "/** @return {number} */\n" +
505 "Class.method;\n" +
506 "\n" +
507 "cr.makePublic(Class, ['method']);");
508 }
509
510 public void testCrMakePublicReportsInvalidSecondArgumentMissing() throws Exc eption {
511 test(
512 "cr.makePublic(Class);", null,
513 ChromePass.CR_MAKE_PUBLIC_INVALID_SECOND_ARGUMENT);
514 }
515
516 public void testCrMakePublicReportsInvalidSecondArgumentNotAnArray() throws Exception {
517 test(
518 "cr.makePublic(Class, 42);", null,
519 ChromePass.CR_MAKE_PUBLIC_INVALID_SECOND_ARGUMENT);
520 }
521
522 public void testCrMakePublicReportsInvalidSecondArgumentArrayWithNotAString( ) throws Exception {
523 test(
524 "cr.makePublic(Class, [42]);", null,
525 ChromePass.CR_MAKE_PUBLIC_INVALID_SECOND_ARGUMENT);
526 }
527
366 } 528 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698