Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Side by Side Diff: tests/lib/mirrors/generic_function_typedef_test.dart

Issue 2771453003: Format all tests. (Closed)
Patch Set: Format files Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 4
5 library test.generic_function_typedef; 5 library test.generic_function_typedef;
6 6
7 @MirrorsUsed(targets: "test.generic_function_typedef") 7 @MirrorsUsed(targets: "test.generic_function_typedef")
8 import 'dart:mirrors'; 8 import 'dart:mirrors';
9 9
10 import 'package:expect/expect.dart'; 10 import 'package:expect/expect.dart';
11 11
12 import 'generics_helper.dart'; 12 import 'generics_helper.dart';
13 13
14 typedef bool NonGenericPredicate(num n); 14 typedef bool NonGenericPredicate(num n);
15 typedef bool GenericPredicate<T>(T t); 15 typedef bool GenericPredicate<T>(T t);
16 typedef S GenericTransform<S>(S s); 16 typedef S GenericTransform<S>(S s);
17 17
18 class C<R> { 18 class C<R> {
19 GenericPredicate<num> predicateOfNum; 19 GenericPredicate<num> predicateOfNum;
20 GenericTransform<String> transformOfString; 20 GenericTransform<String> transformOfString;
21 GenericTransform<R> transformOfR; 21 GenericTransform<R> transformOfR;
22 } 22 }
23 23
24 reflectTypeDeclaration(t) => reflectType(t).originalDeclaration; 24 reflectTypeDeclaration(t) => reflectType(t).originalDeclaration;
25 25
26 main() { 26 main() {
27 TypeMirror dynamicMirror = currentMirrorSystem().dynamicType; 27 TypeMirror dynamicMirror = currentMirrorSystem().dynamicType;
28 28
29 TypedefMirror predicateOfNum = (reflectClass(C).declarations[#predicateOfNum] as VariableMirror).type; 29 TypedefMirror predicateOfNum =
30 TypedefMirror transformOfString = (reflectClass(C).declarations[#transformOfSt ring] as VariableMirror).type; 30 (reflectClass(C).declarations[#predicateOfNum] as VariableMirror).type;
31 TypedefMirror transformOfR = (reflectClass(C).declarations[#transformOfR] as V ariableMirror).type; 31 TypedefMirror transformOfString =
32 TypedefMirror transformOfDouble = (reflect(new C<double>()).type.declarations[ #transformOfR] as VariableMirror).type; 32 (reflectClass(C).declarations[#transformOfString] as VariableMirror).type;
33 TypedefMirror transformOfR =
34 (reflectClass(C).declarations[#transformOfR] as VariableMirror).type;
35 TypedefMirror transformOfDouble = (reflect(new C<double>())
36 .type
37 .declarations[#transformOfR] as VariableMirror)
38 .type;
33 39
34 TypeVariableMirror tFromGenericPredicate = reflectTypeDeclaration(GenericPredi cate).typeVariables[0]; 40 TypeVariableMirror tFromGenericPredicate =
35 TypeVariableMirror sFromGenericTransform = reflectTypeDeclaration(GenericTrans form).typeVariables[0]; 41 reflectTypeDeclaration(GenericPredicate).typeVariables[0];
42 TypeVariableMirror sFromGenericTransform =
43 reflectTypeDeclaration(GenericTransform).typeVariables[0];
36 TypeVariableMirror rFromC = reflectClass(C).typeVariables[0]; 44 TypeVariableMirror rFromC = reflectClass(C).typeVariables[0];
37 45
38 // Typedefs. 46 // Typedefs.
39 typeParameters(reflectTypeDeclaration(NonGenericPredicate), []); 47 typeParameters(reflectTypeDeclaration(NonGenericPredicate), []);
40 typeParameters(reflectTypeDeclaration(GenericPredicate), [#T]); 48 typeParameters(reflectTypeDeclaration(GenericPredicate), [#T]);
41 typeParameters(reflectTypeDeclaration(GenericTransform), [#S]); 49 typeParameters(reflectTypeDeclaration(GenericTransform), [#S]);
42 typeParameters(predicateOfNum, [#T]); 50 typeParameters(predicateOfNum, [#T]);
43 typeParameters(transformOfString, [#S]); 51 typeParameters(transformOfString, [#S]);
44 typeParameters(transformOfR, [#S]); 52 typeParameters(transformOfR, [#S]);
45 typeParameters(transformOfDouble, [#S]); 53 typeParameters(transformOfDouble, [#S]);
46 54
47 typeArguments(reflectTypeDeclaration(NonGenericPredicate), []); 55 typeArguments(reflectTypeDeclaration(NonGenericPredicate), []);
48 typeArguments(reflectTypeDeclaration(GenericPredicate), []); 56 typeArguments(reflectTypeDeclaration(GenericPredicate), []);
49 typeArguments(reflectTypeDeclaration(GenericTransform), []); 57 typeArguments(reflectTypeDeclaration(GenericTransform), []);
50 typeArguments(predicateOfNum, [reflectClass(num)]); 58 typeArguments(predicateOfNum, [reflectClass(num)]);
51 typeArguments(transformOfString, [reflectClass(String)]); 59 typeArguments(transformOfString, [reflectClass(String)]);
52 typeArguments(transformOfR, [rFromC]); 60 typeArguments(transformOfR, [rFromC]);
53 typeArguments(transformOfDouble, [reflectClass(double)]); 61 typeArguments(transformOfDouble, [reflectClass(double)]);
54 62
55 Expect.isTrue(reflectTypeDeclaration(NonGenericPredicate).isOriginalDeclaratio n); 63 Expect.isTrue(
64 reflectTypeDeclaration(NonGenericPredicate).isOriginalDeclaration);
56 Expect.isTrue(reflectTypeDeclaration(GenericPredicate).isOriginalDeclaration); 65 Expect.isTrue(reflectTypeDeclaration(GenericPredicate).isOriginalDeclaration);
57 Expect.isTrue(reflectTypeDeclaration(GenericTransform).isOriginalDeclaration); 66 Expect.isTrue(reflectTypeDeclaration(GenericTransform).isOriginalDeclaration);
58 Expect.isFalse(predicateOfNum.isOriginalDeclaration); 67 Expect.isFalse(predicateOfNum.isOriginalDeclaration);
59 Expect.isFalse(transformOfString.isOriginalDeclaration); 68 Expect.isFalse(transformOfString.isOriginalDeclaration);
60 Expect.isFalse(transformOfR.isOriginalDeclaration); 69 Expect.isFalse(transformOfR.isOriginalDeclaration);
61 Expect.isFalse(transformOfDouble.isOriginalDeclaration); 70 Expect.isFalse(transformOfDouble.isOriginalDeclaration);
62 71
63 // Function types. 72 // Function types.
64 typeParameters(reflectTypeDeclaration(NonGenericPredicate).referent, []); 73 typeParameters(reflectTypeDeclaration(NonGenericPredicate).referent, []);
65 typeParameters(reflectTypeDeclaration(GenericPredicate).referent, []); 74 typeParameters(reflectTypeDeclaration(GenericPredicate).referent, []);
66 typeParameters(reflectTypeDeclaration(GenericTransform).referent, []); 75 typeParameters(reflectTypeDeclaration(GenericTransform).referent, []);
67 typeParameters(predicateOfNum.referent, []); 76 typeParameters(predicateOfNum.referent, []);
68 typeParameters(transformOfString.referent, []); 77 typeParameters(transformOfString.referent, []);
69 typeParameters(transformOfR.referent, []); 78 typeParameters(transformOfR.referent, []);
70 typeParameters(transformOfDouble.referent, []); 79 typeParameters(transformOfDouble.referent, []);
71 80
72 typeArguments(reflectTypeDeclaration(NonGenericPredicate).referent, []); 81 typeArguments(reflectTypeDeclaration(NonGenericPredicate).referent, []);
73 typeArguments(reflectTypeDeclaration(GenericPredicate).referent, []); 82 typeArguments(reflectTypeDeclaration(GenericPredicate).referent, []);
74 typeArguments(reflectTypeDeclaration(GenericTransform).referent, []); 83 typeArguments(reflectTypeDeclaration(GenericTransform).referent, []);
75 typeArguments(predicateOfNum.referent, []); 84 typeArguments(predicateOfNum.referent, []);
76 typeArguments(transformOfString.referent, []); 85 typeArguments(transformOfString.referent, []);
77 typeArguments(transformOfR.referent, []); 86 typeArguments(transformOfR.referent, []);
78 typeArguments(transformOfDouble.referent, []); 87 typeArguments(transformOfDouble.referent, []);
79 88
80 // Function types are always non-generic. Only the typedef is generic. 89 // Function types are always non-generic. Only the typedef is generic.
81 Expect.isTrue(reflectTypeDeclaration(NonGenericPredicate).referent.isOriginalD eclaration); 90 Expect.isTrue(reflectTypeDeclaration(NonGenericPredicate)
82 Expect.isTrue(reflectTypeDeclaration(GenericPredicate).referent.isOriginalDecl aration); 91 .referent
83 Expect.isTrue(reflectTypeDeclaration(GenericTransform).referent.isOriginalDecl aration); 92 .isOriginalDeclaration);
84 Expect.isTrue(predicateOfNum.referent.isOriginalDeclaration); 93 Expect.isTrue(
85 Expect.isTrue(transformOfString.referent.isOriginalDeclaration); 94 reflectTypeDeclaration(GenericPredicate).referent.isOriginalDeclaration);
95 Expect.isTrue(
96 reflectTypeDeclaration(GenericTransform).referent.isOriginalDeclaration);
97 Expect.isTrue(predicateOfNum.referent.isOriginalDeclaration);
98 Expect.isTrue(transformOfString.referent.isOriginalDeclaration);
86 Expect.isTrue(transformOfR.referent.isOriginalDeclaration); 99 Expect.isTrue(transformOfR.referent.isOriginalDeclaration);
87 Expect.isTrue(transformOfDouble.referent.isOriginalDeclaration); 100 Expect.isTrue(transformOfDouble.referent.isOriginalDeclaration);
88 101
89 Expect.equals(reflectClass(num), 102 Expect.equals(reflectClass(num),
90 reflectTypeDeclaration(NonGenericPredicate).referent.parameters[ 0].type); 103 reflectTypeDeclaration(NonGenericPredicate).referent.parameters[0].type);
91 Expect.equals(tFromGenericPredicate, 104 Expect.equals(tFromGenericPredicate,
92 reflectTypeDeclaration(GenericPredicate).referent.parameters[0]. type); 105 reflectTypeDeclaration(GenericPredicate).referent.parameters[0].type);
93 Expect.equals(sFromGenericTransform, 106 Expect.equals(sFromGenericTransform,
94 reflectTypeDeclaration(GenericTransform).referent.parameters[0]. type); 107 reflectTypeDeclaration(GenericTransform).referent.parameters[0].type);
95 108
96 Expect.equals(reflectClass(num), 109 Expect.equals(reflectClass(num), predicateOfNum.referent.parameters[0].type);
97 predicateOfNum.referent.parameters[0].type); 110 Expect.equals(
98 Expect.equals(reflectClass(String), 111 reflectClass(String), transformOfString.referent.parameters[0].type);
99 transformOfString.referent.parameters[0].type); 112 Expect.equals(rFromC, transformOfR.referent.parameters[0].type);
100 Expect.equals(rFromC, 113 Expect.equals(
101 transformOfR.referent.parameters[0].type); 114 reflectClass(double), transformOfDouble.referent.parameters[0].type);
102 Expect.equals(reflectClass(double),
103 transformOfDouble.referent.parameters[0].type);
104 115
105 Expect.equals(reflectClass(bool), 116 Expect.equals(reflectClass(bool),
106 reflectTypeDeclaration(NonGenericPredicate).referent.returnType) ; 117 reflectTypeDeclaration(NonGenericPredicate).referent.returnType);
107 Expect.equals(reflectClass(bool), 118 Expect.equals(reflectClass(bool),
108 reflectTypeDeclaration(GenericPredicate).referent.returnType); 119 reflectTypeDeclaration(GenericPredicate).referent.returnType);
109 Expect.equals(sFromGenericTransform, 120 Expect.equals(sFromGenericTransform,
110 reflectTypeDeclaration(GenericTransform).referent.returnType); 121 reflectTypeDeclaration(GenericTransform).referent.returnType);
111 Expect.equals(reflectClass(bool), 122 Expect.equals(reflectClass(bool), predicateOfNum.referent.returnType);
112 predicateOfNum.referent.returnType); 123 Expect.equals(reflectClass(String), transformOfString.referent.returnType);
113 Expect.equals(reflectClass(String), 124 Expect.equals(rFromC, transformOfR.referent.returnType);
114 transformOfString.referent.returnType); 125 Expect.equals(reflectClass(double), transformOfDouble.referent.returnType);
115 Expect.equals(rFromC,
116 transformOfR.referent.returnType);
117 Expect.equals(reflectClass(double),
118 transformOfDouble.referent.returnType);
119 } 126 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698