| 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 | 6 |
| 7 // Test to stress Frog's named parameter scheme. | 7 // Test to stress Frog's named parameter scheme. |
| 8 | 8 |
| 9 main() { | 9 main() { |
| 10 testDollar(); | 10 testDollar(); |
| 11 testPsycho(); | 11 testPsycho(); |
| 12 } | 12 } |
| 13 | 13 |
| 14 class TestClass { | 14 class TestClass { |
| 15 method({a, b, a$b, a$$b}) => [a, b, a$b, a$$b]; | 15 method({a, b, a$b, a$$b}) => [a, b, a$b, a$$b]; |
| 16 | 16 |
| 17 psycho({$, $$, $$$, $$$$}) => [$, $$, $$$, $$$$]; | 17 psycho({$, $$, $$$, $$$$}) => [$, $$, $$$, $$$$]; |
| 18 } | 18 } |
| 19 |
| 19 globalMethod({a, b, a$b, a$$b}) => [a, b, a$b, a$$b]; | 20 globalMethod({a, b, a$b, a$$b}) => [a, b, a$b, a$$b]; |
| 20 | 21 |
| 21 | |
| 22 format(thing) { | 22 format(thing) { |
| 23 if (thing == null) return '-'; | 23 if (thing == null) return '-'; |
| 24 if (thing is List) { | 24 if (thing is List) { |
| 25 var fragments = ['[']; | 25 var fragments = ['[']; |
| 26 var sep; | 26 var sep; |
| 27 for (final item in thing) { | 27 for (final item in thing) { |
| 28 if (sep != null) fragments.add(sep); | 28 if (sep != null) fragments.add(sep); |
| 29 sep = ', '; | 29 sep = ', '; |
| 30 fragments.add(format(item)); | 30 fragments.add(format(item)); |
| 31 } | 31 } |
| 32 fragments.add(']'); | 32 fragments.add(']'); |
| 33 return fragments.join(); | 33 return fragments.join(); |
| 34 } | 34 } |
| 35 return thing.toString(); | 35 return thing.toString(); |
| 36 } | 36 } |
| 37 | 37 |
| 38 // Hopefully inscrutable to static analysis. | 38 // Hopefully inscrutable to static analysis. |
| 39 makeTestClass(n) => [new TestClass(), new Decoy(), 'string'][n % 3]; | 39 makeTestClass(n) => [new TestClass(), new Decoy(), 'string'][n % 3]; |
| 40 | 40 |
| 41 class Decoy { | 41 class Decoy { |
| 42 method([a$b, b, a]) { throw new UnimplementedError(); } | 42 method([a$b, b, a]) { |
| 43 psycho([$$$, $$, $]) { throw new UnimplementedError(); } | 43 throw new UnimplementedError(); |
| 44 } |
| 45 |
| 46 psycho([$$$, $$, $]) { |
| 47 throw new UnimplementedError(); |
| 48 } |
| 44 } | 49 } |
| 45 | 50 |
| 46 testDollar() { | 51 testDollar() { |
| 47 Expect.equals('[]', format([])); | 52 Expect.equals('[]', format([])); |
| 48 | 53 |
| 49 Expect.equals('[-, -, -, -]', format(globalMethod())); | 54 Expect.equals('[-, -, -, -]', format(globalMethod())); |
| 50 Expect.equals('[1, 2, -, -]', format(globalMethod(a: 1, b: 2))); | 55 Expect.equals('[1, 2, -, -]', format(globalMethod(a: 1, b: 2))); |
| 51 Expect.equals('[1, 2, -, -]', format(globalMethod(b: 2, a: 1))); | 56 Expect.equals('[1, 2, -, -]', format(globalMethod(b: 2, a: 1))); |
| 52 Expect.equals('[-, -, 3, -]', format(globalMethod(a$b: 3))); | 57 Expect.equals('[-, -, 3, -]', format(globalMethod(a$b: 3))); |
| 53 Expect.equals('[-, -, -, 4]', format(globalMethod(a$$b: 4))); | 58 Expect.equals('[-, -, -, 4]', format(globalMethod(a$$b: 4))); |
| 54 | 59 |
| 55 TestClass t = new TestClass(); // Statically typed. | 60 TestClass t = new TestClass(); // Statically typed. |
| 56 | 61 |
| 57 Expect.equals('[-, -, -, -]', format(t.method())); | 62 Expect.equals('[-, -, -, -]', format(t.method())); |
| 58 Expect.equals('[1, 2, -, -]', format(t.method(a: 1, b: 2))); | 63 Expect.equals('[1, 2, -, -]', format(t.method(a: 1, b: 2))); |
| 59 Expect.equals('[1, 2, -, -]', format(t.method(b: 2, a: 1))); | 64 Expect.equals('[1, 2, -, -]', format(t.method(b: 2, a: 1))); |
| 60 Expect.equals('[-, -, 3, -]', format(t.method(a$b: 3))); | 65 Expect.equals('[-, -, 3, -]', format(t.method(a$b: 3))); |
| 61 Expect.equals('[-, -, -, 4]', format(t.method(a$$b: 4))); | 66 Expect.equals('[-, -, -, 4]', format(t.method(a$$b: 4))); |
| 62 | 67 |
| 63 var obj = makeTestClass(0); | 68 var obj = makeTestClass(0); |
| 64 | 69 |
| 65 Expect.equals('[-, -, -, -]', format(obj.method())); | 70 Expect.equals('[-, -, -, -]', format(obj.method())); |
| 66 Expect.equals('[1, 2, -, -]', format(obj.method(a: 1, b: 2))); | 71 Expect.equals('[1, 2, -, -]', format(obj.method(a: 1, b: 2))); |
| 67 Expect.equals('[1, 2, -, -]', format(obj.method(b: 2, a: 1))); | 72 Expect.equals('[1, 2, -, -]', format(obj.method(b: 2, a: 1))); |
| 68 Expect.equals('[-, -, 3, -]', format(obj.method(a$b: 3))); | 73 Expect.equals('[-, -, 3, -]', format(obj.method(a$b: 3))); |
| 69 Expect.equals('[-, -, -, 4]', format(obj.method(a$$b: 4))); | 74 Expect.equals('[-, -, -, 4]', format(obj.method(a$$b: 4))); |
| 70 } | 75 } |
| 71 | 76 |
| 72 testPsycho() { | 77 testPsycho() { |
| 73 TestClass t = new TestClass(); // Statically typed. | 78 TestClass t = new TestClass(); // Statically typed. |
| 74 | 79 |
| 75 Expect.equals('[1, 2, 3, -]', format(t.psycho($:1, $$:2, $$$:3))); | 80 Expect.equals('[1, 2, 3, -]', format(t.psycho($: 1, $$: 2, $$$: 3))); |
| 76 Expect.equals('[1, 2, 3, -]', format(t.psycho($$$:3, $$:2, $:1))); | 81 Expect.equals('[1, 2, 3, -]', format(t.psycho($$$: 3, $$: 2, $: 1))); |
| 77 Expect.equals('[1, 2, -, -]', format(t.psycho($:1, $$:2))); | 82 Expect.equals('[1, 2, -, -]', format(t.psycho($: 1, $$: 2))); |
| 78 Expect.equals('[-, -, -, 4]', format(t.psycho($$$$: 4))); | 83 Expect.equals('[-, -, -, 4]', format(t.psycho($$$$: 4))); |
| 79 | 84 |
| 80 var obj = makeTestClass(0); | 85 var obj = makeTestClass(0); |
| 81 | 86 |
| 82 Expect.equals('[1, 2, -, -]', format(obj.psycho($:1, $$:2))); | 87 Expect.equals('[1, 2, -, -]', format(obj.psycho($: 1, $$: 2))); |
| 83 Expect.equals('[-, -, -, 4]', format(obj.psycho($$$$: 4))); | 88 Expect.equals('[-, -, -, 4]', format(obj.psycho($$$$: 4))); |
| 84 Expect.equals('[1, 2, 3, -]', format(obj.psycho($:1, $$:2, $$$:3))); | 89 Expect.equals('[1, 2, 3, -]', format(obj.psycho($: 1, $$: 2, $$$: 3))); |
| 85 Expect.equals('[1, 2, 3, -]', format(obj.psycho($$$:3, $$:2, $:1))); | 90 Expect.equals('[1, 2, 3, -]', format(obj.psycho($$$: 3, $$: 2, $: 1))); |
| 86 } | 91 } |
| OLD | NEW |