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.class_location; | |
6 | |
7 import "dart:mirrors"; | |
8 import "package:expect/expect.dart"; | |
9 | |
10 part 'class_mirror_location_other.dart'; | |
11 | |
12 class ClassInMainFile {} | |
13 class SpaceIndentedInMainFile {} | |
14 class TabIndentedInMainFile {} | |
15 | |
16 abstract class AbstractClass {} | |
17 typedef bool Predicate(num n); | |
18 | |
19 class M {} | |
20 class S {} | |
21 class MA extends S with M {} | |
22 class MA2 = S with M; | |
23 | |
24 const metadata = 'metadata'; | |
25 | |
26 @metadata | |
27 class WithMetadata {} | |
28 | |
29 // We only check for a suffix of the uri because the test might be run from | |
30 // any number of absolute paths. | |
31 expectLocation(DeclarationMirror mirror, String uriSuffix, int line, int column) { | |
32 Uri uri = mirror.location.sourceUri; | |
33 Expect.isTrue(uri.toString().endsWith(uriSuffix), | |
34 "Expected suffix $uriSuffix in $uri"); | |
35 Expect.equals(line, mirror.location.line, "line"); | |
36 Expect.equals(column, mirror.location.column, "column"); | |
37 } | |
38 | |
39 main() { | |
40 String mainSuffix = 'class_mirror_location_test.dart'; | |
41 String otherSuffix = 'class_mirror_location_other.dart'; | |
42 | |
43 // This file. | |
44 expectLocation(reflectClass(ClassInMainFile), mainSuffix, 12, 1); | |
45 expectLocation(reflectClass(SpaceIndentedInMainFile), mainSuffix, 13, 3); | |
46 expectLocation(reflectClass(TabIndentedInMainFile), mainSuffix, 14, 2); | |
47 expectLocation(reflectClass(AbstractClass), mainSuffix, 16, 1); | |
48 expectLocation(reflectType(Predicate), mainSuffix, 17, 1); | |
49 expectLocation(reflectClass(MA), mainSuffix, 21, 1); | |
50 expectLocation(reflectClass(MA2), mainSuffix, 22, 1); | |
51 expectLocation(reflectClass(WithMetadata), mainSuffix, 26, 1); | |
52 | |
53 // Another part. | |
54 expectLocation(reflectClass(ClassInOtherFile), otherSuffix, 7, 1); | |
55 expectLocation(reflectClass(SpaceIdentedInOtherFile), otherSuffix, 9, 3); | |
gbracha
2015/02/13 03:00:57
Idented -> Indented
| |
56 expectLocation(reflectClass(TabIdentedInOtherFile), otherSuffix, 11, 2); | |
gbracha
2015/02/13 03:00:57
Ditto.
| |
57 | |
58 // Synthetic classes. | |
59 Expect.isNull(reflectClass(MA).superclass.location); | |
60 Expect.isNull((reflect(main) as ClosureMirror).type.location); | |
61 } | |
OLD | NEW |