Chromium Code Reviews| 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 library test.integration.analysis.domain; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 import 'package:analysis_testing/reflective_tests.dart'; | |
| 9 import 'package:path/path.dart'; | |
| 10 import 'package:unittest/unittest.dart'; | |
| 11 | |
| 12 import 'integration_tests.dart'; | |
| 13 | |
| 14 @ReflectiveTestCase() | |
| 15 class AnalysisDomainIntegrationTest extends | |
| 16 AbstractAnalysisServerIntegrationTest { | |
| 17 test_getHover() { | |
| 18 String filename = 'test.dart'; | |
| 19 String pathname = normalizePath(filename); | |
| 20 String text = | |
| 21 r''' | |
| 22 library lib.test; | |
| 23 | |
| 24 List topLevelVar; | |
| 25 | |
| 26 /** | |
| 27 * Documentation for func | |
| 28 */ | |
| 29 void func(int param) { | |
| 30 num localVar = topLevelVar.length; | |
| 31 topLevelVar.length = param; | |
| 32 topLevelVar.add(localVar); | |
| 33 } | |
| 34 | |
| 35 main() { | |
| 36 func(35); | |
| 37 } | |
| 38 '''; | |
| 39 writeFile(filename, text); | |
| 40 setAnalysisRoots(['']); | |
| 41 | |
| 42 testHover(String target, int length, List<String> descriptionRegexps, String | |
| 43 kind, List<String> staticTypeRegexps, {bool isCore: false, String docReg exp: | |
| 44 null, bool isLiteral: false, List<String> parameterRegexps: | |
| 45 null, propagatedType: null}) { | |
| 46 int offset = text.indexOf(target); | |
| 47 return server.send('analysis.getHover', { | |
|
scheglov
2014/07/18 00:03:38
Should we use constants?
Paul Berry
2014/07/18 02:21:15
Yeah, good point. Fixed.
| |
| 48 'file': pathname, | |
| 49 'offset': offset | |
| 50 }).then((result) { | |
| 51 expect(result, isAnalysisGetHoverResult); | |
| 52 expect(result['hovers'], hasLength(1)); | |
| 53 var info = result['hovers'][0]; | |
| 54 expect(info['offset'], equals(offset)); | |
| 55 expect(info['length'], equals(length)); | |
| 56 if (isCore) { | |
| 57 expect(basename(info['containingLibraryPath']), equals('core.dart')); | |
| 58 expect(info['containingLibraryName'], equals('dart.core')); | |
| 59 } else if (isLiteral) { | |
| 60 expect(info['containingLibraryPath'], isNull); | |
| 61 expect(info['containingLibraryName'], isNull); | |
| 62 } else { | |
| 63 expect(info['containingLibraryPath'], equals(pathname)); | |
| 64 expect(info['containingLibraryName'], equals('lib.test')); | |
| 65 } | |
| 66 if (docRegexp == null) { | |
| 67 expect(info['dartdoc'], isNull); | |
| 68 } else { | |
| 69 expect(info['dartdoc'], matches(docRegexp)); | |
| 70 } | |
| 71 if (descriptionRegexps == null) { | |
| 72 expect(info['elementDescription'], isNull); | |
| 73 } else { | |
| 74 expect(info['elementDescription'], isString); | |
| 75 for (String descriptionRegexp in descriptionRegexps) { | |
| 76 expect(info['elementDescription'], matches(descriptionRegexp)); | |
| 77 } | |
| 78 } | |
| 79 expect(info['elementKind'], equals(kind)); | |
| 80 if (parameterRegexps == null) { | |
| 81 expect(info['parameter'], isNull); | |
| 82 } else { | |
| 83 expect(info['parameter'], isString); | |
| 84 for (String parameterRegexp in parameterRegexps) { | |
| 85 expect(info['parameter'], matches(parameterRegexp)); | |
| 86 } | |
| 87 } | |
| 88 expect(info['propagatedType'], equals(propagatedType)); | |
| 89 if (staticTypeRegexps == null) { | |
| 90 expect(info['staticType'], isNull); | |
| 91 } else { | |
| 92 expect(info['staticType'], isString); | |
| 93 for (String staticTypeRegexp in staticTypeRegexps) { | |
| 94 expect(info['staticType'], matches(staticTypeRegexp)); | |
| 95 } | |
| 96 } | |
| 97 }); | |
| 98 } | |
| 99 | |
| 100 // Note: analysis.getHover doesn't wait for analysis to complete--it simply | |
| 101 // returns the latest results that are available at the time that the | |
| 102 // request is made. So wait for analysis to finish before testing anything. | |
| 103 return analysisFinished.then((_) { | |
| 104 List<Future> tests = []; | |
| 105 tests.add(testHover('topLevelVar;', 11, ['List', 'topLevelVar'], | |
| 106 'top level variable', ['List'])); | |
| 107 tests.add(testHover('func(', 4, ['func', 'int', 'param'], 'function', | |
| 108 ['int', 'void'], docRegexp: 'Documentation for func')); | |
| 109 tests.add(testHover('int param', 3, ['int'], 'class', ['int'], isCore: | |
| 110 true, docRegexp: '.*')); | |
| 111 tests.add(testHover('param)', 5, ['int', 'param'], 'parameter', ['int'], | |
| 112 docRegexp: 'Documentation for func')); | |
| 113 tests.add(testHover('num localVar', 3, ['num'], 'class', ['num'], isCore: | |
| 114 true, docRegexp: '.*')); | |
| 115 tests.add(testHover('localVar =', 8, ['num', 'localVar'], | |
| 116 'local variable', ['num'], propagatedType: 'int')); | |
| 117 tests.add(testHover('topLevelVar.length;', 11, ['List', 'topLevelVar'], | |
| 118 'top level variable', ['List'])); | |
| 119 tests.add(testHover('length;', 6, ['get', 'length', 'int'], 'getter', | |
| 120 ['int'], isCore: true, docRegexp: '.*')); | |
| 121 tests.add(testHover('length =', 6, ['set', 'length', 'int'], 'setter', | |
| 122 ['int'], isCore: true, docRegexp: '.*')); | |
| 123 tests.add(testHover('param;', 5, ['int', 'param'], 'parameter', ['int'], | |
| 124 docRegexp: 'Documentation for func')); | |
| 125 tests.add(testHover('add(', 3, ['List', 'add'], 'method', null, isCore: | |
| 126 true, docRegexp: '.*')); | |
| 127 tests.add(testHover('localVar)', 8, ['num', 'localVar'], 'local variable', | |
| 128 ['num'], parameterRegexps: ['.*'], propagatedType: 'int')); | |
| 129 tests.add(testHover('func(35', 4, ['func', 'int', 'param'], 'function', | |
| 130 null, docRegexp: 'Documentation for func')); | |
| 131 tests.add(testHover('35', 2, null, null, ['int'], isLiteral: true, | |
| 132 parameterRegexps: ['int', 'param'])); | |
| 133 return Future.wait(tests); | |
| 134 }); | |
| 135 } | |
| 136 | |
| 137 fail_test_getHover_noInfo() { | |
| 138 String filename = 'test.dart'; | |
| 139 String pathname = normalizePath(filename); | |
| 140 String text = | |
| 141 r''' | |
| 142 main() { | |
| 143 // no code | |
| 144 } | |
| 145 '''; | |
| 146 writeFile(filename, text); | |
| 147 setAnalysisRoots(['']); | |
| 148 | |
| 149 // Note: analysis.getHover doesn't wait for analysis to complete--it simply | |
| 150 // returns the latest results that are available at the time that the | |
| 151 // request is made. So wait for analysis to finish before testing anything. | |
| 152 return analysisFinished.then((_) { | |
| 153 return server.send('analysis.getHover', { | |
| 154 'file': pathname, | |
| 155 'offset': text.indexOf('no code') | |
| 156 }).then((result) { | |
| 157 expect(result, isAnalysisGetHoverResult); | |
| 158 expect(result['hovers'], hasLength(0)); | |
| 159 }); | |
| 160 }); | |
| 161 } | |
| 162 } | |
| 163 | |
| 164 main() { | |
| 165 runReflectiveTests(AnalysisDomainIntegrationTest); | |
| 166 } | |
| OLD | NEW |