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

Side by Side Diff: frog/tests/frog_native/native_class_inheritance4_frog_test.dart

Issue 10536169: Move frog/tests/{leg,leg_only,frog_native} to tests/compiler/. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 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
5 // Additional Dart code may be 'placed on' hidden native classes. With
6 // inheritance, the superclass method must not be reached by a call on the
7 // subclass.
8
9 class A native "*A" {
10 var _field;
11
12 int get X() => _field;
13 void set X(int x) { _field = x; }
14
15 int method(int z) => _field + z;
16 }
17
18 class B extends A native "*B" {
19 var _field2;
20
21 int get X() => _field2;
22 void set X(int x) { _field2 = x; }
23
24 int method(int z) => _field2 + z;
25 }
26
27 A makeA() native { return new A(); }
28 B makeB() native { return new B(); }
29
30 void setup() native @"""
31 function inherits(child, parent) {
32 if (child.prototype.__proto__) {
33 child.prototype.__proto__ = parent.prototype;
34 } else {
35 function tmp() {};
36 tmp.prototype = parent.prototype;
37 child.prototype = new tmp();
38 child.prototype.constructor = child;
39 }
40 }
41
42 function A(){}
43 function B(){}
44 inherits(B, A);
45 makeA = function(){return new A;};
46 makeB = function(){return new B;};
47 """;
48
49 testBasicA_dynamic() {
50 setup(); // Fresh constructors.
51
52 var a = [makeA()][0];
53
54 a.X = 100;
55 Expect.equals(100, a._field);
56 Expect.equals(100, a.X);
57 Expect.equals(150, a.method(50));
58 }
59
60 testBasicA_typed() {
61 setup(); // Fresh constructors.
62
63 A a = makeA();
64
65 a.X = 100;
66 Expect.equals(100, a._field);
67 Expect.equals(100, a.X);
68 Expect.equals(150, a.method(50));
69 }
70
71 testBasicB_dynamic() {
72 setup(); // Fresh constructors.
73
74 var b = [makeB()][0];
75
76 b._field = 1;
77 b.X = 123;
78 Expect.equals(1, b._field);
79 Expect.equals(123, b._field2);
80 Expect.equals(123, b.X);
81 Expect.equals(200, b.method(77));
82 }
83
84 testBasicB_typed() {
85 setup(); // Fresh constructors.
86
87 B b = makeB();
88
89 b._field = 1;
90 b.X = 123;
91 Expect.equals(1, b._field);
92 Expect.equals(123, b._field2);
93 Expect.equals(123, b.X);
94 Expect.equals(200, b.method(77));
95 }
96
97 testAB_dynamic() {
98 setup(); // Fresh constructors.
99
100 var things = [makeA(), makeB()];
101 var a = things[0];
102 var b = things[1];
103
104 a.X = 100;
105 Expect.equals(100, a._field);
106 Expect.equals(100, a.X);
107 Expect.equals(150, a.method(50));
108
109 b._field = 1;
110 b._field2 = 2;
111 b.X = 123;
112 Expect.equals(1, b._field);
113 Expect.equals(123, b._field2);
114 Expect.equals(123, b.X);
115 Expect.equals(200, b.method(77));
116 }
117
118 testAB_typed() {
119 setup(); // Fresh constructors.
120
121 A a = makeA();
122 B b = makeB();
123
124 a.X = 100;
125 Expect.equals(100, a._field);
126 Expect.equals(100, a.X);
127 Expect.equals(150, a.method(50));
128
129 b._field = 1;
130 b._field2 = 2;
131 b.X = 123;
132 Expect.equals(1, b._field);
133 Expect.equals(123, b._field2);
134 Expect.equals(123, b.X);
135 Expect.equals(200, b.method(77));
136 }
137
138 main() {
139 testBasicA_dynamic();
140 testBasicA_typed();
141 testBasicB_dynamic();
142 testBasicB_typed();
143 testAB_dynamic();
144 testAB_typed();
145 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698