| OLD | NEW |
| 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.invoke_call_through_getter; | 5 library test.invoke_call_through_getter; |
| 6 | 6 |
| 7 import 'dart:mirrors'; | 7 import 'dart:mirrors'; |
| 8 | 8 |
| 9 import 'package:expect/expect.dart'; | 9 import 'package:expect/expect.dart'; |
| 10 | 10 |
| 11 class FakeFunctionCall { | 11 class FakeFunctionCall { |
| 12 call(x, y) => '1 $x $y'; | 12 call(x, y) => '1 $x $y'; |
| 13 } | 13 } |
| 14 | |
| 15 class FakeFunctionNSM { | 14 class FakeFunctionNSM { |
| 16 noSuchMethod(msg) => msg.positionalArguments.join(', '); | 15 noSuchMethod(msg) => msg.positionalArguments.join(', '); |
| 17 } | 16 } |
| 18 | 17 |
| 19 class C { | 18 class C { |
| 20 get fakeFunctionCall => new FakeFunctionCall(); | 19 get fakeFunctionCall => new FakeFunctionCall(); |
| 21 get fakeFunctionNSM => new FakeFunctionNSM(); | 20 get fakeFunctionNSM => new FakeFunctionNSM(); |
| 22 get closure => (x, y) => '2 $this $x $y'; | 21 get closure => (x, y) => '2 $this $x $y'; |
| 23 get closureOpt => (x, y, [z, w]) => '3 $this $x $y $z $w'; | 22 get closureOpt => (x, y, [z, w]) => '3 $this $x $y $z $w'; |
| 24 get closureNamed => (x, y, {z, w}) => '4 $this $x $y $z $w'; | 23 get closureNamed => (x, y, {z, w}) => '4 $this $x $y $z $w'; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 37 Expect.equals('3 C 11 12 13 null', c.closureOpt(11, 12, 13)); | 36 Expect.equals('3 C 11 12 13 null', c.closureOpt(11, 12, 13)); |
| 38 Expect.equals('4 C 14 15 null 16', c.closureNamed(14, 15, w: 16)); | 37 Expect.equals('4 C 14 15 null 16', c.closureNamed(14, 15, w: 16)); |
| 39 Expect.equals('DNU', c.doesNotExist(17, 18)); | 38 Expect.equals('DNU', c.doesNotExist(17, 18)); |
| 40 Expect.throws(() => c.closure('wrong arity'), (e) => e is NoSuchMethodError); | 39 Expect.throws(() => c.closure('wrong arity'), (e) => e is NoSuchMethodError); |
| 41 Expect.throws(() => c.notAClosure(), (e) => e is NoSuchMethodError); | 40 Expect.throws(() => c.notAClosure(), (e) => e is NoSuchMethodError); |
| 42 } | 41 } |
| 43 | 42 |
| 44 testInstanceReflective() { | 43 testInstanceReflective() { |
| 45 InstanceMirror im = reflect(new C()); | 44 InstanceMirror im = reflect(new C()); |
| 46 | 45 |
| 47 Expect.equals('1 5 6', im.invoke(#fakeFunctionCall, [5, 6]).reflectee); | 46 Expect.equals('1 5 6', |
| 48 Expect.equals('7, 8', im.invoke(#fakeFunctionNSM, [7, 8]).reflectee); | 47 im.invoke(#fakeFunctionCall, [5, 6]).reflectee); |
| 49 Expect.equals('2 C 9 10', im.invoke(#closure, [9, 10]).reflectee); | 48 Expect.equals('7, 8', |
| 50 Expect.equals( | 49 im.invoke(#fakeFunctionNSM, [7, 8]).reflectee); |
| 51 '3 C 11 12 13 null', im.invoke(#closureOpt, [11, 12, 13]).reflectee); | 50 Expect.equals('2 C 9 10', |
| 51 im.invoke(#closure, [9, 10]).reflectee); |
| 52 Expect.equals('3 C 11 12 13 null', |
| 53 im.invoke(#closureOpt, [11, 12, 13]).reflectee); |
| 52 Expect.equals('4 C 14 15 null 16', // //
# named: ok | 54 Expect.equals('4 C 14 15 null 16', // //
# named: ok |
| 53 im.invoke(#closureNamed, [14, 15], {#w: 16}).reflectee); // //
# named: continued | 55 im.invoke(#closureNamed, [14, 15], {#w: 16}).reflectee); // //
# named: continued |
| 54 Expect.equals('DNU', im.invoke(#doesNotExist, [17, 18]).reflectee); | 56 Expect.equals('DNU', |
| 57 im.invoke(#doesNotExist, [17, 18]).reflectee); |
| 55 Expect.throws(() => im.invoke(#closure, ['wrong arity']), | 58 Expect.throws(() => im.invoke(#closure, ['wrong arity']), |
| 56 (e) => e is NoSuchMethodError); | 59 (e) => e is NoSuchMethodError); |
| 57 Expect.throws( | 60 Expect.throws(() => im.invoke(#notAClosure, []), |
| 58 () => im.invoke(#notAClosure, []), (e) => e is NoSuchMethodError); | 61 (e) => e is NoSuchMethodError); |
| 59 } | 62 } |
| 60 | 63 |
| 61 class D { | 64 class D { |
| 62 static get fakeFunctionCall => new FakeFunctionCall(); | 65 static get fakeFunctionCall => new FakeFunctionCall(); |
| 63 static get fakeFunctionNSM => new FakeFunctionNSM(); | 66 static get fakeFunctionNSM => new FakeFunctionNSM(); |
| 64 static get closure => (x, y) => '2 $x $y'; | 67 static get closure => (x, y) => '2 $x $y'; |
| 65 static get closureOpt => (x, y, [z, w]) => '3 $x $y $z $w'; | 68 static get closureOpt => (x, y, [z, w]) => '3 $x $y $z $w'; |
| 66 static get closureNamed => (x, y, {z, w}) => '4 $x $y $z $w'; | 69 static get closureNamed => (x, y, {z, w}) => '4 $x $y $z $w'; |
| 67 static get notAClosure => 'Not a closure'; | 70 static get notAClosure => 'Not a closure'; |
| 68 } | 71 } |
| 69 | 72 |
| 70 testClassBase() { | 73 testClassBase() { |
| 71 Expect.equals('1 5 6', D.fakeFunctionCall(5, 6)); | 74 Expect.equals('1 5 6', D.fakeFunctionCall(5, 6)); |
| 72 Expect.equals('7, 8', D.fakeFunctionNSM(7, 8)); | 75 Expect.equals('7, 8', D.fakeFunctionNSM(7, 8)); |
| 73 Expect.equals('2 9 10', D.closure(9, 10)); | 76 Expect.equals('2 9 10', D.closure(9, 10)); |
| 74 Expect.equals('3 11 12 13 null', D.closureOpt(11, 12, 13)); | 77 Expect.equals('3 11 12 13 null', D.closureOpt(11, 12, 13)); |
| 75 Expect.equals('4 14 15 null 16', D.closureNamed(14, 15, w: 16)); | 78 Expect.equals('4 14 15 null 16', D.closureNamed(14, 15, w: 16)); |
| 76 Expect.throws(() => D.closure('wrong arity'), (e) => e is NoSuchMethodError); | 79 Expect.throws(() => D.closure('wrong arity'), (e) => e is NoSuchMethodError); |
| 77 } | 80 } |
| 78 | 81 |
| 79 testClassReflective() { | 82 testClassReflective() { |
| 80 ClassMirror cm = reflectClass(D); | 83 ClassMirror cm = reflectClass(D); |
| 81 | 84 |
| 82 Expect.equals('1 5 6', cm.invoke(#fakeFunctionCall, [5, 6]).reflectee); | 85 Expect.equals('1 5 6', |
| 83 Expect.equals('7, 8', cm.invoke(#fakeFunctionNSM, [7, 8]).reflectee); | 86 cm.invoke(#fakeFunctionCall, [5, 6]).reflectee); |
| 84 Expect.equals('2 9 10', cm.invoke(#closure, [9, 10]).reflectee); | 87 Expect.equals('7, 8', |
| 85 Expect.equals( | 88 cm.invoke(#fakeFunctionNSM, [7, 8]).reflectee); |
| 86 '3 11 12 13 null', cm.invoke(#closureOpt, [11, 12, 13]).reflectee); | 89 Expect.equals('2 9 10', |
| 90 cm.invoke(#closure, [9, 10]).reflectee); |
| 91 Expect.equals('3 11 12 13 null', |
| 92 cm.invoke(#closureOpt, [11, 12, 13]).reflectee); |
| 87 Expect.equals('4 14 15 null 16', // //#
named: continued | 93 Expect.equals('4 14 15 null 16', // //#
named: continued |
| 88 cm.invoke(#closureNamed, [14, 15], {#w: 16}).reflectee); // //#
named: continued | 94 cm.invoke(#closureNamed, [14, 15], {#w: 16}).reflectee); // //#
named: continued |
| 89 Expect.throws(() => cm.invoke(#closure, ['wrong arity']), | 95 Expect.throws(() => cm.invoke(#closure, ['wrong arity']), |
| 90 (e) => e is NoSuchMethodError); | 96 (e) => e is NoSuchMethodError); |
| 91 } | 97 } |
| 92 | 98 |
| 93 get fakeFunctionCall => new FakeFunctionCall(); | 99 get fakeFunctionCall => new FakeFunctionCall(); |
| 94 get fakeFunctionNSM => new FakeFunctionNSM(); | 100 get fakeFunctionNSM => new FakeFunctionNSM(); |
| 95 get closure => (x, y) => '2 $x $y'; | 101 get closure => (x, y) => '2 $x $y'; |
| 96 get closureOpt => (x, y, [z, w]) => '3 $x $y $z $w'; | 102 get closureOpt => (x, y, [z, w]) => '3 $x $y $z $w'; |
| 97 get closureNamed => (x, y, {z, w}) => '4 $x $y $z $w'; | 103 get closureNamed => (x, y, {z, w}) => '4 $x $y $z $w'; |
| 98 get notAClosure => 'Not a closure'; | 104 get notAClosure => 'Not a closure'; |
| 99 | 105 |
| 100 testLibraryBase() { | 106 testLibraryBase() { |
| 101 Expect.equals('1 5 6', fakeFunctionCall(5, 6)); | 107 Expect.equals('1 5 6', fakeFunctionCall(5, 6)); |
| 102 Expect.equals('7, 8', fakeFunctionNSM(7, 8)); | 108 Expect.equals('7, 8', fakeFunctionNSM(7, 8)); |
| 103 Expect.equals('2 9 10', closure(9, 10)); | 109 Expect.equals('2 9 10', closure(9, 10)); |
| 104 Expect.equals('3 11 12 13 null', closureOpt(11, 12, 13)); | 110 Expect.equals('3 11 12 13 null', closureOpt(11, 12, 13)); |
| 105 Expect.equals('4 14 15 null 16', closureNamed(14, 15, w: 16)); | 111 Expect.equals('4 14 15 null 16', closureNamed(14, 15, w: 16)); |
| 106 Expect.throws(() => closure('wrong arity'), (e) => e is NoSuchMethodError); | 112 Expect.throws(() => closure('wrong arity'), (e) => e is NoSuchMethodError); |
| 107 } | 113 } |
| 108 | 114 |
| 109 testLibraryReflective() { | 115 testLibraryReflective() { |
| 110 LibraryMirror lm = reflectClass(D).owner; | 116 LibraryMirror lm = reflectClass(D).owner; |
| 111 | 117 |
| 112 Expect.equals('1 5 6', lm.invoke(#fakeFunctionCall, [5, 6]).reflectee); | 118 Expect.equals('1 5 6', |
| 113 Expect.equals('7, 8', lm.invoke(#fakeFunctionNSM, [7, 8]).reflectee); | 119 lm.invoke(#fakeFunctionCall, [5, 6]).reflectee); |
| 114 Expect.equals('2 9 10', lm.invoke(#closure, [9, 10]).reflectee); | 120 Expect.equals('7, 8', |
| 115 Expect.equals( | 121 lm.invoke(#fakeFunctionNSM, [7, 8]).reflectee); |
| 116 '3 11 12 13 null', lm.invoke(#closureOpt, [11, 12, 13]).reflectee); | 122 Expect.equals('2 9 10', |
| 123 lm.invoke(#closure, [9, 10]).reflectee); |
| 124 Expect.equals('3 11 12 13 null', |
| 125 lm.invoke(#closureOpt, [11, 12, 13]).reflectee); |
| 117 Expect.equals('4 14 15 null 16', // //#
named: continued | 126 Expect.equals('4 14 15 null 16', // //#
named: continued |
| 118 lm.invoke(#closureNamed, [14, 15], {#w: 16}).reflectee); // //#
named: continued | 127 lm.invoke(#closureNamed, [14, 15], {#w: 16}).reflectee); // //#
named: continued |
| 119 Expect.throws(() => lm.invoke(#closure, ['wrong arity']), | 128 Expect.throws(() => lm.invoke(#closure, ['wrong arity']), |
| 120 (e) => e is NoSuchMethodError); | 129 (e) => e is NoSuchMethodError); |
| 121 } | 130 } |
| 122 | 131 |
| 123 main() { | 132 main() { |
| 124 // Do not access the getters/closures at the base level in this variant. | 133 // Do not access the getters/closures at the base level in this variant. |
| 125 //testInstanceBase(); | 134 //testInstanceBase(); |
| 126 testInstanceReflective(); | 135 testInstanceReflective(); |
| 127 //testClassBase(); | 136 //testClassBase(); |
| 128 testClassReflective(); | 137 testClassReflective(); |
| 129 //testLibraryBase(); | 138 //testLibraryBase(); |
| 130 testLibraryReflective(); | 139 testLibraryReflective(); |
| 131 } | 140 } |
| OLD | NEW |