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

Side by Side Diff: tests/language/src/ConstructorRedirectTest.dart

Issue 10248007: test rename overhaul: step 8 - language tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4 // Dart test program for redirection constructors.
5
6 class A {
7 var x;
8 A(this.x) {}
9 A.named(x, int y) : this(x + y);
10 A.named2(int x, int y, z) : this.named(staticFun(x, y), z);
11
12 // The following is a bit tricky. It is a compile-time error to
13 // refer to this (implicitly or explicitly) from an initializer.
14 // When we remove the line with moreStaticFun, staticFun is really a
15 // static function and it is legal to call it. This is what will
16 // happen in the /none version of this test. However, in /01,
17 // staticFun isn't really a static function and should cause a
18 // compile-time error.
19 static
20 moreStaticFun() {} /// 01: compile-time error
21 int staticFun(int v1, int v2) {
22 return v1 * v2;
23 }
24 }
25
26 class B extends A {
27 B(y) : super(y + 1) {}
28 B.named(y) : super.named(y, y + 1) {}
29 }
30
31 class C {
32 final x;
33 const C(this.x);
34 const C.named(x, int y) : this(x + y);
35 }
36
37 class D extends C {
38 const D(y) : super(y + 1);
39 const D.named(y) : super.named(y, y + 1);
40 }
41
42 class ConstructorRedirectTest {
43 static testMain() {
44 var a = new A(499);
45 Expect.equals(499, a.x);
46 a = new A.named(349, 499);
47 Expect.equals(349 + 499, a.x);
48 a = new A.named2(11, 42, 99);
49 Expect.equals(11 * 42 + 99, a.x);
50
51 var b = new B(498);
52 Expect.equals(499, b.x);
53 b = new B.named(249);
54 Expect.equals(499, b.x);
55
56 C c = const C(499);
57 Expect.equals(499, c.x);
58 c = const C.named(249, 250);
59 Expect.equals(499, c.x);
60
61 D d = const D(498);
62 Expect.equals(499, d.x);
63 d = const D.named(249);
64 Expect.equals(499, d.x);
65 }
66 }
67
68 main() {
69 ConstructorRedirectTest.testMain();
70 }
OLDNEW
« no previous file with comments | « tests/language/src/ConstructorRedirect5NegativeTest.dart ('k') | tests/language/src/ConstructorReturnNegativeTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698