OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013, 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 // TODO(ahe): This test is sligthly broken but provides temporary test coverage |
| 6 // for dart2js. See http://dartbug.com/12464. |
| 7 |
| 8 library test.mixin_test; |
| 9 |
| 10 @MirrorsUsed(targets: 'test.mixin_test, test.model, Object', override: '*') |
| 11 import 'dart:mirrors'; |
| 12 |
| 13 import 'package:expect/expect.dart'; |
| 14 |
| 15 import 'model.dart'; |
| 16 import 'stringify.dart'; |
| 17 |
| 18 class Mixin { |
| 19 int i; |
| 20 m() {} |
| 21 } |
| 22 |
| 23 class Mixin2 { |
| 24 int i2; |
| 25 m2() {} |
| 26 } |
| 27 |
| 28 typedef MixinApplication = C with Mixin; |
| 29 typedef MixinApplicationA = C with Mixin, Mixin2; |
| 30 |
| 31 typedef UnusedMixinApplication = C with Mixin; |
| 32 |
| 33 class Subclass extends C with Mixin { |
| 34 f() {} |
| 35 } |
| 36 |
| 37 class Subclass2 extends MixinApplication { |
| 38 g() {} |
| 39 } |
| 40 |
| 41 class SubclassA extends C with Mixin, Mixin2 { |
| 42 fa() {} |
| 43 } |
| 44 |
| 45 class Subclass2A extends MixinApplicationA { |
| 46 ga() {} |
| 47 } |
| 48 |
| 49 checkClass(Type type, List<String> expectedSuperclasses) { |
| 50 int i = 0; |
| 51 for (var cls = reflectClass(type); cls != null; cls = cls.superclass) { |
| 52 expect(expectedSuperclasses[i++], cls); |
| 53 } |
| 54 Expect.equals(i, expectedSuperclasses.length, '$type'); |
| 55 } |
| 56 |
| 57 expectSame(ClassMirror a, ClassMirror b) { |
| 58 Expect.equals(a, b); |
| 59 expect(stringify(a), b); |
| 60 expect(stringify(b), a); |
| 61 } |
| 62 |
| 63 testMixin() { |
| 64 checkClass(Mixin, [ |
| 65 'Class(s(Mixin) in s(test.mixin_test), top-level)', |
| 66 'Class(s(Object) in s(dart.core), top-level)', |
| 67 ]); |
| 68 expect( |
| 69 '{Mixin: Method(s(Mixin) in s(Mixin), constructor),' |
| 70 ' i: Variable(s(i) in s(Mixin)),' |
| 71 ' m: Method(s(m) in s(Mixin))}', |
| 72 reflectClass(Mixin).members); |
| 73 } |
| 74 |
| 75 testMixin2() { |
| 76 checkClass(Mixin2, [ |
| 77 'Class(s(Mixin2) in s(test.mixin_test), top-level)', |
| 78 'Class(s(Object) in s(dart.core), top-level)', |
| 79 ]); |
| 80 expect( |
| 81 '{Mixin2: Method(s(Mixin2) in s(Mixin2), constructor),' |
| 82 ' i2: Variable(s(i2) in s(Mixin2)),' |
| 83 ' m2: Method(s(m2) in s(Mixin2))}', |
| 84 reflectClass(Mixin2).members); |
| 85 } |
| 86 |
| 87 testMixinApplication() { |
| 88 checkClass(MixinApplication, [ |
| 89 'Class(s(MixinApplication) in s(test.mixin_test), top-level)', |
| 90 'Class(s(C) in s(test.model), top-level)', |
| 91 'Class(s(B) in s(test.model), top-level)', |
| 92 'Class(s(A) in s(test.model), top-level)', |
| 93 'Class(s(Object) in s(dart.core), top-level)', |
| 94 ]); |
| 95 |
| 96 expect( |
| 97 '{MixinApplication: Method(s(MixinApplication) in s(MixinApplication),' |
| 98 ' constructor),' |
| 99 ' i: Variable(s(i) in s(MixinApplication)),' |
| 100 ' m: Method(s(m) in s(MixinApplication))}', |
| 101 reflectClass(MixinApplication).members); |
| 102 |
| 103 expectSame(reflectClass(C), reflectClass(MixinApplication).superclass); |
| 104 } |
| 105 |
| 106 testMixinApplicationA() { |
| 107 checkClass(MixinApplicationA, [ |
| 108 'Class(s(MixinApplicationA) in s(test.mixin_test), top-level)', |
| 109 'Class(s(test.mixin_test.Mixin(test.model.C)), top-level)', |
| 110 'Class(s(C) in s(test.model), top-level)', |
| 111 'Class(s(B) in s(test.model), top-level)', |
| 112 'Class(s(A) in s(test.model), top-level)', |
| 113 'Class(s(Object) in s(dart.core), top-level)', |
| 114 ]); |
| 115 |
| 116 expect( |
| 117 '{MixinApplicationA: Method(s(MixinApplicationA) in s(MixinApplicationA),' |
| 118 ' constructor),' |
| 119 ' i2: Variable(s(i2) in s(MixinApplicationA)),' |
| 120 ' m2: Method(s(m2) in s(MixinApplicationA))}', |
| 121 reflectClass(MixinApplicationA).members); |
| 122 |
| 123 expect( |
| 124 // TODO(ahe): The owner should probably be the mixin application. |
| 125 '{Mixin: Method(s(Mixin) in s(Mixin), constructor),' |
| 126 ' i: Variable(s(i) in s(Mixin)),' |
| 127 ' m: Method(s(m) in s(Mixin))}', |
| 128 reflectClass(MixinApplicationA).superclass.members); |
| 129 |
| 130 expectSame( |
| 131 reflectClass(C), |
| 132 reflectClass(MixinApplicationA).superclass.superclass); |
| 133 } |
| 134 |
| 135 testUnusedMixinApplication() { |
| 136 checkClass(UnusedMixinApplication, [ |
| 137 'Class(s(UnusedMixinApplication) in s(test.mixin_test), top-level)', |
| 138 'Class(s(C) in s(test.model), top-level)', |
| 139 'Class(s(B) in s(test.model), top-level)', |
| 140 'Class(s(A) in s(test.model), top-level)', |
| 141 'Class(s(Object) in s(dart.core), top-level)', |
| 142 ]); |
| 143 |
| 144 expect( |
| 145 '{UnusedMixinApplication: Method(s(UnusedMixinApplication)' |
| 146 ' in s(UnusedMixinApplication), constructor),' |
| 147 ' i: Variable(s(i) in s(UnusedMixinApplication)),' |
| 148 ' m: Method(s(m) in s(UnusedMixinApplication))}', |
| 149 reflectClass(UnusedMixinApplication).members); |
| 150 |
| 151 expectSame(reflectClass(C), reflectClass(UnusedMixinApplication).superclass); |
| 152 } |
| 153 |
| 154 testSubclass() { |
| 155 checkClass(Subclass, [ |
| 156 'Class(s(Subclass) in s(test.mixin_test), top-level)', |
| 157 'Class(s(test.mixin_test.Mixin(test.model.C)), top-level)', |
| 158 'Class(s(C) in s(test.model), top-level)', |
| 159 'Class(s(B) in s(test.model), top-level)', |
| 160 'Class(s(A) in s(test.model), top-level)', |
| 161 'Class(s(Object) in s(dart.core), top-level)', |
| 162 ]); |
| 163 |
| 164 expect( |
| 165 '{Subclass: Method(s(Subclass) in s(Subclass), constructor),' |
| 166 ' f: Method(s(f) in s(Subclass))}', |
| 167 reflectClass(Subclass).members); |
| 168 |
| 169 expect( |
| 170 // TODO(ahe): The owner should probably be the mixin application. |
| 171 '{Mixin: Method(s(Mixin) in s(Mixin), constructor),' |
| 172 ' i: Variable(s(i) in s(Mixin)),' |
| 173 ' m: Method(s(m) in s(Mixin))}', |
| 174 reflectClass(Subclass).superclass.members); |
| 175 |
| 176 expectSame( |
| 177 reflectClass(C), |
| 178 reflectClass(Subclass).superclass.superclass); |
| 179 } |
| 180 |
| 181 testSubclass2() { |
| 182 checkClass(Subclass2, [ |
| 183 'Class(s(Subclass2) in s(test.mixin_test), top-level)', |
| 184 'Class(s(MixinApplication) in s(test.mixin_test), top-level)', |
| 185 'Class(s(C) in s(test.model), top-level)', |
| 186 'Class(s(B) in s(test.model), top-level)', |
| 187 'Class(s(A) in s(test.model), top-level)', |
| 188 'Class(s(Object) in s(dart.core), top-level)', |
| 189 ]); |
| 190 |
| 191 expect( |
| 192 '{Subclass2: Method(s(Subclass2) in s(Subclass2), constructor),' |
| 193 ' g: Method(s(g) in s(Subclass2))}', |
| 194 reflectClass(Subclass2).members); |
| 195 |
| 196 expectSame( |
| 197 reflectClass(MixinApplication), |
| 198 reflectClass(Subclass2).superclass); |
| 199 } |
| 200 |
| 201 testSubclassA() { |
| 202 checkClass(SubclassA, [ |
| 203 'Class(s(SubclassA) in s(test.mixin_test), top-level)', |
| 204 'Class(s(test.mixin_test.Mixin2(test.mixin_test.Mixin(test.model.C))),' |
| 205 ' top-level)', |
| 206 'Class(s(test.mixin_test.Mixin(test.model.C)), top-level)', |
| 207 'Class(s(C) in s(test.model), top-level)', |
| 208 'Class(s(B) in s(test.model), top-level)', |
| 209 'Class(s(A) in s(test.model), top-level)', |
| 210 'Class(s(Object) in s(dart.core), top-level)', |
| 211 ]); |
| 212 |
| 213 expect( |
| 214 '{SubclassA: Method(s(SubclassA) in s(SubclassA), constructor),' |
| 215 ' fa: Method(s(fa) in s(SubclassA))}', |
| 216 reflectClass(SubclassA).members); |
| 217 |
| 218 expect( |
| 219 // TODO(ahe): The owner should probably be the mixin application. |
| 220 '{Mixin2: Method(s(Mixin2) in s(Mixin2), constructor),' |
| 221 ' i2: Variable(s(i2) in s(Mixin2)),' |
| 222 ' m2: Method(s(m2) in s(Mixin2))}', |
| 223 reflectClass(SubclassA).superclass.members); |
| 224 |
| 225 expect( |
| 226 // TODO(ahe): The owner should probably be the mixin application. |
| 227 '{Mixin: Method(s(Mixin) in s(Mixin), constructor),' |
| 228 ' i: Variable(s(i) in s(Mixin)),' |
| 229 ' m: Method(s(m) in s(Mixin))}', |
| 230 reflectClass(SubclassA).superclass.superclass.members); |
| 231 |
| 232 expectSame( |
| 233 reflectClass(C), |
| 234 reflectClass(SubclassA).superclass.superclass.superclass); |
| 235 } |
| 236 |
| 237 testSubclass2A() { |
| 238 checkClass(Subclass2A, [ |
| 239 'Class(s(Subclass2A) in s(test.mixin_test), top-level)', |
| 240 'Class(s(MixinApplicationA) in s(test.mixin_test), top-level)', |
| 241 'Class(s(test.mixin_test.Mixin(test.model.C)), top-level)', |
| 242 'Class(s(C) in s(test.model), top-level)', |
| 243 'Class(s(B) in s(test.model), top-level)', |
| 244 'Class(s(A) in s(test.model), top-level)', |
| 245 'Class(s(Object) in s(dart.core), top-level)', |
| 246 ]); |
| 247 |
| 248 expect( |
| 249 '{Subclass2A: Method(s(Subclass2A) in s(Subclass2A), constructor),' |
| 250 ' ga: Method(s(ga) in s(Subclass2A))}', |
| 251 reflectClass(Subclass2A).members); |
| 252 |
| 253 expectSame(reflectClass(MixinApplicationA), |
| 254 reflectClass(Subclass2A).superclass); |
| 255 } |
| 256 |
| 257 main() { |
| 258 testMixin(); |
| 259 testMixin2(); |
| 260 testMixinApplication(); |
| 261 testMixinApplicationA(); |
| 262 testUnusedMixinApplication(); |
| 263 testSubclass(); |
| 264 testSubclass2(); |
| 265 testSubclassA(); |
| 266 testSubclass2A(); |
| 267 } |
OLD | NEW |