| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 class A { | 5 class A { |
| 6 A() { NamingTest.count++; } | 6 A() { NamingTest.count++; } |
| 7 foo(a, b) { | 7 foo(a, b) { |
| 8 Expect.equals(1, a); | 8 Expect.equals(1, a); |
| 9 Expect.equals(2, b); | 9 Expect.equals(2, b); |
| 10 } | 10 } |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 Expect.equals(10, b(10)); | 445 Expect.equals(10, b(10)); |
| 446 Expect.equals(10, c(10)); | 446 Expect.equals(10, c(10)); |
| 447 } | 447 } |
| 448 | 448 |
| 449 static testPseudoTokens() { | 449 static testPseudoTokens() { |
| 450 var EOS = 400; | 450 var EOS = 400; |
| 451 var ILLEGAL = 99; | 451 var ILLEGAL = 99; |
| 452 Expect.equals(499, EOS + ILLEGAL); | 452 Expect.equals(499, EOS + ILLEGAL); |
| 453 } | 453 } |
| 454 | 454 |
| 455 static testDollar() { |
| 456 Expect.equals(123, $(123).wrapped); |
| 457 var x = new Object(), y = new Object(); |
| 458 Expect.identical(x, $(x).wrapped); |
| 459 Expect.identical(y, $(x).$add(y)); |
| 460 Expect.identical(x, $(x).$negate()); |
| 461 Expect.equals(123, $(x) + x); |
| 462 Expect.equals(444, -$(x)); |
| 463 } |
| 464 |
| 455 static void testMain() { | 465 static void testMain() { |
| 456 count = 0; | 466 count = 0; |
| 457 testExceptionNaming(); | 467 testExceptionNaming(); |
| 458 testTmpNaming(); | 468 testTmpNaming(); |
| 459 testScopeNaming(); | 469 testScopeNaming(); |
| 460 testGlobalMangling(); | 470 testGlobalMangling(); |
| 461 testMemberMangling(); | 471 testMemberMangling(); |
| 462 testFactoryMangling(); | 472 testFactoryMangling(); |
| 463 testFunctionParameters(); | 473 testFunctionParameters(); |
| 464 Bug4082360.test(); | 474 Bug4082360.test(); |
| 465 Hoisting.test(); | 475 Hoisting.test(); |
| 466 testPseudoTokens(); | 476 testPseudoTokens(); |
| 477 testDollar(); |
| 467 } | 478 } |
| 468 } | 479 } |
| 469 | 480 |
| 481 // Test that the generated JS names don't conflict with "$" |
| 482 class DartQuery { |
| 483 Object wrapped; |
| 484 DartQuery(this.wrapped); |
| 485 |
| 486 $add(Object other) => other; |
| 487 $negate() => wrapped; |
| 488 |
| 489 operator +(Object other) => 123; |
| 490 operator negate() => 444; |
| 491 } |
| 492 |
| 493 $add(Object first, Object second) => second; |
| 494 DartQuery $(Object obj) => new DartQuery(obj); |
| 470 | 495 |
| 471 // Ensure we don't have false positive. named constructor and methods | 496 // Ensure we don't have false positive. named constructor and methods |
| 472 // are in different namespaces, therefore it is ok to have a method | 497 // are in different namespaces, therefore it is ok to have a method |
| 473 // called foo and a named constructor CLASS.foo | 498 // called foo and a named constructor CLASS.foo |
| 474 class Naming1Test { | 499 class Naming1Test { |
| 475 Naming1Test.foo() { } | 500 Naming1Test.foo() { } |
| 476 foo() { } | 501 foo() { } |
| 477 | 502 |
| 478 static void main(args) { | 503 static void main(args) { |
| 479 var a = new Naming1Test.foo(); | 504 var a = new Naming1Test.foo(); |
| 480 a.foo(); | 505 a.foo(); |
| 481 } | 506 } |
| 482 } | 507 } |
| 483 | 508 |
| 484 // Ensure we don't have false positive. | 509 // Ensure we don't have false positive. |
| 485 class Naming2Test { | 510 class Naming2Test { |
| 486 Naming2Test() { } | 511 Naming2Test() { } |
| 487 int get foo() { return 1; } | 512 int get foo() { return 1; } |
| 488 set foo(x) { } | 513 set foo(x) { } |
| 489 | 514 |
| 490 static void main(args) { | 515 static void main(args) { |
| 491 var a = new Naming2Test(); | 516 var a = new Naming2Test(); |
| 492 a.foo(2); | 517 Expect.throws(() => a.foo(2), (e) => e is ObjectNotClosureException); |
| 493 } | 518 } |
| 494 } | 519 } |
| 495 | 520 |
| 496 // Ensure we don't have false positivesj. | 521 // Ensure we don't have false positivesj. |
| 497 class Naming3Test { | 522 class Naming3Test { |
| 498 Naming3Test() { } | 523 Naming3Test() { } |
| 499 operator negate() { } | 524 operator negate() { } |
| 500 negate() { } | 525 negate() => 777; |
| 501 | 526 |
| 502 static void main(args) { | 527 static void main(args) { |
| 503 var a = new Naming3Test(); | 528 var a = new Naming3Test(); |
| 504 a.negate(3); | 529 Expect.equals(777, a.negate()); |
| 505 } | 530 } |
| 506 } | 531 } |
| 507 | 532 |
| 508 main() { | 533 main() { |
| 509 NamingTest.testMain(); | 534 NamingTest.testMain(); |
| 535 Naming1Test.main(null); |
| 536 Naming2Test.main(null); |
| 537 Naming3Test.main(null); |
| 510 } | 538 } |
| OLD | NEW |