OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 /// Test operators. |
| 6 library test.operator_test; |
| 7 |
| 8 import 'dart:mirrors'; |
| 9 |
| 10 import 'package:expect/expect.dart'; |
| 11 |
| 12 import 'stringify.dart'; |
| 13 |
| 14 class Foo { |
| 15 Foo operator ~() {} |
| 16 Foo operator -() {} |
| 17 |
| 18 bool operator ==(a) {} |
| 19 Foo operator [](int a) {} |
| 20 Foo operator *(Foo a) {} |
| 21 Foo operator /(Foo a) {} |
| 22 Foo operator %(Foo a) {} |
| 23 Foo operator ~/(Foo a) {} |
| 24 Foo operator +(Foo a) {} |
| 25 Foo operator <<(Foo a) {} |
| 26 Foo operator >>(Foo a) {} |
| 27 Foo operator >=(Foo a) {} |
| 28 Foo operator >(Foo a) {} |
| 29 Foo operator <=(Foo a) {} |
| 30 Foo operator <(Foo a) {} |
| 31 Foo operator &(Foo a) {} |
| 32 Foo operator ^(Foo a) {} |
| 33 Foo operator |(Foo a) {} |
| 34 Foo operator -(Foo a) {} |
| 35 |
| 36 // TODO(ahe): use void when dart2js reifies that type. |
| 37 operator []=(int a, Foo b) {} |
| 38 } |
| 39 |
| 40 void main() { |
| 41 ClassMirror cls = reflectClass(Foo); |
| 42 var operators = new Map<Symbol, MethodMirror>(); |
| 43 var operatorParameters = new Map<Symbol, List>(); |
| 44 var returnTypes = new Map<Symbol, Mirror>(); |
| 45 for (MethodMirror method in cls.declarations.values.where( |
| 46 (d) => d is MethodMirror && !d.isConstructor)) { |
| 47 Expect.isTrue(method.isRegularMethod); |
| 48 Expect.isTrue(method.isOperator); |
| 49 Expect.isFalse(method.isGetter); |
| 50 Expect.isFalse(method.isSetter); |
| 51 Expect.isFalse(method.isAbstract); |
| 52 operators[method.simpleName] = method; |
| 53 operatorParameters[method.simpleName] = method.parameters; |
| 54 returnTypes[method.simpleName] = method.returnType; |
| 55 } |
| 56 expect(OPERATORS, operators); |
| 57 expect(PARAMETERS, operatorParameters); |
| 58 expect(RETURN_TYPES, returnTypes); |
| 59 } |
| 60 |
| 61 const String OPERATORS = '{' |
| 62 '%: Method(s(%) in s(Foo)), ' |
| 63 '&: Method(s(&) in s(Foo)), ' |
| 64 '*: Method(s(*) in s(Foo)), ' |
| 65 '+: Method(s(+) in s(Foo)), ' |
| 66 '-: Method(s(-) in s(Foo)), ' |
| 67 '/: Method(s(/) in s(Foo)), ' |
| 68 '<: Method(s(<) in s(Foo)), ' |
| 69 '<<: Method(s(<<) in s(Foo)), ' |
| 70 '<=: Method(s(<=) in s(Foo)), ' |
| 71 '==: Method(s(==) in s(Foo)), ' |
| 72 '>: Method(s(>) in s(Foo)), ' |
| 73 '>=: Method(s(>=) in s(Foo)), ' |
| 74 '>>: Method(s(>>) in s(Foo)), ' |
| 75 '[]: Method(s([]) in s(Foo)), ' |
| 76 '[]=: Method(s([]=) in s(Foo)), ' |
| 77 '^: Method(s(^) in s(Foo)), ' |
| 78 'unary-: Method(s(unary-) in s(Foo)), ' |
| 79 '|: Method(s(|) in s(Foo)), ' |
| 80 '~: Method(s(~) in s(Foo)), ' |
| 81 '~/: Method(s(~/) in s(Foo))' |
| 82 '}'; |
| 83 |
| 84 const String DYNAMIC = 'Type(s(dynamic), top-level)'; |
| 85 |
| 86 const String FOO = 'Class(s(Foo) in s(test.operator_test), top-level)'; |
| 87 |
| 88 const String INT = 'Class(s(int) in s(dart.core), top-level)'; |
| 89 |
| 90 const String BOOL = 'Class(s(bool) in s(dart.core), top-level)'; |
| 91 |
| 92 const String PARAMETERS = '{' |
| 93 '%: [Parameter(s(a) in s(%), type = $FOO)], ' |
| 94 '&: [Parameter(s(a) in s(&), type = $FOO)], ' |
| 95 '*: [Parameter(s(a) in s(*), type = $FOO)], ' |
| 96 '+: [Parameter(s(a) in s(+), type = $FOO)], ' |
| 97 '-: [Parameter(s(a) in s(-), type = $FOO)], ' |
| 98 '/: [Parameter(s(a) in s(/), type = $FOO)], ' |
| 99 '<: [Parameter(s(a) in s(<), type = $FOO)], ' |
| 100 '<<: [Parameter(s(a) in s(<<), type = $FOO)], ' |
| 101 '<=: [Parameter(s(a) in s(<=), type = $FOO)], ' |
| 102 '==: [Parameter(s(a) in s(==), type = $DYNAMIC)], ' |
| 103 '>: [Parameter(s(a) in s(>), type = $FOO)], ' |
| 104 '>=: [Parameter(s(a) in s(>=), type = $FOO)], ' |
| 105 '>>: [Parameter(s(a) in s(>>), type = $FOO)], ' |
| 106 '[]: [Parameter(s(a) in s([]), type = $INT)], ' |
| 107 '[]=: [Parameter(s(a) in s([]=), type = $INT), ' |
| 108 'Parameter(s(b) in s([]=), type = $FOO)], ' |
| 109 '^: [Parameter(s(a) in s(^), type = $FOO)], ' |
| 110 'unary-: [], ' |
| 111 '|: [Parameter(s(a) in s(|), type = $FOO)], ' |
| 112 '~: [], ' |
| 113 '~/: [Parameter(s(a) in s(~/), type = $FOO)]' |
| 114 '}'; |
| 115 |
| 116 const String RETURN_TYPES = '{' |
| 117 '%: $FOO, ' |
| 118 '&: $FOO, ' |
| 119 '*: $FOO, ' |
| 120 '+: $FOO, ' |
| 121 '-: $FOO, ' |
| 122 '/: $FOO, ' |
| 123 '<: $FOO, ' |
| 124 '<<: $FOO, ' |
| 125 '<=: $FOO, ' |
| 126 '==: $BOOL, ' |
| 127 '>: $FOO, ' |
| 128 '>=: $FOO, ' |
| 129 '>>: $FOO, ' |
| 130 '[]: $FOO, ' |
| 131 '[]=: $DYNAMIC, ' |
| 132 '^: $FOO, ' |
| 133 'unary-: $FOO, ' |
| 134 '|: $FOO, ' |
| 135 '~: $FOO, ' |
| 136 '~/: $FOO' |
| 137 '}'; |
OLD | NEW |