OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014, 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 /// Test that poi.dart can serialize a scope. |
| 6 |
| 7 library trydart.serialize_test; |
| 8 |
| 9 import 'dart:io' show |
| 10 Platform; |
| 11 |
| 12 import 'dart:async' show |
| 13 Future; |
| 14 |
| 15 import 'dart:convert' show |
| 16 JSON; |
| 17 |
| 18 import 'package:try/poi/poi.dart' as poi; |
| 19 |
| 20 import 'package:async_helper/async_helper.dart'; |
| 21 |
| 22 import 'package:expect/expect.dart'; |
| 23 |
| 24 import 'package:compiler/implementation/elements/elements.dart' show |
| 25 Element; |
| 26 |
| 27 import 'package:compiler/implementation/source_file_provider.dart' show |
| 28 FormattingDiagnosticHandler; |
| 29 |
| 30 Future testPoi() { |
| 31 Uri script = Platform.script.resolve('data/interesting.dart'); |
| 32 FormattingDiagnosticHandler handler = new FormattingDiagnosticHandler(); |
| 33 |
| 34 int position = 241; |
| 35 Future future = poi.runPoi(script, position, handler.provider, handler); |
| 36 return future.then((Element element) { |
| 37 Uri foundScript = element.compilationUnit.script.resourceUri; |
| 38 Expect.stringEquals('$script', '$foundScript'); |
| 39 Expect.stringEquals('fisk', element.name); |
| 40 |
| 41 Expect.stringEquals( |
| 42 JSON.encode(expected), |
| 43 JSON.encode(JSON.decode(poi.scopeInformation(element, position)))); |
| 44 }); |
| 45 } |
| 46 |
| 47 void main() { |
| 48 asyncTest(testPoi); |
| 49 } |
| 50 |
| 51 final expected = { |
| 52 "name": "fisk", |
| 53 "kind": "function", |
| 54 "enclosing": { |
| 55 "name": "Foo", |
| 56 "kind": "class", |
| 57 "members": [ |
| 58 { |
| 59 "name": "fisk", |
| 60 "kind": "function" |
| 61 }, |
| 62 { |
| 63 "name": "hest", |
| 64 "kind": "function" |
| 65 }, |
| 66 { |
| 67 "name": "", |
| 68 "kind": "generative_constructor" |
| 69 } |
| 70 ], |
| 71 "enclosing": { |
| 72 "name": "tests/try/poi/data/interesting.dart", |
| 73 "kind": "library", |
| 74 "members": [ |
| 75 { |
| 76 "name": "main", |
| 77 "kind": "function" |
| 78 }, |
| 79 { |
| 80 "name": "Foo", |
| 81 "kind": "class" |
| 82 } |
| 83 ] |
| 84 } |
| 85 } |
| 86 }; |
OLD | NEW |