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 finds the right element. | |
6 | |
7 library trydart.poi_find_test; | |
8 | |
9 import 'dart:io' show | |
10 Platform; | |
11 | |
12 import 'dart:async' show | |
13 Future; | |
14 | |
15 import 'package:try/poi/poi.dart' as poi; | |
16 | |
17 import 'package:async_helper/async_helper.dart'; | |
18 | |
19 import 'package:expect/expect.dart'; | |
20 | |
21 import 'package:compiler/src/elements/elements.dart' show | |
22 Element; | |
23 | |
24 import 'package:compiler/src/source_file_provider.dart' show | |
25 FormattingDiagnosticHandler; | |
26 | |
27 Future testPoi() { | |
28 Uri script = Platform.script.resolve('data/empty_main.dart'); | |
29 FormattingDiagnosticHandler handler = new FormattingDiagnosticHandler(); | |
30 handler.verbose = false; | |
31 | |
32 Future future = poi.runPoi(script, 225, handler.provider, handler); | |
33 return future.then((Element element) { | |
34 Uri foundScript = element.compilationUnit.script.resourceUri; | |
35 Expect.stringEquals('$script', '$foundScript'); | |
36 Expect.stringEquals('main', element.name); | |
37 | |
38 String source = handler.provider.sourceFiles[script].slowText(); | |
39 final int position = source.indexOf('main()'); | |
40 Expect.isTrue(position > 0, '$position > 0'); | |
41 | |
42 var token; | |
43 | |
44 // When the cursor is at the same character offset as "main()", it | |
45 // corresponds to having the cursor just before "main()". So we find the | |
46 // "void" token. | |
47 token = poi.findToken(element, position); | |
48 Expect.isNotNull(token, 'token'); | |
49 Expect.stringEquals('void', token.value); | |
50 | |
51 // Cursor at position + 1 corresponds to having the cursor just after "m" | |
52 // in "main()". So we find the "main" token. | |
53 token = poi.findToken(element, position + 1); | |
54 Expect.isNotNull(token, 'token'); | |
55 Expect.equals(position, token.charOffset); | |
56 Expect.stringEquals('main', token.value); | |
57 | |
58 // This corresponds to the cursor after "main", but before "()" in | |
59 // "main()". So we find the "main" token. | |
60 token = poi.findToken(element, position + 4); | |
61 Expect.isNotNull(token, 'token'); | |
62 Expect.equals(position, token.charOffset); | |
63 Expect.stringEquals('main', token.value); | |
64 | |
65 // This corresponds to the cursor after "(" in "main()". So we find the "(" | |
66 // token. | |
67 token = poi.findToken(element, position + 5); | |
68 Expect.isNotNull(token, 'token'); | |
69 Expect.equals(position + 4, token.charOffset, '$token'); | |
70 Expect.stringEquals('(', token.value); | |
71 }); | |
72 } | |
73 | |
74 void main() { | |
75 asyncTest(testPoi); | |
76 } | |
OLD | NEW |