| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 | 4 |
| 5 library test.invoke_test; | 5 library test.invoke_test; |
| 6 | 6 |
| 7 import 'dart:mirrors'; | 7 import 'dart:mirrors'; |
| 8 | 8 |
| 9 import 'dart:async' show Future; |
| 10 |
| 9 import 'package:expect/expect.dart'; | 11 import 'package:expect/expect.dart'; |
| 10 import "package:async_helper/async_helper.dart"; | 12 import "package:async_helper/async_helper.dart"; |
| 11 | 13 |
| 12 class C { | 14 class C { |
| 13 var field; | 15 var field; |
| 14 C() : this.field = 'default'; | 16 C() : this.field = 'default'; |
| 15 C.named(this.field); | 17 C.named(this.field); |
| 16 | 18 |
| 17 get getter => 'get $field'; | 19 get getter => 'get $field'; |
| 18 set setter(v) => field = 'set $v'; | 20 set setter(v) => field = 'set $v'; |
| 19 method(x, y, z) => '$x+$y+$z'; | 21 method(x, y, z) => '$x+$y+$z'; |
| 20 toString() => 'a C'; | 22 toString() => 'a C'; |
| 21 | 23 |
| 22 noSuchMethod(invocation) => 'DNU'; | 24 noSuchMethod(invocation) => 'DNU'; |
| 23 | 25 |
| 24 static var staticField = 'initial'; | 26 static var staticField = 'initial'; |
| 25 static get staticGetter => 'sget $staticField'; | 27 static get staticGetter => 'sget $staticField'; |
| 26 static set staticSetter(v) => staticField = 'sset $v'; | 28 static set staticSetter(v) => staticField = 'sset $v'; |
| 27 static staticFunction(x, y) => "($x,$y)"; | 29 static staticFunction(x, y) => "($x,$y)"; |
| 28 } | 30 } |
| 29 | 31 |
| 30 var libraryField = 'a priori'; | 32 var libraryField = 'a priori'; |
| 31 get libraryGetter => 'lget $libraryField'; | 33 get libraryGetter => 'lget $libraryField'; |
| 32 set librarySetter(v) => libraryField = 'lset $v'; | 34 set librarySetter(v) => libraryField = 'lset $v'; |
| 33 libraryFunction(x,y) => '$x$y'; | 35 libraryFunction(x,y) => '$x$y'; |
| 34 | 36 |
| 35 Future expectValueThen(Future future, Function onValue) { | 37 Future expectValueThen(Future future, Function onValue) { |
| 36 asyncStart(); | 38 asyncStart(); |
| 37 wrappedOnValue(resultIn) { | 39 wrappedOnValue(resultIn) { |
| 38 var resultOut = onValue(resultIn); | 40 var resultOut = onValue(resultIn); |
| 39 asyncEnd(); | 41 asyncEnd(); |
| 40 return resultOut; | 42 return resultOut; |
| 41 } | 43 } |
| 42 onError(e) { | 44 onError(e) { |
| 43 Expect.fail("Value expected. ($e)"); | 45 Expect.fail("Value expected. ($e)"); |
| 44 } | 46 } |
| 45 return future.then(wrappedOnValue, onError: onError); | 47 return future.then(wrappedOnValue, onError: onError); |
| 46 } | 48 } |
| 47 | 49 |
| 48 Future expectError(Future future, Function errorPredicate, String reason) { | 50 Future expectError(Future future, Function errorPredicate, String reason) { |
| 49 asyncStart(); | 51 asyncStart(); |
| 50 onValue(result) { | 52 onValue(result) { |
| 51 Expect.fail("Error expected ($reason)"); | 53 Expect.fail("Error expected ($reason)"); |
| 52 } | 54 } |
| 53 onError(e) { | 55 onError(e) { |
| 54 asyncEnd(); | 56 asyncEnd(); |
| 55 if (!errorPredicate(e)) { | 57 if (!errorPredicate(e)) { |
| 56 Expect.fail("Unexpected error ($reason)"); | 58 Expect.fail("Unexpected error ($reason)"); |
| 57 } | 59 } |
| 58 } | 60 } |
| 59 return future.then(onValue, onError: onError); | 61 return future.then(onValue, onError: onError); |
| 60 } | 62 } |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 | 268 |
| 267 // ClassMirror invokeSetter | 269 // ClassMirror invokeSetter |
| 268 future = cm.setFieldAsync(const Symbol('staticSetter'), 'sfoo'); | 270 future = cm.setFieldAsync(const Symbol('staticSetter'), 'sfoo'); |
| 269 expectValueThen(future, (result) { | 271 expectValueThen(future, (result) { |
| 270 Expect.equals('sfoo', result.reflectee); | 272 Expect.equals('sfoo', result.reflectee); |
| 271 Expect.equals('sset sfoo', C.staticField); | 273 Expect.equals('sset sfoo', C.staticField); |
| 272 return cm.setFieldAsync(const Symbol('staticField'), 'sbar'); | 274 return cm.setFieldAsync(const Symbol('staticField'), 'sbar'); |
| 273 }).then((result) { | 275 }).then((result) { |
| 274 Expect.equals('sbar', result.reflectee); | 276 Expect.equals('sbar', result.reflectee); |
| 275 Expect.equals('sbar', C.staticField); | 277 Expect.equals('sbar', C.staticField); |
| 276 return cm.setFieldAsync(const Symbol('staticField'), im);; | 278 return cm.setFieldAsync(const Symbol('staticField'), im); |
| 277 }).then((result) { | 279 }).then((result) { |
| 278 Expect.equals(im.reflectee, result.reflectee); | 280 Expect.equals(im.reflectee, result.reflectee); |
| 279 Expect.equals(c, C.staticField); | 281 Expect.equals(c, C.staticField); |
| 280 }); | 282 }); |
| 281 future = cm.setFieldAsync(const Symbol('doesntExist'), 'sbar'); | 283 future = cm.setFieldAsync(const Symbol('doesntExist'), 'sbar'); |
| 282 expectError(future, isNoSuchMethodError, 'Not defined'); | 284 expectError(future, isNoSuchMethodError, 'Not defined'); |
| 283 | 285 |
| 284 // ClassMirror invokeConstructor | 286 // ClassMirror invokeConstructor |
| 285 future = cm.newInstanceAsync(const Symbol(''), []); | 287 future = cm.newInstanceAsync(const Symbol(''), []); |
| 286 expectValueThen(future, (result) { | 288 expectValueThen(future, (result) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 Expect.equals(c, libraryField); | 348 Expect.equals(c, libraryField); |
| 347 }); | 349 }); |
| 348 future = lm.setFieldAsync(const Symbol('doesntExist'), 'lbar'); | 350 future = lm.setFieldAsync(const Symbol('doesntExist'), 'lbar'); |
| 349 expectError(future, isNoSuchMethodError, 'Not defined'); | 351 expectError(future, isNoSuchMethodError, 'Not defined'); |
| 350 } | 352 } |
| 351 | 353 |
| 352 main() { | 354 main() { |
| 353 testSync(); | 355 testSync(); |
| 354 testAsync(); | 356 testAsync(); |
| 355 } | 357 } |
| OLD | NEW |