2dcd56ef43
There are far too many files here to review everyone carefully. Spot checking most of the diffs look good as test code is generally written with less care than application code so lots of ugly formatting get through. If people notice files where the automated formatting bothers them feel free to comment indicating file names and I'll move spaces within comments to make the formatting cleaner and use comments to force block formatting as I have done for other case where formatting looked bad. BUG= R=efortuna@google.com Review-Url: https://codereview.chromium.org/2771453003 .
74 lines
2.5 KiB
Dart
74 lines
2.5 KiB
Dart
// 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.method_location;
|
|
|
|
import "dart:mirrors";
|
|
import "package:expect/expect.dart";
|
|
|
|
part 'method_mirror_location_other.dart';
|
|
|
|
// We only check for a suffix of the uri because the test might be run from
|
|
// any number of absolute paths.
|
|
expectLocation(Mirror mirror, String uriSuffix, int line, int column) {
|
|
MethodMirror methodMirror;
|
|
if (mirror is ClosureMirror) {
|
|
methodMirror = mirror.function;
|
|
} else {
|
|
methodMirror = mirror as MethodMirror;
|
|
}
|
|
Expect.isTrue(methodMirror is MethodMirror);
|
|
Uri uri = methodMirror.location.sourceUri;
|
|
Expect.isTrue(uri.toString().endsWith(uriSuffix),
|
|
"Expected suffix $uriSuffix in $uri");
|
|
Expect.equals(line, methodMirror.location.line, "line");
|
|
Expect.equals(column, methodMirror.location.column, "column");
|
|
}
|
|
|
|
class ClassInMainFile {
|
|
|
|
ClassInMainFile();
|
|
|
|
method() {}
|
|
}
|
|
|
|
void topLevelInMainFile() {}
|
|
spaceIdentedInMainFile() {}
|
|
tabIdentedInMainFile() {}
|
|
|
|
class HasImplicitConstructor {}
|
|
|
|
typedef bool Predicate(num n);
|
|
|
|
main() {
|
|
localFunction(x) { return x; }
|
|
|
|
String mainSuffix = 'method_mirror_location_test.dart';
|
|
String otherSuffix = 'method_mirror_location_other.dart';
|
|
|
|
// This file.
|
|
expectLocation(reflectClass(ClassInMainFile).declarations[#ClassInMainFile],
|
|
mainSuffix, 31, 3);
|
|
expectLocation(reflectClass(ClassInMainFile).declarations[#method],
|
|
mainSuffix, 33, 3);
|
|
expectLocation(reflect(topLevelInMainFile), mainSuffix, 36, 1);
|
|
expectLocation(reflect(spaceIdentedInMainFile), mainSuffix, 37, 3);
|
|
expectLocation(reflect(tabIdentedInMainFile), mainSuffix, 38, 2);
|
|
expectLocation(reflect(localFunction), mainSuffix, 45, 3);
|
|
|
|
// Another part.
|
|
expectLocation(reflectClass(ClassInOtherFile).declarations[#ClassInOtherFile],
|
|
otherSuffix, 8, 3);
|
|
expectLocation(reflectClass(ClassInOtherFile).declarations[#method],
|
|
otherSuffix, 10, 3);
|
|
expectLocation(reflect(topLevelInOtherFile), otherSuffix, 13, 1);
|
|
expectLocation(reflect(spaceIdentedInOtherFile), otherSuffix, 15, 3);
|
|
expectLocation(reflect(tabIdentedInOtherFile), otherSuffix, 17, 2);
|
|
|
|
// Synthetic methods.
|
|
Expect.isNull(reflectClass(HasImplicitConstructor)
|
|
.declarations[#HasImplicitConstructor].location);
|
|
Expect.isNull((reflectType(Predicate) as TypedefMirror).referent.callMethod.location);
|
|
}
|