OLD | NEW |
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 Loading... |
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 "function Class() {};\n" + |
| 370 "\n" + |
| 371 "Class.prototype = {\n" + |
| 372 " /** @return {number} */\n" + |
| 373 " method_: function() { return 42; }\n" + |
| 374 "};\n" + |
| 375 "\n" + |
| 376 "cr.makePublic(Class, ['method']);", |
| 377 "/** @constructor */\n" + |
| 378 "function Class() {};\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 "function Class() {}\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 "function Class() {}\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 "function Class() {}\n" + |
| 428 "\n" + |
| 429 "Class.prototype = {\n" + |
| 430 " method_: function() {}\n" + |
| 431 "}\n" + |
| 432 "\n" + |
| 433 "cr.makePublic(Class, ['method']);", null, ChromePass.CR_MAKE_PUBLIC
_HAS_NO_JSDOC); |
| 434 } |
| 435 |
| 436 public void testCrMakePublicDoesNothingWithMethodsNotInAPI() throws Exceptio
n { |
| 437 test( |
| 438 "/** @constructor */\n" + |
| 439 "function Class() {}\n" + |
| 440 "\n" + |
| 441 "Class.prototype = {\n" + |
| 442 " method_: function() {}\n" + |
| 443 "}\n" + |
| 444 "\n" + |
| 445 "cr.makePublic(Class, []);", |
| 446 "/** @constructor */\n" + |
| 447 "function Class() {}\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 "function Class() {}\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 "function Class() {}\n" + |
| 472 "\n" + |
| 473 "/** @return {number} */\n" + |
| 474 "Class.prototype.method_ = function() {};\n" + |
| 475 "\n" + |
| 476 "cr.makePublic(Class, ['method']);", |
| 477 "/** @constructor */\n" + |
| 478 "function Class() {}\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 |
| 489 public void testCrMakePublicWorksOnDummyDeclaration() throws Exception { |
| 490 test( |
| 491 "/** @constructor */\n" + |
| 492 "function Class() {}\n" + |
| 493 "\n" + |
| 494 "/** @return {number} */\n" + |
| 495 "Class.prototype.method_;\n" + |
| 496 "\n" + |
| 497 "cr.makePublic(Class, ['method']);", |
| 498 "/** @constructor */\n" + |
| 499 "function Class() {}\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 } |
OLD | NEW |