OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 library test.class_location; | 4 library test.class_location; |
5 | 5 |
6 @MirrorsUsed(targets: "test.class_location") | 6 @MirrorsUsed(targets: "test.class_location") |
7 import "dart:mirrors"; | 7 import "dart:mirrors"; |
8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
9 | 9 |
10 part 'class_mirror_location_other.dart'; | 10 part 'class_mirror_location_other.dart'; |
(...skipping 15 matching lines...) Expand all Loading... |
26 @metadata | 26 @metadata |
27 class WithMetadata {} | 27 class WithMetadata {} |
28 | 28 |
29 enum Enum { RED, GREEN, BLUE } | 29 enum Enum { RED, GREEN, BLUE } |
30 | 30 |
31 @metadata | 31 @metadata |
32 enum AnnotatedEnum { SALT, PEPPER } | 32 enum AnnotatedEnum { SALT, PEPPER } |
33 | 33 |
34 // We only check for a suffix of the uri because the test might be run from | 34 // We only check for a suffix of the uri because the test might be run from |
35 // any number of absolute paths. | 35 // any number of absolute paths. |
36 expectLocation(DeclarationMirror mirror, String uriSuffix, int line, int column)
{ | 36 expectLocation( |
| 37 DeclarationMirror mirror, String uriSuffix, int line, int column) { |
37 Uri uri = mirror.location.sourceUri; | 38 Uri uri = mirror.location.sourceUri; |
38 Expect.isTrue(uri.toString().endsWith(uriSuffix), | 39 Expect.isTrue( |
39 » "Expected suffix $uriSuffix in $uri"); | 40 uri.toString().endsWith(uriSuffix), "Expected suffix $uriSuffix in $uri"); |
40 Expect.equals(line, mirror.location.line, "line"); | 41 Expect.equals(line, mirror.location.line, "line"); |
41 Expect.equals(column, mirror.location.column, "column"); | 42 Expect.equals(column, mirror.location.column, "column"); |
42 } | 43 } |
43 | 44 |
44 main() { | 45 main() { |
45 String mainSuffix = 'class_mirror_location_test.dart'; | 46 String mainSuffix = 'class_mirror_location_test.dart'; |
46 String otherSuffix = 'class_mirror_location_other.dart'; | 47 String otherSuffix = 'class_mirror_location_other.dart'; |
47 | 48 |
48 // This file. | 49 // This file. |
49 expectLocation(reflectClass(ClassInMainFile), mainSuffix, 12, 1); | 50 expectLocation(reflectClass(ClassInMainFile), mainSuffix, 12, 1); |
50 expectLocation(reflectClass(SpaceIndentedInMainFile), mainSuffix, 13, 3); | 51 expectLocation(reflectClass(SpaceIndentedInMainFile), mainSuffix, 13, 3); |
51 expectLocation(reflectClass(TabIndentedInMainFile), mainSuffix, 14, 2); | 52 expectLocation(reflectClass(TabIndentedInMainFile), mainSuffix, 14, 2); |
52 expectLocation(reflectClass(AbstractClass), mainSuffix, 16, 1); | 53 expectLocation(reflectClass(AbstractClass), mainSuffix, 16, 1); |
53 expectLocation(reflectType(Predicate), mainSuffix, 17, 1); | 54 expectLocation(reflectType(Predicate), mainSuffix, 17, 1); |
54 expectLocation(reflectClass(MA), mainSuffix, 21, 1); | 55 expectLocation(reflectClass(MA), mainSuffix, 21, 1); |
55 expectLocation(reflectClass(MA2), mainSuffix, 22, 1); | 56 expectLocation(reflectClass(MA2), mainSuffix, 22, 1); |
56 expectLocation(reflectClass(WithMetadata), mainSuffix, 26, 1); | 57 expectLocation(reflectClass(WithMetadata), mainSuffix, 26, 1); |
57 expectLocation(reflectClass(Enum), mainSuffix, 29, 1); | 58 expectLocation(reflectClass(Enum), mainSuffix, 29, 1); |
58 expectLocation(reflectClass(AnnotatedEnum), mainSuffix, 31, 1); | 59 expectLocation(reflectClass(AnnotatedEnum), mainSuffix, 31, 1); |
59 | 60 |
60 // Another part. | 61 // Another part. |
61 expectLocation(reflectClass(ClassInOtherFile), otherSuffix, 7, 1); | 62 expectLocation(reflectClass(ClassInOtherFile), otherSuffix, 7, 1); |
62 expectLocation(reflectClass(SpaceIndentedInOtherFile), otherSuffix, 9, 3); | 63 expectLocation(reflectClass(SpaceIndentedInOtherFile), otherSuffix, 9, 3); |
63 expectLocation(reflectClass(TabIndentedInOtherFile), otherSuffix, 11, 2); | 64 expectLocation(reflectClass(TabIndentedInOtherFile), otherSuffix, 11, 2); |
64 | 65 |
65 // Synthetic classes. | 66 // Synthetic classes. |
66 Expect.isNull(reflectClass(MA).superclass.location); | 67 Expect.isNull(reflectClass(MA).superclass.location); |
67 Expect.isNull((reflect(main) as ClosureMirror).type.location); | 68 Expect.isNull((reflect(main) as ClosureMirror).type.location); |
68 } | 69 } |
OLD | NEW |