OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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 /// Test that poi.dart finds the right element. | 5 /// Test that poi.dart finds the right element. |
6 | 6 |
7 library trydart.poi_find_test; | 7 library trydart.poi_find_test; |
8 | 8 |
9 import 'dart:io' show | 9 import 'dart:io' show |
10 Platform; | 10 Platform; |
(...skipping 17 matching lines...) Expand all Loading... |
28 Uri script = Platform.script.resolve('data/empty_main.dart'); | 28 Uri script = Platform.script.resolve('data/empty_main.dart'); |
29 FormattingDiagnosticHandler handler = new FormattingDiagnosticHandler(); | 29 FormattingDiagnosticHandler handler = new FormattingDiagnosticHandler(); |
30 handler.verbose = false; | 30 handler.verbose = false; |
31 | 31 |
32 Future future = poi.runPoi(script, 225, handler.provider, handler); | 32 Future future = poi.runPoi(script, 225, handler.provider, handler); |
33 return future.then((Element element) { | 33 return future.then((Element element) { |
34 Uri foundScript = element.compilationUnit.script.resourceUri; | 34 Uri foundScript = element.compilationUnit.script.resourceUri; |
35 Expect.stringEquals('$script', '$foundScript'); | 35 Expect.stringEquals('$script', '$foundScript'); |
36 Expect.stringEquals('main', element.name); | 36 Expect.stringEquals('main', element.name); |
37 | 37 |
38 String source = handler.provider.sourceFiles['$script'].slowText(); | 38 String source = handler.provider.sourceFiles[script].slowText(); |
39 final int position = source.indexOf('main()'); | 39 final int position = source.indexOf('main()'); |
40 Expect.isTrue(position > 0, '$position > 0'); | 40 Expect.isTrue(position > 0, '$position > 0'); |
41 | 41 |
42 var token; | 42 var token; |
43 | 43 |
44 // When the cursor is at the same character offset as "main()", it | 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 | 45 // corresponds to having the cursor just before "main()". So we find the |
46 // "void" token. | 46 // "void" token. |
47 token = poi.findToken(element, position); | 47 token = poi.findToken(element, position); |
48 Expect.isNotNull(token, 'token'); | 48 Expect.isNotNull(token, 'token'); |
(...skipping 18 matching lines...) Expand all Loading... |
67 token = poi.findToken(element, position + 5); | 67 token = poi.findToken(element, position + 5); |
68 Expect.isNotNull(token, 'token'); | 68 Expect.isNotNull(token, 'token'); |
69 Expect.equals(position + 4, token.charOffset, '$token'); | 69 Expect.equals(position + 4, token.charOffset, '$token'); |
70 Expect.stringEquals('(', token.value); | 70 Expect.stringEquals('(', token.value); |
71 }); | 71 }); |
72 } | 72 } |
73 | 73 |
74 void main() { | 74 void main() { |
75 asyncTest(testPoi); | 75 asyncTest(testPoi); |
76 } | 76 } |
OLD | NEW |