| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 // Check that we can use pseudo keywords as names in function level code. | 4 // Check that we can use pseudo keywords as names in function level code. |
| 5 | 5 |
| 6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 7 | 7 |
| 8 | 8 |
| 9 class PseudoKWTest { | 9 class PseudoKWTest { |
| 10 static testMain() { | 10 static testMain() { |
| 11 | 11 |
| 12 // This is a list of built-in identifiers from the Dart spec. | 12 // This is a list of built-in identifiers from the Dart spec. |
| 13 // It sanity checks that these pseudo-keywords are legal identifiers. | 13 // It sanity checks that these pseudo-keywords are legal identifiers. |
| 14 | 14 |
| 15 var abstract = 0; // /// 01: ok | 15 var abstract = 0; // //# 01: ok |
| 16 var as = 0; | 16 var as = 0; |
| 17 var dynamic = 0; | 17 var dynamic = 0; |
| 18 var export = 0; | 18 var export = 0; |
| 19 var external = 0; // /// 01: ok | 19 var external = 0; // //# 01: ok |
| 20 var factory = 0; | 20 var factory = 0; |
| 21 var get = 0; | 21 var get = 0; |
| 22 var implements = 0; | 22 var implements = 0; |
| 23 var import = 0; | 23 var import = 0; |
| 24 var library = 0; | 24 var library = 0; |
| 25 var operator = 0; | 25 var operator = 0; |
| 26 var part = 0; | 26 var part = 0; |
| 27 var set = 0; | 27 var set = 0; |
| 28 var static = 0; // /// 01: ok | 28 var static = 0; // //# 01: ok |
| 29 var typedef = 0; | 29 var typedef = 0; |
| 30 | 30 |
| 31 // "native" is a per-implementation extension that is not a part of the | 31 // "native" is a per-implementation extension that is not a part of the |
| 32 // Dart language. While it is not an official built-in identifier, it | 32 // Dart language. While it is not an official built-in identifier, it |
| 33 // is useful to ensure that it remains a legal identifier. | 33 // is useful to ensure that it remains a legal identifier. |
| 34 var native = 0; | 34 var native = 0; |
| 35 | 35 |
| 36 | 36 |
| 37 // The code below adds a few additional variants of usage without any | 37 // The code below adds a few additional variants of usage without any |
| 38 // attempt at complete coverage. | 38 // attempt at complete coverage. |
| 39 { | 39 { |
| 40 void factory(set) { | 40 void factory(set) { |
| 41 return; // /// 01: ok | 41 return; // //# 01: ok |
| 42 } | 42 } |
| 43 } | 43 } |
| 44 | 44 |
| 45 get: while (import > 0) { | 45 get: while (import > 0) { |
| 46 break get; | 46 break get; |
| 47 } | 47 } |
| 48 | 48 |
| 49 return | 49 return |
| 50 static + // /// 01: ok | 50 static + // //# 01: ok |
| 51 library * operator; | 51 library * operator; |
| 52 } | 52 } |
| 53 } | 53 } |
| 54 | 54 |
| 55 typedef(x) => "typedef $x"; // /// 01: ok | 55 typedef(x) => "typedef $x"; // //# 01: ok |
| 56 | 56 |
| 57 static(abstract) { // /// 01: ok | 57 static(abstract) { // //# 01: ok |
| 58 return abstract == true; // /// 01: ok | 58 return abstract == true; // //# 01: ok |
| 59 } // /// 01: ok | 59 } // //# 01: ok |
| 60 | 60 |
| 61 class A { | 61 class A { |
| 62 var typedef = 0; | 62 var typedef = 0; |
| 63 final operator = "smooth"; | 63 final operator = "smooth"; |
| 64 | 64 |
| 65 set(x) { typedef = x; } | 65 set(x) { typedef = x; } |
| 66 get() => typedef - 5; | 66 get() => typedef - 5; |
| 67 | 67 |
| 68 static static() { // /// 01: ok | 68 static static() { // //# 01: ok |
| 69 return 1; // /// 01: ok | 69 return 1; // //# 01: ok |
| 70 } // /// 01: ok | 70 } // //# 01: ok |
| 71 static check() { | 71 static check() { |
| 72 var o = new A(); | 72 var o = new A(); |
| 73 o.set(55); | 73 o.set(55); |
| 74 Expect.equals(50, o.get()); | 74 Expect.equals(50, o.get()); |
| 75 static(); // /// 01: ok | 75 static(); // //# 01: ok |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 | 78 |
| 79 class B { | 79 class B { |
| 80 var set = 100; | 80 var set = 100; |
| 81 get get => set; | 81 get get => set; |
| 82 set get(get) => set = 2 * get.get; | 82 set get(get) => set = 2 * get.get; |
| 83 | 83 |
| 84 static() { // /// 01: ok | 84 static() { // //# 01: ok |
| 85 var set = new B(); // /// 01: ok | 85 var set = new B(); // //# 01: ok |
| 86 set.get = set; // /// 01: ok | 86 set.get = set; // //# 01: ok |
| 87 Expect.equals(200, set.get); // /// 01: ok | 87 Expect.equals(200, set.get); // //# 01: ok |
| 88 } // /// 01: ok | 88 } // //# 01: ok |
| 89 int operator() { | 89 int operator() { |
| 90 return 1; | 90 return 1; |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 | 93 |
| 94 class C { | 94 class C { |
| 95 static int operator = (5); | 95 static int operator = (5); |
| 96 static var get; | 96 static var get; |
| 97 static get set => 111; | 97 static get set => 111; |
| 98 static set set(set) { } | 98 static set set(set) { } |
| 99 } | 99 } |
| 100 | 100 |
| 101 | 101 |
| 102 main() { | 102 main() { |
| 103 PseudoKWTest.testMain(); | 103 PseudoKWTest.testMain(); |
| 104 A.check(); | 104 A.check(); |
| 105 new B().static(); // /// 01: ok | 105 new B().static(); // //# 01: ok |
| 106 Expect.equals(1, new B().operator()); | 106 Expect.equals(1, new B().operator()); |
| 107 Expect.equals(1, A.static()); // /// 01: ok | 107 Expect.equals(1, A.static()); // //# 01: ok |
| 108 typedef("T"); // /// 01: ok | 108 typedef("T"); // //# 01: ok |
| 109 Expect.equals("typedef T", typedef("T")); // /// 01: ok | 109 Expect.equals("typedef T", typedef("T")); // //# 01: ok |
| 110 static("true"); // /// 01: ok | 110 static("true"); // //# 01: ok |
| 111 Expect.equals(false, static("true")); // /// 01: ok | 111 Expect.equals(false, static("true")); // //# 01: ok |
| 112 Expect.equals(5, C.operator); | 112 Expect.equals(5, C.operator); |
| 113 Expect.equals(null, C.get); | 113 Expect.equals(null, C.get); |
| 114 C.set = 0; | 114 C.set = 0; |
| 115 Expect.equals(111, C.set); | 115 Expect.equals(111, C.set); |
| 116 } | 116 } |
| OLD | NEW |