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