OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, 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.declarations_location; |
| 6 |
| 7 import "dart:mirrors"; |
| 8 import "package:expect/expect.dart"; |
| 9 import "library_without_declaration.dart"; |
| 10 import "library_with_annotated_declaration.dart"; |
| 11 |
| 12 const metadata = 'metadata'; |
| 13 |
| 14 class C<S, @metadata T> { |
| 15 var a; |
| 16 final b = 2; |
| 17 static var c; |
| 18 static final d = 4; |
| 19 @metadata var e; |
| 20 List<C> f; |
| 21 } |
| 22 |
| 23 |
| 24 // We only check for a suffix of the uri because the test might be run from |
| 25 // any number of absolute paths. |
| 26 expectLocation(DeclarationMirror mirror, String uriSuffix, int line, int column)
{ |
| 27 Uri uri = mirror.location.sourceUri; |
| 28 Expect.isTrue(uri.toString().endsWith(uriSuffix), |
| 29 "Expected suffix $uriSuffix in $uri"); |
| 30 Expect.equals(line, mirror.location.line, "line"); |
| 31 Expect.equals(column, mirror.location.column, "column"); |
| 32 } |
| 33 |
| 34 main() { |
| 35 String mainSuffix = 'other_declarations_location_test.dart'; |
| 36 |
| 37 // Fields. |
| 38 expectLocation(reflectClass(C).declarations[#a], mainSuffix, 15, 7); |
| 39 expectLocation(reflectClass(C).declarations[#b], mainSuffix, 16, 9); |
| 40 expectLocation(reflectClass(C).declarations[#c], mainSuffix, 17, 14); |
| 41 expectLocation(reflectClass(C).declarations[#d], mainSuffix, 18, 16); |
| 42 expectLocation(reflectClass(C).declarations[#e], mainSuffix, 19, 17); |
| 43 expectLocation(reflectClass(C).declarations[#f], mainSuffix, 20, 11); |
| 44 |
| 45 // Type variables. |
| 46 expectLocation(reflectClass(C).declarations[#S], mainSuffix, 14, 9); |
| 47 expectLocation(reflectClass(C).declarations[#T], mainSuffix, 14, 12); |
| 48 |
| 49 // Libraries. |
| 50 expectLocation(reflectClass(C).owner, mainSuffix, 5, 1); |
| 51 expectLocation(reflectClass(ClassInLibraryWithoutDeclaration).owner, |
| 52 "library_without_declaration.dart", 1, 1); |
| 53 expectLocation(reflectClass(ClassInLibraryWithAnnotatedDeclaration).owner, |
| 54 "library_with_annotated_declaration.dart", 5, 1); |
| 55 } |
OLD | NEW |