Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(340)

Unified Diff: editor/tools/plugins/com.google.dart.tools.core_test/src/com/google/dart/tools/core/search/SearchEngineTest.java

Issue 10915031: Issue 4796. Support for renaming named parameters in invocations (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: editor/tools/plugins/com.google.dart.tools.core_test/src/com/google/dart/tools/core/search/SearchEngineTest.java
diff --git a/editor/tools/plugins/com.google.dart.tools.core_test/src/com/google/dart/tools/core/search/SearchEngineTest.java b/editor/tools/plugins/com.google.dart.tools.core_test/src/com/google/dart/tools/core/search/SearchEngineTest.java
index 35939d3025e6a229cd555ae817bf4a17c090c3ef..26260024d24a9a396891c71731975f67bde24947 100644
--- a/editor/tools/plugins/com.google.dart.tools.core_test/src/com/google/dart/tools/core/search/SearchEngineTest.java
+++ b/editor/tools/plugins/com.google.dart.tools.core_test/src/com/google/dart/tools/core/search/SearchEngineTest.java
@@ -75,31 +75,24 @@ public class SearchEngineTest extends TestCase {
// private DartLibraryImpl moneyLibrary;
- private InMemoryIndex index;
-
- @Override
- public void setUp() {
- try {
-// DartProject moneyProject = getMoneyProject();
-// DartLibrary[] libraries = moneyProject.getDartLibraries();
-// assertNotNull(libraries);
-// assertEquals(1, libraries.length);
-// moneyLibrary = (DartLibraryImpl) libraries[0];
-
- index = InMemoryIndex.getInstance();
- index.initializeIndex();
- } catch (Exception exception) {
- fail("Could not load money project");
- }
+ @SuppressWarnings("unchecked")
+ private static <T extends DartElement> T findElement(CompilationUnit unit, String pattern)
+ throws Exception {
+ int offset = findPattern(unit, pattern);
+ DartElement[] elements = unit.codeSelect(offset, 0);
+ assertThat(elements).hasSize(1);
+ return (T) elements[0];
}
- @Override
- public void tearDown() {
- if (index != null) {
- index.shutdown();
- }
+ private static int findPattern(CompilationUnit unit, String pattern) throws Exception {
+ String unitSource = unit.getSource();
+ int offset = unitSource.indexOf(pattern);
+ assertThat(offset).describedAs(unitSource).isNotEqualTo(-1);
+ return offset;
}
+ private InMemoryIndex index;
+
// scheglov: this test fails for me, probably depends on order of execution
// public void test_searchConstructorDeclarations() throws Exception {
// SearchEngine engine = createSearchEngine();
@@ -144,6 +137,29 @@ public class SearchEngineTest extends TestCase {
// assertEquals(4, matches.size());
// }
+ @Override
+ public void setUp() {
+ try {
+// DartProject moneyProject = getMoneyProject();
Brian Wilkerson 2012/08/31 15:05:36 nit: Unless there's value that I'm not seeing for
scheglov 2012/08/31 15:12:52 Done.
+// DartLibrary[] libraries = moneyProject.getDartLibraries();
+// assertNotNull(libraries);
+// assertEquals(1, libraries.length);
+// moneyLibrary = (DartLibraryImpl) libraries[0];
+
+ index = InMemoryIndex.getInstance();
+ index.initializeIndex();
+ } catch (Exception exception) {
+ fail("Could not load money project");
+ }
+ }
+
+ @Override
+ public void tearDown() {
+ if (index != null) {
+ index.shutdown();
+ }
+ }
+
public void test_searchReferences_field_local() throws Exception {
TestProject testProject = new TestProject();
try {
@@ -849,6 +865,64 @@ public class SearchEngineTest extends TestCase {
}
}
+ public void test_searchReferences_namedParameter_ofFunction() throws Exception {
+ TestProject testProject = new TestProject("Test");
+ try {
+ CompilationUnit unit = testProject.setUnitContent(
+ "Test.dart",
+ buildSource(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "f({test: 0}) {}",
+ "",
+ "void main() {",
+ " f(test: 42);",
+ "}",
+ ""));
+ indexUnits(unit);
+ DartVariableDeclaration variable = findElement(unit, "test: 0");
+ List<SearchMatch> matches = getVariableReferences(variable);
+ assertEquals(1, matches.size());
+ {
+ SearchMatch match = matches.get(0);
+ SourceRange range = match.getSourceRange();
+ assertEquals(findPattern(unit, "test: 42"), range.getOffset());
+ assertEquals("test".length(), range.getLength());
+ }
+ } finally {
+ testProject.dispose();
+ }
+ }
+
+ public void test_searchReferences_namedParameter_ofMethod() throws Exception {
+ TestProject testProject = new TestProject("Test");
+ try {
+ CompilationUnit unit = testProject.setUnitContent(
+ "Test.dart",
+ buildSource(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "class A {",
+ " static f({test: 0}) {}",
+ "}",
+ "",
+ "void main() {",
+ " A.f(test: 42);",
+ "}",
+ ""));
+ indexUnits(unit);
+ DartVariableDeclaration variable = findElement(unit, "test: 0");
+ List<SearchMatch> matches = getVariableReferences(variable);
+ assertEquals(1, matches.size());
+ {
+ SearchMatch match = matches.get(0);
+ SourceRange range = match.getSourceRange();
+ assertEquals(findPattern(unit, "test: 42"), range.getOffset());
+ assertEquals("test".length(), range.getLength());
+ }
+ } finally {
+ testProject.dispose();
+ }
+ }
+
/**
* Test that we {@link SearchMatch#getImportPrefix()}.
*/
@@ -912,6 +986,17 @@ public class SearchEngineTest extends TestCase {
}
}
+// public void test_searchReferences_type() throws Exception {
+// Type type = moneyLibrary.getCompilationUnit("simple_money.dart").getType("SimpleMoney");
+// SearchEngine engine = createSearchEngine();
+// List<SearchMatch> matches = engine.searchReferences(
+// type,
+// SearchScopeFactory.createWorkspaceScope(),
+// null,
+// new NullProgressMonitor());
+// assertEquals(20, matches.size()); // I believe that this should eventually be 17.
+// }
+
public void test_searchReferences_type_fromConstructor_factoryImpl() throws Exception {
TestProject testProject = new TestProject();
try {
@@ -997,17 +1082,6 @@ public class SearchEngineTest extends TestCase {
}
}
-// public void test_searchReferences_type() throws Exception {
-// Type type = moneyLibrary.getCompilationUnit("simple_money.dart").getType("SimpleMoney");
-// SearchEngine engine = createSearchEngine();
-// List<SearchMatch> matches = engine.searchReferences(
-// type,
-// SearchScopeFactory.createWorkspaceScope(),
-// null,
-// new NullProgressMonitor());
-// assertEquals(20, matches.size()); // I believe that this should eventually be 17.
-// }
-
public void test_searchReferences_variable() throws Exception {
TestProject testProject = new TestProject("Test");
try {
@@ -1174,34 +1248,6 @@ public class SearchEngineTest extends TestCase {
return new SearchEngineImpl(index);
}
- // TODO (danrubel): Investigate why test is flaky
-// public void test_searchTypeDeclarations_workspace() throws Exception {
-// SearchEngine engine = createSearchEngine();
-// List<SearchMatch> matches = engine.searchTypeDeclarations(
-// SearchScopeFactory.createWorkspaceScope(),
-// SearchPatternFactory.createPrefixPattern("Money", true),
-// (SearchFilter) null,
-// new NullProgressMonitor());
-// assertEquals(1, matches.size());
-// for (SearchMatch match : matches) {
-// if (isType(match, "Money")) {
-// return;
-// }
-// }
-// fail("Type Money not found");
-// }
-
- @SuppressWarnings("unchecked")
- private <T extends DartElement> T findElement(CompilationUnit unit, String pattern)
- throws DartModelException {
- String unitSource = unit.getSource();
- int offset = unitSource.indexOf(pattern);
- assertThat(offset).describedAs(unitSource).isNotEqualTo(-1);
- DartElement[] elements = unit.codeSelect(offset, 0);
- assertThat(elements).hasSize(1);
- return (T) elements[0];
- }
-
private List<SearchMatch> getFileReferences(IFile targetFile) throws SearchException {
SearchEngine engine = createSearchEngine();
List<SearchMatch> references = engine.searchReferences(

Powered by Google App Engine
This is Rietveld 408576698