Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library test.method_location; | |
| 6 | |
| 7 import "dart:mirrors"; | |
| 8 import "package:expect/expect.dart"; | |
| 9 | |
| 10 part 'method_mirror_location_other.dart'; | |
| 11 | |
| 12 // We only check for a suffix of the uri because the test might be run from | |
| 13 // any number of absolute paths. | |
| 14 expectLocation(Mirror mirror, String uriSuffix, int line, int column) { | |
| 15 MethodMirror methodMirror; | |
| 16 if (mirror is ClosureMirror) { | |
| 17 methodMirror = mirror.function; | |
| 18 } else { | |
| 19 methodMirror = mirror as MethodMirror; | |
| 20 } | |
| 21 Expect.isTrue(methodMirror is MethodMirror); | |
| 22 Uri uri = methodMirror.location.sourceUri; | |
| 23 Expect.isTrue(uri.toString().endsWith(uriSuffix), | |
| 24 "Expected suffix $uriSuffix in $uri"); | |
| 25 Expect.equals(line, methodMirror.location.line, "line"); | |
| 26 Expect.equals(column, methodMirror.location.column, "column"); | |
| 27 } | |
| 28 | |
| 29 class ClassInMainFile { | |
| 30 | |
| 31 ClassInMainFile(); | |
| 32 | |
| 33 method() {} | |
| 34 } | |
| 35 | |
| 36 topLevelInMainFile() {} | |
| 37 spaceIntentedInMainFile() {} | |
|
gbracha
2014/03/25 21:08:35
Again, spaceIntented should be spaceIndented
| |
| 38 tabIntentedInMainFile() {} | |
|
gbracha
2014/03/25 21:08:35
and here too.
| |
| 39 | |
| 40 class HasImplicitConstructor {} | |
| 41 | |
| 42 typedef bool Predicate(num n); | |
| 43 | |
| 44 main() { | |
| 45 localFunction(x) { return x; } | |
| 46 | |
| 47 String mainSuffix = 'method_mirror_location_test.dart'; | |
| 48 String otherSuffix = 'method_mirror_location_other.dart'; | |
| 49 | |
| 50 // This file. | |
| 51 expectLocation(reflectType(ClassInMainFile).declarations[#ClassInMainFile], | |
| 52 mainSuffix, 31, 3); | |
| 53 expectLocation(reflectType(ClassInMainFile).declarations[#method], | |
| 54 mainSuffix, 33, 3); | |
| 55 expectLocation(reflect(topLevelInMainFile), mainSuffix, 36, 1); | |
| 56 expectLocation(reflect(spaceIntentedInMainFile), mainSuffix, 37, 3); | |
| 57 expectLocation(reflect(tabIntentedInMainFile), mainSuffix, 38, 2); | |
| 58 expectLocation(reflect(localFunction), mainSuffix, 45, 3); | |
| 59 | |
| 60 // Another part. | |
| 61 expectLocation(reflectType(ClassInOtherFile).declarations[#ClassInOtherFile], | |
| 62 otherSuffix, 9, 3); | |
| 63 expectLocation(reflectType(ClassInOtherFile).declarations[#method], | |
| 64 otherSuffix, 11, 3); | |
| 65 expectLocation(reflect(topLevelInOtherFile), otherSuffix, 14, 1); | |
| 66 expectLocation(reflect(spaceIntentedInOtherFile), otherSuffix, 16, 3); | |
| 67 expectLocation(reflect(tabIntentedInOtherFile), otherSuffix, 18, 2); | |
| 68 | |
| 69 // Synthetic methods. | |
| 70 Expect.isNull(reflectType(HasImplicitConstructor) | |
| 71 .declarations[#HasImplicitConstructor].location); | |
| 72 Expect.isNull(reflectType(Predicate).referent.callMethod.location); | |
| 73 } | |
| OLD | NEW |