Chromium Code Reviews| 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 class Proxy { | |
| 6 final proxied; | |
| 7 Proxy(this.proxied); | |
| 8 noSuchMethod(mirror) => mirror.invokeOn(proxied); | |
| 9 } | |
| 10 | |
| 11 main() { | |
| 12 testList(); | |
| 13 testString(); | |
| 14 testInt(); | |
| 15 testDouble(); | |
|
ngeoffray
2013/02/06 12:40:39
If you want to be exhaustive, you can also check n
kasperl
2013/02/06 12:46:14
Yeah, but none of those objects have any methods I
ngeoffray
2013/02/06 12:50:31
Good point :)
| |
| 16 } | |
| 17 | |
| 18 testList() { | |
| 19 var list = []; | |
| 20 var proxy = new Proxy(list); | |
| 21 | |
| 22 Expect.isTrue(proxy.isEmpty); | |
| 23 Expect.isTrue(list.isEmpty); | |
| 24 | |
| 25 proxy.add(42); | |
| 26 | |
| 27 Expect.isFalse(proxy.isEmpty); | |
| 28 Expect.equals(1, proxy.length); | |
| 29 Expect.equals(42, proxy[0]); | |
| 30 | |
| 31 Expect.isFalse(list.isEmpty); | |
| 32 Expect.equals(1, list.length); | |
| 33 Expect.equals(42, list[0]); | |
| 34 | |
| 35 proxy.add(87); | |
| 36 | |
| 37 Expect.equals(2, proxy.length); | |
| 38 Expect.equals(87, proxy[1]); | |
| 39 | |
| 40 Expect.equals(2, list.length); | |
| 41 Expect.equals(87, list[1]); | |
| 42 | |
| 43 Expect.throws(() => proxy.funky(), (e) => e is NoSuchMethodError); | |
| 44 Expect.throws(() => list.funky(), (e) => e is NoSuchMethodError); | |
| 45 } | |
| 46 | |
| 47 testString() { | |
| 48 var string = "funky"; | |
| 49 var proxy = new Proxy(string); | |
| 50 | |
| 51 Expect.equals(string.charCodeAt(0), proxy.charCodeAt(0)); | |
| 52 Expect.equals(string.length, proxy.length); | |
| 53 | |
| 54 Expect.throws(() => proxy.funky(), (e) => e is NoSuchMethodError); | |
| 55 Expect.throws(() => string.funky(), (e) => e is NoSuchMethodError); | |
| 56 } | |
| 57 | |
| 58 testInt() { | |
| 59 var number = 42; | |
| 60 var proxy = new Proxy(number); | |
| 61 | |
| 62 Expect.equals(number + 87, proxy + 87); | |
| 63 Expect.equals(number.toDouble(), proxy.toDouble()); | |
| 64 | |
| 65 Expect.throws(() => proxy.funky(), (e) => e is NoSuchMethodError); | |
| 66 Expect.throws(() => number.funky(), (e) => e is NoSuchMethodError); | |
| 67 } | |
| 68 | |
| 69 testDouble() { | |
| 70 var number = 42.99; | |
| 71 var proxy = new Proxy(number); | |
| 72 | |
| 73 Expect.equals(number + 87, proxy + 87); | |
| 74 Expect.equals(number.toInt(), proxy.toInt()); | |
| 75 | |
| 76 Expect.throws(() => proxy.funky(), (e) => e is NoSuchMethodError); | |
| 77 Expect.throws(() => number.funky(), (e) => e is NoSuchMethodError); | |
| 78 } | |
| OLD | NEW |