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 // Test for instance field initializer expressions. | 4 // Test for instance field initializer expressions. |
5 | 5 |
6 class Cheese { | 6 class Cheese { |
7 static final mild = 1; | 7 static const mild = 1; |
8 static final stinky = 2; | 8 static const stinky = 2; |
9 | 9 |
10 // Instance fields with initializer expression. | 10 // Instance fields with initializer expression. |
11 String name = ""; | 11 String name = ""; |
12 var smell = mild; | 12 var smell = mild; |
13 | 13 |
14 Cheese() { | 14 Cheese() { |
15 Expect.equals("", this.name); | 15 Expect.equals("", this.name); |
16 Expect.equals(Cheese.mild, this.smell); | 16 Expect.equals(Cheese.mild, this.smell); |
17 } | 17 } |
18 | 18 |
19 Cheese.initInBlock(String s) { | 19 Cheese.initInBlock(String s) { |
20 Expect.equals("", this.name); | 20 Expect.equals("", this.name); |
21 Expect.equals(Cheese.mild, this.smell); | 21 Expect.equals(Cheese.mild, this.smell); |
22 this.name = s; | 22 this.name = s; |
23 } | 23 } |
24 | 24 |
25 Cheese.initFieldParam(this.name, this.smell) { | 25 Cheese.initFieldParam(this.name, this.smell) { |
26 } | 26 } |
27 | 27 |
28 // Test that static final field Cheese.mild is not shadowed | 28 // Test that static const field Cheese.mild is not shadowed |
29 // by the parameter mild when compiling the field initializer | 29 // by the parameter mild when compiling the field initializer |
30 // for instance field smell. | 30 // for instance field smell. |
31 Cheese.hideAndSeek(var mild) : name = mild { | 31 Cheese.hideAndSeek(var mild) : name = mild { |
32 Expect.equals(mild, this.name); | 32 Expect.equals(mild, this.name); |
33 Expect.equals(Cheese.mild, this.smell); | 33 Expect.equals(Cheese.mild, this.smell); |
34 } | 34 } |
35 } | 35 } |
36 | 36 |
37 class HasNoExplicitConstructor { | 37 class HasNoExplicitConstructor { |
38 String s = "Tilsiter"; | 38 String s = "Tilsiter"; |
(...skipping 12 matching lines...) Expand all Loading... |
51 Expect.equals("Munster", munster.name); | 51 Expect.equals("Munster", munster.name); |
52 Expect.equals(Cheese.stinky, munster.smell); | 52 Expect.equals(Cheese.stinky, munster.smell); |
53 | 53 |
54 var brie = new Cheese.hideAndSeek("Brie"); | 54 var brie = new Cheese.hideAndSeek("Brie"); |
55 Expect.equals("Brie", brie.name); | 55 Expect.equals("Brie", brie.name); |
56 Expect.equals(Cheese.mild, brie.smell); | 56 Expect.equals(Cheese.mild, brie.smell); |
57 | 57 |
58 var t = new HasNoExplicitConstructor(); | 58 var t = new HasNoExplicitConstructor(); |
59 Expect.equals("Tilsiter", t.s); | 59 Expect.equals("Tilsiter", t.s); |
60 } | 60 } |
OLD | NEW |