0db404e598
BUG=dartbug.com/15287 R=alanknight@google.com, efortuna@google.com Committed: https://code.google.com/p/dart/source/detail?r=30634 Review URL: https://codereview.chromium.org//83173012 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@30644 260f80e4-7a28-3924-810f-c04153c831b5
137 lines
4.6 KiB
Dart
137 lines
4.6 KiB
Dart
library single_library_test;
|
|
|
|
import 'dart:io';
|
|
|
|
import 'package:path/path.dart' as path;
|
|
import 'package:unittest/unittest.dart';
|
|
|
|
import '../lib/docgen.dart';
|
|
|
|
const String DART_LIBRARY = '''
|
|
library test;
|
|
/**
|
|
* Doc comment for class [A].
|
|
*
|
|
* Multiline Test
|
|
*/
|
|
/*
|
|
* Normal comment for class A.
|
|
*/
|
|
class A {
|
|
|
|
int _someNumber;
|
|
|
|
A() {
|
|
_someNumber = 12;
|
|
}
|
|
|
|
/**
|
|
* Test for linking to parameter [A]
|
|
*/
|
|
void doThis(int A) {
|
|
print(A);
|
|
}
|
|
}
|
|
|
|
main() {
|
|
A a = new A();
|
|
a.doThis(5);
|
|
}
|
|
''';
|
|
|
|
main() {
|
|
group('Generate docs for', () {
|
|
test('one simple file.', () {
|
|
var temporaryDir = Directory.systemTemp.createTempSync('single_library_');
|
|
var fileName = path.join(temporaryDir.path, 'temp.dart');
|
|
var file = new File(fileName);
|
|
file.writeAsStringSync(DART_LIBRARY);
|
|
getMirrorSystem([new Uri.file(fileName)])
|
|
.then(expectAsync1((mirrorSystem) {
|
|
var testLibraryUri = new Uri(scheme: 'file',
|
|
path: path.absolute(fileName));
|
|
var library = generateLibrary(mirrorSystem.libraries[testLibraryUri]);
|
|
expect(library is Library, isTrue);
|
|
|
|
var classTypes = library.classes;
|
|
expect(classTypes is ClassGroup, isTrue);
|
|
|
|
var classes = [];
|
|
classes.addAll(classTypes.classes.values);
|
|
classes.addAll(classTypes.errors.values);
|
|
expect(classes.every((e) => e is Class), isTrue);
|
|
|
|
expect(classTypes.typedefs.values.every((e) => e is Typedef), isTrue);
|
|
|
|
var classMethodTypes = [];
|
|
classes.forEach((e) {
|
|
classMethodTypes.add(e.methods);
|
|
classMethodTypes.add(e.inheritedMethods);
|
|
});
|
|
expect(classMethodTypes.every((e) => e is MethodGroup), isTrue);
|
|
|
|
var classMethods = [];
|
|
classMethodTypes.forEach((e) {
|
|
classMethods.addAll(e.setters.values);
|
|
classMethods.addAll(e.getters.values);
|
|
classMethods.addAll(e.constructors.values);
|
|
classMethods.addAll(e.operators.values);
|
|
classMethods.addAll(e.regularMethods.values);
|
|
});
|
|
expect(classMethods.every((e) => e is Method), isTrue);
|
|
|
|
var methodParameters = [];
|
|
classMethods.forEach((e) {
|
|
methodParameters.addAll(e.parameters.values);
|
|
});
|
|
expect(methodParameters.every((e) => e is Parameter), isTrue);
|
|
|
|
var functionTypes = library.functions;
|
|
expect(functionTypes is MethodGroup, isTrue);
|
|
|
|
var functions = [];
|
|
functions.addAll(functionTypes.setters.values);
|
|
functions.addAll(functionTypes.getters.values);
|
|
functions.addAll(functionTypes.constructors.values);
|
|
functions.addAll(functionTypes.operators.values);
|
|
functions.addAll(functionTypes.regularMethods.values);
|
|
expect(functions.every((e) => e is Method), isTrue);
|
|
|
|
var functionParameters = [];
|
|
functions.forEach((e) {
|
|
functionParameters.addAll(e.parameters.values);
|
|
});
|
|
expect(functionParameters.every((e) => e is Parameter), isTrue);
|
|
|
|
var variables = library.variables.values;
|
|
expect(variables.every((e) => e is Variable), isTrue);
|
|
|
|
/// Testing fixReference
|
|
// Testing Doc comment for class [A].
|
|
var libraryMirror = mirrorSystem.libraries[testLibraryUri];
|
|
var classMirror = libraryMirror.classes.values.first;
|
|
var classDocComment = fixReference('A', libraryMirror,
|
|
classMirror, null).children.first.text;
|
|
expect(classDocComment == 'test.A', isTrue);
|
|
|
|
// Test for linking to parameter [A]
|
|
var methodMirror = classMirror.methods['doThis'];
|
|
var methodParameterDocComment = fixReference('A', libraryMirror,
|
|
classMirror, methodMirror).children.first.text;
|
|
// TODO(alanknight) : We're not supporting linking to parameters yet
|
|
// expect(methodParameterDocComment == 'test.A.doThis#A', isTrue);
|
|
|
|
// Testing trying to refer to doThis function
|
|
var methodDocComment = fixReference('doThis', libraryMirror,
|
|
classMirror, methodMirror).children.first.text;
|
|
expect(methodDocComment == 'test.A.doThis', isTrue);
|
|
|
|
// Testing something with no reference
|
|
var libraryDocComment = fixReference('foobar', libraryMirror,
|
|
classMirror, methodMirror).text;
|
|
expect(libraryDocComment == 'foobar', isTrue);
|
|
})).whenComplete(() => temporaryDir.deleteSync(recursive: true));
|
|
});
|
|
});
|
|
}
|