| 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 // Dart test program for default constructors. | 4 // Dart test program for default constructors. |
| 5 | 5 |
| 6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 7 | 7 |
| 8 String message; | 8 String message; |
| 9 | 9 |
| 10 foo() { | 10 foo() { |
| 11 message += 'foo'; | 11 message += 'foo'; |
| 12 return 1; | 12 return 1; |
| 13 } | 13 } |
| 14 | 14 |
| 15 bar() { | 15 bar() { |
| 16 message += 'bar'; | 16 message += 'bar'; |
| 17 return 2; | 17 return 2; |
| 18 } | 18 } |
| 19 | 19 |
| 20 class X { | 20 class X { |
| 21 var i; | 21 var i; |
| 22 var j; | 22 var j; |
| 23 X({a: 'defa', b: 'defb'}) | 23 X({a: 'defa', b: 'defb'}) : this.i = a, this.j = b; |
| 24 : this.i = a, | |
| 25 this.j = b; | |
| 26 X.foo() : this(b: 1, a: 2); | 24 X.foo() : this(b: 1, a: 2); |
| 27 X.bar() | 25 X.bar() : this( |
| 28 : this( | |
| 29 1, // //# 01: static type warning, runtime error | 26 1, // //# 01: static type warning, runtime error |
| 30 a: 2); | 27 a: 2); |
| 31 X.baz() : this(a: 1, b: 2); | 28 X.baz() : this(a: 1, b: 2); |
| 32 X.qux() : this(b: 2); | 29 X.qux() : this(b: 2); |
| 33 X.hest() : this(); | 30 X.hest() : this(); |
| 34 X.fisk() : this(b: bar(), a: foo()); | 31 X.fisk() : this(b: bar(), a: foo()); |
| 35 X.naebdyr() : this(a: foo(), b: bar()); | 32 X.naebdyr() : this(a: foo(), b: bar()); |
| 36 } | 33 } |
| 37 | 34 |
| 38 test(x, a, b) { | 35 test(x, a, b) { |
| 39 Expect.equals(x.i, a); | 36 Expect.equals(x.i, a); |
| 40 Expect.equals(x.j, b); | 37 Expect.equals(x.j, b); |
| 41 } | 38 } |
| 42 | 39 |
| 43 main() { | 40 main() { |
| 44 test(new X.foo(), 2, 1); | 41 test(new X.foo(), 2, 1); |
| 45 test(new X.bar(), 2, 'defb'); | 42 test(new X.bar(), 2, 'defb'); |
| 46 test(new X.baz(), 1, 2); | 43 test(new X.baz(), 1, 2); |
| 47 test(new X.qux(), 'defa', 2); | 44 test(new X.qux(), 'defa', 2); |
| 48 test(new X.hest(), 'defa', 'defb'); | 45 test(new X.hest(), 'defa', 'defb'); |
| 49 | 46 |
| 50 message = ''; | 47 message = ''; |
| 51 new X.fisk(); | 48 new X.fisk(); |
| 52 Expect.equals('barfoo', message); | 49 Expect.equals('barfoo', message); |
| 53 | 50 |
| 54 message = ''; | 51 message = ''; |
| 55 new X.naebdyr(); | 52 new X.naebdyr(); |
| 56 Expect.equals('foobar', message); | 53 Expect.equals('foobar', message); |
| 57 } | 54 } |
| OLD | NEW |