Tests for LocalIndex and Dart index contributor.

Pub spec files will be updated before commit.

R=brianwilkerson@google.com
BUG=

Review URL: https://codereview.chromium.org//377053002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@38071 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
scheglov@google.com
2014-07-08 20:53:10 +00:00
parent fd000ad560
commit 6d5773dc5e
10 changed files with 1826 additions and 158 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ dependencies:
path: any
watcher: any
dev_dependencies:
analysis_testing: '>=0.1.0'
analysis_testing: '>=0.2.0'
mock: '>=0.10.0 <0.11.0'
typed_mock: '>=0.0.4 <1.0.0'
unittest: '>=0.10.0 <0.12.0'
@@ -97,6 +97,11 @@ class ElementKindTest {
@ReflectiveTestCase()
class ElementTest extends AbstractContextTest {
engine.Element findElementInUnit(CompilationUnit unit, String name,
[engine.ElementKind kind]) {
return findChildElement(unit.element, name, kind);
}
void test_fromElement_CLASS() {
Source source = addSource('/test.dart', '''
@deprecated
@@ -1075,6 +1075,7 @@ class _IndexContributor extends GeneralizingAstVisitor<Object> {
static Location
_getLocationWithTypeAssignedToField(SimpleIdentifier identifier,
Element element, Location location) {
// TODO(scheglov) decide if we want to remember assigned types
// we need accessor
if (element is! PropertyAccessorElement) {
return location;
@@ -1181,7 +1182,7 @@ class _IndexContributor extends GeneralizingAstVisitor<Object> {
}
Namespace namespace = new NamespaceBuilder(
).createImportNamespaceForDirective(importElement);
Set<Element> elements = new Set();
Set<Element> elements = new Set.from(namespace.definedNames.values);
importElementsMap[importElement] = elements;
}
// use import namespace to choose correct one
+1 -1
View File
@@ -8,5 +8,5 @@ environment:
dependencies:
analyzer: '>=0.21.0 <1.0.0'
dev_dependencies:
analysis_testing: '>=0.1.0 <1.0.0'
analysis_testing: '>=0.2.0 <1.0.0'
unittest: '>=0.10.0 <0.12.0'
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,26 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library test.services.src.index.local_file_index;
import 'dart:io';
import 'package:analysis_services/index/index.dart';
import 'package:analysis_services/index/local_file_index.dart';
import 'package:unittest/unittest.dart';
main() {
groupSep = ' | ';
test('createLocalFileIndex', () {
Directory indexDirectory = Directory.systemTemp.createTempSync(
'AnalysisServer_index');
try {
Index index = createLocalFileIndex(indexDirectory);
expect(index, isNotNull);
} finally {
indexDirectory.delete(recursive: true);
}
});
}
@@ -4,159 +4,148 @@
library test.services.src.index.local_index;
//import 'dart:async';
//import 'dart:io' show Directory;
//
//import 'package:analyzer/src/generated/ast.dart';
//import 'package:analyzer/src/generated/element.dart';
//import 'package:analyzer/src/generated/html.dart';
//import 'package:analyzer/src/generated/source_io.dart';
//import 'package:unittest/unittest.dart';
//
//import '../reflective_tests.dart';
//import 'store/memory_node_manager.dart';
//import 'store/single_source_container.dart';
//import 'package:analyzer/src/index/local_index.dart';
//import 'package:analyzer/index/index.dart';
import 'dart:async';
import 'package:analysis_services/index/index.dart';
import 'package:analysis_services/index/local_memory_index.dart';
import 'package:analysis_services/src/index/local_index.dart';
import 'package:analysis_testing/abstract_context.dart';
import 'package:analysis_testing/reflective_tests.dart';
import 'package:analyzer/src/generated/ast.dart';
import 'package:analyzer/src/generated/html.dart';
import 'package:analyzer/src/generated/source_io.dart';
import 'package:unittest/unittest.dart';
import 'store/single_source_container.dart';
main() {
// groupSep = ' | ';
// group('LocalIndex', () {
//// runReflectiveTests(LocalIndexTest);
// });
groupSep = ' | ';
group('LocalIndex', () {
runReflectiveTests(LocalIndexTest);
});
}
//void _assertElementNames(List<Location> locations, List expected) {
// expect(_toElementNames(locations), unorderedEquals(expected));
//}
//
//
//Iterable<String> _toElementNames(List<Location> locations) {
// return locations.map((loc) => loc.element.name);
//}
void _assertElementNames(List<Location> locations, List expected) {
expect(_toElementNames(locations), unorderedEquals(expected));
}
/**
* TODO(scheglov) Decide what what to do with AbstractContextTest, resource and
* all other testing infrastructure existing in Server, but not in Engine.
*/
class LocalIndexTest {}
//@ReflectiveTestCase()
//class LocalIndexTest extends AbstractContextTest {
// Directory indexDirectory;
// LocalIndex index;
//
// void setUp() {
// super.setUp();
// // prepare Index
// indexDirectory = Directory.systemTemp.createTempSync(
// 'AnalysisServer_index');
// index = new LocalIndex(new MemoryNodeManager());
// }
//
// void tearDown() {
// super.tearDown();
// indexDirectory.delete(recursive: true);
// index = null;
// }
//
// Future test_clear() {
// _indexTest('main() {}');
// return _getDefinedFunctions().then((locations) {
// _assertElementNames(locations, ['main']);
// // clear
// index.clear();
// return _getDefinedFunctions().then((locations) {
// expect(locations, isEmpty);
// });
// });
// }
//
// void test_indexHtmlUnit_nullUnit() {
// index.indexHtmlUnit(context, null);
// }
//
// void test_indexHtmlUnit_nullUnitElement() {
// HtmlUnit unit = new HtmlUnit(null, [], null);
// index.indexHtmlUnit(context, unit);
// }
//
// Future test_indexUnit() {
// _indexTest('main() {}');
// return _getDefinedFunctions().then((locations) {
// _assertElementNames(locations, ['main']);
// });
// }
//
// void test_indexUnit_nullUnit() {
// index.indexUnit(context, null);
// }
//
// void test_indexUnit_nullUnitElement() {
// CompilationUnit unit = new CompilationUnit(null, null, [], [], null);
// index.indexUnit(context, unit);
// }
//
// Future test_removeContext() {
// _indexTest('main() {}');
// return _getDefinedFunctions().then((locations) {
// // OK, there is a location
// _assertElementNames(locations, ['main']);
// // remove context
// index.removeContext(context);
// return _getDefinedFunctions().then((locations) {
// expect(locations, isEmpty);
// });
// });
// }
//
// Future test_removeSource() {
// Source sourceA = _indexLibraryUnit('/testA.dart', 'fa() {}');
// _indexLibraryUnit('/testB.dart', 'fb() {}');
// return _getDefinedFunctions().then((locations) {
// // OK, there are 2 functions
// _assertElementNames(locations, ['fa', 'fb']);
// // remove source
// index.removeSource(context, sourceA);
// return _getDefinedFunctions().then((locations) {
// _assertElementNames(locations, ['fb']);
// });
// });
// }
//
// Future test_removeSources() {
// Source sourceA = _indexLibraryUnit('/testA.dart', 'fa() {}');
// _indexLibraryUnit('/testB.dart', 'fb() {}');
// return _getDefinedFunctions().then((locations) {
// // OK, there are 2 functions
// _assertElementNames(locations, ['fa', 'fb']);
// // remove source(s)
// index.removeSources(context, new SingleSourceContainer(sourceA));
// return _getDefinedFunctions().then((locations) {
// _assertElementNames(locations, ['fb']);
// });
// });
// }
//
// void test_statistics() {
// expect(index.statistics, '[0 locations, 0 sources, 0 names]');
// }
//
// Future<List<Location>> _getDefinedFunctions() {
// return index.getRelationshipsAsync(UniverseElement.INSTANCE,
// IndexConstants.DEFINES_FUNCTION);
// }
//
// Source _indexLibraryUnit(String path, String content) {
// Source source = addSource(path, content);
// CompilationUnit dartUnit = resolveLibraryUnit(source);
// index.indexUnit(context, dartUnit);
// return source;
// }
//
// void _indexTest(String content) {
// _indexLibraryUnit('/test.dart', content);
// }
//}
Iterable<String> _toElementNames(List<Location> locations) {
return locations.map((loc) => loc.element.name);
}
@ReflectiveTestCase()
class LocalIndexTest extends AbstractContextTest {
LocalIndex index;
void setUp() {
super.setUp();
index = createLocalMemoryIndex();
}
void tearDown() {
super.tearDown();
index = null;
}
Future test_clear() {
_indexTest('main() {}');
return _getDefinedFunctions().then((locations) {
_assertElementNames(locations, ['main']);
// clear
index.clear();
return _getDefinedFunctions().then((locations) {
expect(locations, isEmpty);
});
});
}
void test_indexHtmlUnit_nullUnit() {
index.indexHtmlUnit(context, null);
}
void test_indexHtmlUnit_nullUnitElement() {
HtmlUnit unit = new HtmlUnit(null, [], null);
index.indexHtmlUnit(context, unit);
}
Future test_indexUnit() {
_indexTest('main() {}');
return _getDefinedFunctions().then((locations) {
_assertElementNames(locations, ['main']);
});
}
void test_indexUnit_nullUnit() {
index.indexUnit(context, null);
}
void test_indexUnit_nullUnitElement() {
CompilationUnit unit = new CompilationUnit(null, null, [], [], null);
index.indexUnit(context, unit);
}
Future test_removeContext() {
_indexTest('main() {}');
return _getDefinedFunctions().then((locations) {
// OK, there is a location
_assertElementNames(locations, ['main']);
// remove context
index.removeContext(context);
return _getDefinedFunctions().then((locations) {
expect(locations, isEmpty);
});
});
}
Future test_removeSource() {
Source sourceA = _indexLibraryUnit('/testA.dart', 'fa() {}');
_indexLibraryUnit('/testB.dart', 'fb() {}');
return _getDefinedFunctions().then((locations) {
// OK, there are 2 functions
_assertElementNames(locations, ['fa', 'fb']);
// remove source
index.removeSource(context, sourceA);
return _getDefinedFunctions().then((locations) {
_assertElementNames(locations, ['fb']);
});
});
}
Future test_removeSources() {
Source sourceA = _indexLibraryUnit('/testA.dart', 'fa() {}');
_indexLibraryUnit('/testB.dart', 'fb() {}');
return _getDefinedFunctions().then((locations) {
// OK, there are 2 functions
_assertElementNames(locations, ['fa', 'fb']);
// remove source(s)
index.removeSources(context, new SingleSourceContainer(sourceA));
return _getDefinedFunctions().then((locations) {
_assertElementNames(locations, ['fb']);
});
});
}
void test_statistics() {
expect(index.statistics, '[0 locations, 0 sources, 0 names]');
}
Future<List<Location>> _getDefinedFunctions() {
return index.getRelationships(UniverseElement.INSTANCE,
IndexConstants.DEFINES_FUNCTION);
}
Source _indexLibraryUnit(String path, String content) {
Source source = addSource(path, content);
CompilationUnit dartUnit = resolveLibraryUnit(source);
index.indexUnit(context, dartUnit);
return source;
}
void _indexTest(String content) {
_indexLibraryUnit('/test.dart', content);
}
}
@@ -6,6 +6,8 @@ library test.services.src.index.all;
import 'package:unittest/unittest.dart';
import 'dart_index_contributor_test.dart' as dart_index_contributor_test;
import 'local_file_index_test.dart' as local_file_index_test;
import 'local_index_test.dart' as local_index_test;
import 'store/test_all.dart' as store_test_all;
@@ -16,6 +18,8 @@ import 'store/test_all.dart' as store_test_all;
main() {
groupSep = ' | ';
group('index', () {
dart_index_contributor_test.main();
local_file_index_test.main();
local_index_test.main();
store_test_all.main();
});
@@ -5,7 +5,6 @@
library testing.abstract_context;
import 'package:analysis_testing/mock_sdk.dart';
import 'package:analysis_testing/reflective_tests.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/file_system/memory_file_system.dart';
import 'package:analyzer/src/generated/ast.dart';
@@ -16,12 +15,11 @@ import 'package:analyzer/src/generated/source_io.dart';
/**
* Finds an [engine.Element] with the given [name].
* Finds an [Element] with the given [name].
*/
Element findElementInUnit(CompilationUnit unit, String name, [ElementKind kind])
{
Element findChildElement(Element root, String name, [ElementKind kind]) {
Element result = null;
unit.element.accept(new _ElementVisitorFunctionWrapper((Element element) {
root.accept(new _ElementVisitorFunctionWrapper((Element element) {
if (element.name != name) {
return;
}
@@ -40,7 +38,6 @@ Element findElementInUnit(CompilationUnit unit, String name, [ElementKind kind])
typedef void _ElementVisitorFunction(Element element);
@ReflectiveTestCase()
class AbstractContextTest {
static final DartSdk SDK = new MockSdk();
@@ -57,6 +54,10 @@ class AbstractContextTest {
return source;
}
CompilationUnit resolveDartUnit(Source unitSource, Source librarySource) {
return context.resolveCompilationUnit2(unitSource, librarySource);
}
CompilationUnit resolveLibraryUnit(Source source) {
return context.resolveCompilationUnit2(source, source);
}
+1 -1
View File
@@ -1,5 +1,5 @@
name: analysis_testing
version: 0.1.0
version: 0.2.0
author: Dart Team <misc@dartlang.org>
description: A set of libraries for testing Analysis services and server
homepage: http://www.dartlang.org