| 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'}) : this.i = a, this.j = b; | 23 X({a: 'defa', b: 'defb'}) |
| 24 : this.i = a, |
| 25 this.j = b; |
| 24 X.foo() : this(b: 1, a: 2); | 26 X.foo() : this(b: 1, a: 2); |
| 25 X.bar() : this( | 27 X.bar() |
| 28 : this( |
| 26 1, // //# 01: static type warning, runtime error | 29 1, // //# 01: static type warning, runtime error |
| 27 a: 2); | 30 a: 2); |
| 28 X.baz() : this(a: 1, b: 2); | 31 X.baz() : this(a: 1, b: 2); |
| 29 X.qux() : this(b: 2); | 32 X.qux() : this(b: 2); |
| 30 X.hest() : this(); | 33 X.hest() : this(); |
| 31 X.fisk() : this(b: bar(), a: foo()); | 34 X.fisk() : this(b: bar(), a: foo()); |
| 32 X.naebdyr() : this(a: foo(), b: bar()); | 35 X.naebdyr() : this(a: foo(), b: bar()); |
| 33 } | 36 } |
| 34 | 37 |
| 35 test(x, a, b) { | 38 test(x, a, b) { |
| 36 Expect.equals(x.i, a); | 39 Expect.equals(x.i, a); |
| 37 Expect.equals(x.j, b); | 40 Expect.equals(x.j, b); |
| 38 } | 41 } |
| 39 | 42 |
| 40 main() { | 43 main() { |
| 41 test(new X.foo(), 2, 1); | 44 test(new X.foo(), 2, 1); |
| 42 test(new X.bar(), 2, 'defb'); | 45 test(new X.bar(), 2, 'defb'); |
| 43 test(new X.baz(), 1, 2); | 46 test(new X.baz(), 1, 2); |
| 44 test(new X.qux(), 'defa', 2); | 47 test(new X.qux(), 'defa', 2); |
| 45 test(new X.hest(), 'defa', 'defb'); | 48 test(new X.hest(), 'defa', 'defb'); |
| 46 | 49 |
| 47 message = ''; | 50 message = ''; |
| 48 new X.fisk(); | 51 new X.fisk(); |
| 49 Expect.equals('barfoo', message); | 52 Expect.equals('barfoo', message); |
| 50 | 53 |
| 51 message = ''; | 54 message = ''; |
| 52 new X.naebdyr(); | 55 new X.naebdyr(); |
| 53 Expect.equals('foobar', message); | 56 Expect.equals('foobar', message); |
| 54 } | 57 } |
| OLD | NEW |