OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, 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 library implicit_getter_setter_test; |
| 6 |
| 7 import 'package:observatory/service_io.dart'; |
| 8 import 'package:unittest/unittest.dart'; |
| 9 import 'test_helper.dart'; |
| 10 |
| 11 class A { |
| 12 double field = 0.0; |
| 13 } |
| 14 |
| 15 script() { |
| 16 for (int i = 0; i < 10; i++) { |
| 17 new A(); |
| 18 } |
| 19 } |
| 20 |
| 21 testGetter(Isolate isolate) async { |
| 22 Library rootLibrary = await isolate.rootLibrary.load(); |
| 23 expect(rootLibrary.classes.length, equals(1)); |
| 24 Class classA = await rootLibrary.classes[0].load(); |
| 25 expect(classA.name, equals('A')); |
| 26 // Find getter. |
| 27 ServiceFunction getterFunc; |
| 28 for (ServiceFunction function in classA.functions) { |
| 29 if (function.name == 'field') { |
| 30 getterFunc = function; |
| 31 break; |
| 32 } |
| 33 } |
| 34 expect(getterFunc, isNotNull); |
| 35 await getterFunc.load(); |
| 36 Field field = await getterFunc.field.load(); |
| 37 expect(field, isNotNull); |
| 38 expect(field.name, equals('field')); |
| 39 Class classDouble = await field.guardClass.load(); |
| 40 expect(classDouble.name, equals('_Double')); |
| 41 } |
| 42 |
| 43 |
| 44 testSetter(Isolate isolate) async { |
| 45 Library rootLibrary = await isolate.rootLibrary.load(); |
| 46 expect(rootLibrary.classes.length, equals(1)); |
| 47 Class classA = await rootLibrary.classes[0].load(); |
| 48 expect(classA.name, equals('A')); |
| 49 // Find setter. |
| 50 ServiceFunction setterFunc; |
| 51 for (ServiceFunction function in classA.functions) { |
| 52 if (function.name == 'field=') { |
| 53 setterFunc = function; |
| 54 break; |
| 55 } |
| 56 } |
| 57 expect(setterFunc, isNotNull); |
| 58 await setterFunc.load(); |
| 59 Field field = await setterFunc.field.load(); |
| 60 expect(field, isNotNull); |
| 61 expect(field.name, equals('field')); |
| 62 Class classDouble = await field.guardClass.load(); |
| 63 expect(classDouble.name, equals('_Double')); |
| 64 } |
| 65 |
| 66 |
| 67 var tests = [testGetter, testSetter]; |
| 68 |
| 69 main(args) => runIsolateTests(args, tests, testeeBefore: script); |
OLD | NEW |