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