Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(715)

Side by Side Diff: tests/language/field_initialization_order_test.dart

Issue 10873033: Support non-const instance field initializers. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/co19/co19-dart2js.status ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4 // Test that field initializers are evaluated in the right order.
5
6 int counter = 0;
7
8 class Mark {
9 static StringBuffer buffer;
10 Mark(value) {
11 buffer.add('$value.');
12 }
13 }
14
15 class OneField {
16 var a = new Mark('a');
17
18 OneField();
19
20 OneField.init() : a = new Mark('ai');
21 }
22
23 class TwoFields {
24 var b = new Mark('b');
25 var a = new Mark('a');
26
27 TwoFields();
28
29 TwoFields.initA() : a = new Mark('ai');
30
31 TwoFields.initB() : b = new Mark('bi');
32
33 TwoFields.initBoth() : a = new Mark('ai'), b = new Mark('bi');
34 }
35
36 class InheritOneField extends OneField {
37 var b = new Mark('b');
38
39 InheritOneField() : super();
40
41 InheritOneField.init() : b = new Mark('bi'), super();
42
43 InheritOneField.superWithInit() : super.init();
44
45 InheritOneField.initWithSuperInit() : b = new Mark('bi'), super.init();
46
47 InheritOneField.initWithSuperInit2() : super.init(), b = new Mark('bi');
48 }
49
50 String run(callback) {
51 Mark.buffer = new StringBuffer();
52 callback();
53 return Mark.buffer.toString();
54 }
55
56 main() {
57 Expect.equals('a.', run(() => new OneField()));
58 Expect.equals('a.ai.', run(() => new OneField.init()));
59
60 Expect.equals('b.a.', run(() => new TwoFields()));
61 Expect.equals('b.a.ai.', run(() => new TwoFields.initA()));
62 Expect.equals('b.a.bi.', run(() => new TwoFields.initB()));
63 Expect.equals('b.a.ai.bi.', run(() => new TwoFields.initBoth()));
64
65 Expect.equals('b.a.', run(() => new InheritOneField()));
66 Expect.equals('b.bi.a.', run(() => new InheritOneField.init()));
67 Expect.equals('b.a.ai.', run(() => new InheritOneField.superWithInit()));
68 Expect.equals('b.bi.a.ai.', run(() => new InheritOneField.initWithSuperInit()) );
69 Expect.equals('b.a.ai.bi.', run(() => new InheritOneField.initWithSuperInit2() ));
70 }
OLDNEW
« no previous file with comments | « tests/co19/co19-dart2js.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698