| 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 library test.completion.support; | 5 library test.completion.support; |
| 6 | 6 |
| 7 import 'dart:async'; |
| 7 import 'dart:collection'; | 8 import 'dart:collection'; |
| 8 | 9 |
| 9 import 'package:analysis_server/src/protocol.dart'; | 10 import 'package:analysis_server/src/protocol.dart'; |
| 10 import 'package:analyzer/src/generated/java_core.dart'; | 11 import 'package:analyzer/src/generated/java_core.dart'; |
| 11 import 'package:unittest/unittest.dart'; | 12 import 'package:unittest/unittest.dart'; |
| 12 | 13 |
| 13 import 'domain_completion_test.dart'; | 14 import 'domain_completion_test.dart'; |
| 14 import 'dart:async'; | |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * A base class for classes containing completion tests. | 17 * A base class for classes containing completion tests. |
| 18 */ | 18 */ |
| 19 class CompletionTestCase extends CompletionTest { | 19 class CompletionTestCase extends CompletionTest { |
| 20 static const String CURSOR_MARKER = '!'; | 20 static const String CURSOR_MARKER = '!'; |
| 21 | 21 |
| 22 List get suggestedCompletions => | 22 List get suggestedCompletions => |
| 23 suggestions.map( | 23 suggestions.map( |
| 24 (CompletionSuggestion suggestion) => suggestion.completion).toList(); | 24 (CompletionSuggestion suggestion) => suggestion.completion).toList(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 46 } | 46 } |
| 47 }); | 47 }); |
| 48 if (matchingSuggestion == null) { | 48 if (matchingSuggestion == null) { |
| 49 fail("Expected '$completion' but found none:\n $suggestedCompletions"); | 49 fail("Expected '$completion' but found none:\n $suggestedCompletions"); |
| 50 } | 50 } |
| 51 expect(matchingSuggestion.selectionOffset, equals(expectedOffset)); | 51 expect(matchingSuggestion.selectionOffset, equals(expectedOffset)); |
| 52 expect(matchingSuggestion.selectionLength, equals(0)); | 52 expect(matchingSuggestion.selectionLength, equals(0)); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void assertHasNoCompletion(String completion) { | 55 void assertHasNoCompletion(String completion) { |
| 56 // As a temporary measure, disable negative tests. | |
| 57 // TODO(paulberry): fix this. | |
| 58 return; | |
| 59 if (suggestions.any( | 56 if (suggestions.any( |
| 60 (CompletionSuggestion suggestion) => suggestion.completion == completion
)) { | 57 (CompletionSuggestion suggestion) => suggestion.completion == completion
)) { |
| 61 fail( | 58 fail( |
| 62 "Did not expect completion '$completion' but found:\n $suggestedCompl
etions"); | 59 "Did not expect completion '$completion' but found:\n $suggestedCompl
etions"); |
| 63 } | 60 } |
| 64 } | 61 } |
| 65 | 62 |
| 63 /** |
| 64 * Discard any results that do not start with the characters the user has |
| 65 * "already typed". |
| 66 */ |
| 67 void filterResults(String content) { |
| 68 String charsAlreadyTyped = |
| 69 content.substring(replacementOffset, completionOffset).toLowerCase(); |
| 70 suggestions = suggestions.where( |
| 71 (CompletionSuggestion suggestion) => |
| 72 suggestion.completion.toLowerCase().startsWith(charsAlreadyTyped)).t
oList(); |
| 73 } |
| 74 |
| 66 runTest(LocationSpec spec, [Map<String, String> extraFiles]) { | 75 runTest(LocationSpec spec, [Map<String, String> extraFiles]) { |
| 67 super.setUp(); | 76 super.setUp(); |
| 68 return new Future(() { | 77 return new Future(() { |
| 69 String content = spec.source; | 78 String content = spec.source; |
| 70 addFile(testFile, content); | 79 addFile(testFile, content); |
| 71 this.testCode = content; | 80 this.testCode = content; |
| 72 completionOffset = spec.testLocation; | 81 completionOffset = spec.testLocation; |
| 73 if (extraFiles != null) { | 82 if (extraFiles != null) { |
| 74 extraFiles.forEach((String fileName, String content) { | 83 extraFiles.forEach((String fileName, String content) { |
| 75 addFile(fileName, content); | 84 addFile(fileName, content); |
| 76 }); | 85 }); |
| 77 } | 86 } |
| 78 }).then((_) => getSuggestions()).then((_) { | 87 }).then((_) => getSuggestions()).then((_) { |
| 79 //expect(replacementOffset, equals(completionOffset)); | 88 filterResults(spec.source); |
| 80 //expect(replacementLength, equals(0)); | |
| 81 for (String result in spec.positiveResults) { | 89 for (String result in spec.positiveResults) { |
| 82 assertHasCompletion(result); | 90 assertHasCompletion(result); |
| 83 } | 91 } |
| 84 for (String result in spec.negativeResults) { | 92 for (String result in spec.negativeResults) { |
| 85 assertHasNoCompletion(result); | 93 assertHasNoCompletion(result); |
| 86 } | 94 } |
| 87 }).whenComplete(() { | 95 }).whenComplete(() { |
| 88 super.tearDown(); | 96 super.tearDown(); |
| 89 }); | 97 }); |
| 90 } | 98 } |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 err | 263 err |
| 256 ..write(' ') | 264 ..write(' ') |
| 257 ..write(ch); | 265 ..write(ch); |
| 258 } | 266 } |
| 259 } | 267 } |
| 260 throw new IllegalStateException(err.toString()); | 268 throw new IllegalStateException(err.toString()); |
| 261 } | 269 } |
| 262 return tests.values.toList(); | 270 return tests.values.toList(); |
| 263 } | 271 } |
| 264 } | 272 } |
| OLD | NEW |