Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 // Tests that const symbols are only equal to the symbol they represent. | 5 // Tests that const symbols are only equal to the symbol they represent. |
| 6 | 6 |
| 7 import 'package:expect/expect.dart'; | 7 import 'package:expect/expect.dart'; |
| 8 | 8 |
| 9 class A { | 9 class A { |
| 10 noSuchMethod(invocation) { | 10 noSuchMethod(invocation) { |
| 11 Expect.isFalse(oneAndTwoCharacterSymbols.contains(invocation.memberName)); | 11 Expect.isFalse(oneAndTwoCharacterSymbols.contains(invocation.memberName)); |
| 12 } | 12 } |
| 13 } | 13 } |
| 14 | 14 |
| 15 main() { | 15 main() { |
| 16 var a = new A(); | 16 var a = new A(); |
| 17 a.foo = 23; | 17 a.foo = 23; |
| 18 a.foo; | 18 a.foo; |
| 19 a.bar; | 19 a.bar; |
| 20 a.longer; | 20 a.longer; |
| 21 a.anotherOne; | 21 a.anotherOne; |
| 22 a.add(1); | 22 a.add(1); |
| 23 a.isEmpty; | 23 a.isEmpty; |
| 24 } | 24 } |
| 25 | 25 |
| 26 /** | 26 /** |
| 27 The following constant was generated with the following program: | 27 The following constant was generated with the following program: |
| 28 | 28 |
| 29 const RESERVED_WORDS = const [ | |
| 30 'assert', 'break', 'case', 'catch', 'class', 'const', 'continue', | |
| 31 'default', 'do', 'else', 'enum', 'extends', 'false', 'final', | |
| 32 'finally', 'for', 'if', 'in', 'is', 'new', 'null', 'rethrow', | |
| 33 'return', 'super', 'switch', 'this', 'throw', 'true', 'try', | |
| 34 'var', 'void', 'while', 'with']; | |
| 35 | |
| 29 get chars sync* { | 36 get chars sync* { |
| 30 for (int i = "a".codeUnitAt(0); i <= "z".codeUnitAt(0); i++) { | 37 for (int i = "a".codeUnitAt(0); i <= "z".codeUnitAt(0); i++) { |
| 31 yield new String.fromCharCodes([i]); | 38 yield new String.fromCharCodes([i]); |
| 32 } | 39 } |
| 33 for (int i = "A".codeUnitAt(0); i <= "Z".codeUnitAt(0); i++) { | 40 for (int i = "A".codeUnitAt(0); i <= "Z".codeUnitAt(0); i++) { |
| 34 yield new String.fromCharCodes([i]); | 41 yield new String.fromCharCodes([i]); |
| 35 } | 42 } |
| 36 } | 43 } |
| 37 | 44 |
| 38 main() { | 45 main() { |
| 39 print("const oneAndTwoCharacterSymbols = const ["); | 46 print("const oneAndTwoCharacterSymbols = const ["); |
| 40 // One character symbols. | 47 // One character symbols. |
| 41 for (String c in chars) { | 48 for (String c in chars) { |
| 42 print(" const Symbol('$c'),"); | 49 print(" const Symbol('$c'),"); |
| 43 } | 50 } |
| 44 // Two character symbols. | 51 // Two character symbols. |
| 45 for (String c1 in chars) { | 52 for (String c1 in chars) { |
| 46 for (String c2 in chars) { | 53 for (String c2 in chars) { |
| 47 print(" const Symbol('$c1$c2'),"); | 54 if (!RESERVED_WORDS.contains('$c1$c2')) { |
|
karlklose
2015/07/24 08:27:57
You could actually make a multi-test that also tes
Paul Berry
2015/07/24 13:26:25
Actually there is already a test which verifies th
| |
| 55 print(" const Symbol('$c1$c2'),"); | |
| 56 } | |
| 48 } | 57 } |
| 49 } | 58 } |
| 50 print("];"); | 59 print("];"); |
| 51 } | 60 } |
| 52 */ | 61 */ |
| 53 const oneAndTwoCharacterSymbols = const [ | 62 const oneAndTwoCharacterSymbols = const [ |
| 54 const Symbol('a'), | 63 const Symbol('a'), |
| 55 const Symbol('b'), | 64 const Symbol('b'), |
| 56 const Symbol('c'), | 65 const Symbol('c'), |
| 57 const Symbol('d'), | 66 const Symbol('d'), |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 const Symbol('de'), | 275 const Symbol('de'), |
| 267 const Symbol('df'), | 276 const Symbol('df'), |
| 268 const Symbol('dg'), | 277 const Symbol('dg'), |
| 269 const Symbol('dh'), | 278 const Symbol('dh'), |
| 270 const Symbol('di'), | 279 const Symbol('di'), |
| 271 const Symbol('dj'), | 280 const Symbol('dj'), |
| 272 const Symbol('dk'), | 281 const Symbol('dk'), |
| 273 const Symbol('dl'), | 282 const Symbol('dl'), |
| 274 const Symbol('dm'), | 283 const Symbol('dm'), |
| 275 const Symbol('dn'), | 284 const Symbol('dn'), |
| 276 const Symbol('do'), | |
| 277 const Symbol('dp'), | 285 const Symbol('dp'), |
| 278 const Symbol('dq'), | 286 const Symbol('dq'), |
| 279 const Symbol('dr'), | 287 const Symbol('dr'), |
| 280 const Symbol('ds'), | 288 const Symbol('ds'), |
| 281 const Symbol('dt'), | 289 const Symbol('dt'), |
| 282 const Symbol('du'), | 290 const Symbol('du'), |
| 283 const Symbol('dv'), | 291 const Symbol('dv'), |
| 284 const Symbol('dw'), | 292 const Symbol('dw'), |
| 285 const Symbol('dx'), | 293 const Symbol('dx'), |
| 286 const Symbol('dy'), | 294 const Symbol('dy'), |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 517 const Symbol('hV'), | 525 const Symbol('hV'), |
| 518 const Symbol('hW'), | 526 const Symbol('hW'), |
| 519 const Symbol('hX'), | 527 const Symbol('hX'), |
| 520 const Symbol('hY'), | 528 const Symbol('hY'), |
| 521 const Symbol('hZ'), | 529 const Symbol('hZ'), |
| 522 const Symbol('ia'), | 530 const Symbol('ia'), |
| 523 const Symbol('ib'), | 531 const Symbol('ib'), |
| 524 const Symbol('ic'), | 532 const Symbol('ic'), |
| 525 const Symbol('id'), | 533 const Symbol('id'), |
| 526 const Symbol('ie'), | 534 const Symbol('ie'), |
| 527 const Symbol('if'), | |
| 528 const Symbol('ig'), | 535 const Symbol('ig'), |
| 529 const Symbol('ih'), | 536 const Symbol('ih'), |
| 530 const Symbol('ii'), | 537 const Symbol('ii'), |
| 531 const Symbol('ij'), | 538 const Symbol('ij'), |
| 532 const Symbol('ik'), | 539 const Symbol('ik'), |
| 533 const Symbol('il'), | 540 const Symbol('il'), |
| 534 const Symbol('im'), | 541 const Symbol('im'), |
| 535 const Symbol('in'), | |
| 536 const Symbol('io'), | 542 const Symbol('io'), |
| 537 const Symbol('ip'), | 543 const Symbol('ip'), |
| 538 const Symbol('iq'), | 544 const Symbol('iq'), |
| 539 const Symbol('ir'), | 545 const Symbol('ir'), |
| 540 const Symbol('is'), | |
| 541 const Symbol('it'), | 546 const Symbol('it'), |
| 542 const Symbol('iu'), | 547 const Symbol('iu'), |
| 543 const Symbol('iv'), | 548 const Symbol('iv'), |
| 544 const Symbol('iw'), | 549 const Symbol('iw'), |
| 545 const Symbol('ix'), | 550 const Symbol('ix'), |
| 546 const Symbol('iy'), | 551 const Symbol('iy'), |
| 547 const Symbol('iz'), | 552 const Symbol('iz'), |
| 548 const Symbol('iA'), | 553 const Symbol('iA'), |
| 549 const Symbol('iB'), | 554 const Symbol('iB'), |
| 550 const Symbol('iC'), | 555 const Symbol('iC'), |
| (...skipping 2250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2801 const Symbol('ZR'), | 2806 const Symbol('ZR'), |
| 2802 const Symbol('ZS'), | 2807 const Symbol('ZS'), |
| 2803 const Symbol('ZT'), | 2808 const Symbol('ZT'), |
| 2804 const Symbol('ZU'), | 2809 const Symbol('ZU'), |
| 2805 const Symbol('ZV'), | 2810 const Symbol('ZV'), |
| 2806 const Symbol('ZW'), | 2811 const Symbol('ZW'), |
| 2807 const Symbol('ZX'), | 2812 const Symbol('ZX'), |
| 2808 const Symbol('ZY'), | 2813 const Symbol('ZY'), |
| 2809 const Symbol('ZZ'), | 2814 const Symbol('ZZ'), |
| 2810 ]; | 2815 ]; |
| OLD | NEW |