Chromium Code Reviews| Index: tests/language/tearoff_basic_test.dart |
| diff --git a/tests/language/tearoff_basic_test.dart b/tests/language/tearoff_basic_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9b7c67c019ee490aa8fa8b7dcb3b8303616f49c9 |
| --- /dev/null |
| +++ b/tests/language/tearoff_basic_test.dart |
| @@ -0,0 +1,141 @@ |
| +// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +// Basic test for tear-off closures. |
| + |
| +import "package:expect/expect.dart"; |
| +import "tearoff_basic_lib.dart" as P; |
| +import "tearoff_basic_lib.dart" deferred as D; |
| + |
| +class C { |
| + var v = 99; |
| + final fv = 444; |
| + |
| + operator + (a) { return v + a; } |
| + get sugus => "sugus"; |
| + set frosch(a) { v = "ribbit $a"; } |
| + foo() => "kuh"; |
| + |
| + static var st; |
| + static final stfin = 1000; |
| + static stfoo([p1 = 100]) => p1 * 10; |
| + static get stg => "stg"; |
| + static set sts(x) { st = x; } |
| +} |
| + |
| + |
| +testStatic() { |
| + // Closurize static variable. |
| + var a = C#st=; |
| + a(100); |
| + Expect.equals(100, C.st); |
| + var b = C#st; |
| + Expect.equals(100, b()); |
| + |
| + // Closurize static final variable. |
| + a = C#stfin; |
| + Expect.equals(1000, a()); |
| + Expect.throws(() => C#stfin= ); // Final variable has no setter. |
| + |
| + // Closurize static method. |
| + a = C#stfoo; |
| + Expect.equals(1000, a()); |
| + Expect.equals(90, a(9)); |
| + |
| + // Closurize static getter. |
| + a = C#stg; |
| + Expect.equals("stg", a()); |
| + |
| + // Closurize static setter. |
| + Expect.throws(() => C#sts); // No setter/method named sts exists. |
| + a = C#sts=; |
| + a("pflug"); |
| + Expect.equals("pflug", C.st); |
| + |
| + // Can't closurize instance method via class literal. |
| + Expect.throws(() => C#foo); |
| +} |
| + |
| +testInstance() { |
| + var o = new C(); |
| + var p = new C(); |
| + var a, b; |
| + |
| + // Closurize instance variable. |
| + a = o#v; |
| + Expect.equals(99, a()); |
| + b = p#v=; |
| + b(999); |
| + Expect.equals(999, p.v); |
| + Expect.equals(99, a()); |
| + |
| + // Closurize final instance variable. |
| + Expect.throws(() => o#fv=); // Final variable has not setter. |
| + a = o#fv; |
| + Expect.equals(444, a()); |
| + |
| + // Closurize instance method. |
| + a = o#foo; |
| + Expect.equals("kuh", a()); |
| + |
| + // Closurize operator. |
| + a = o#+; |
| + Expect.equals(100, o + 1); |
| + Expect.equals(100, a(1)); |
| + |
| + // Closurize instance getter. |
| + a = o#sugus; |
| + Expect.equals("sugus", a()); |
| + Expect.throws(() => o#sugus=); |
| + |
| + // Closurize instance setter. |
| + a = o#frosch=; |
| + a("!"); |
| + Expect.equals("ribbit !", o.v); |
| + Expect.throws(() => o#frosch); |
| +} |
| + |
| +testPrefix() { |
| + // Closurize top-level variable. |
| + var a = P#cvar; |
| + Expect.equals(6, a()); |
| + var b = P#cvar=; |
| + b(7); |
| + Expect.equals(7, a()); |
| + |
| + // Closurize final top-level variable. |
| + a = P#cfinvar; |
| + Expect.equals("set in stone", a()); |
| + Expect.throws(() => P#cfinvar=); |
| + |
| + // Closurize top-level function. |
| + a = P#cfunc; |
| + Expect.equals("cfunc", a()); |
| + |
| + // Closurize top-level getter. |
| + a = P#cget; |
| + Expect.equals("cget", a()); |
| + |
| + // Closurize top-level getter. |
| + a = P#cset=; |
| + a(99); |
| + Expect.equals(99, P.cvar); |
| + |
| + Expect.throws(() => P#ZZ); // Cannot closurize class. |
| +} |
| + |
| +testDeferred() { |
| + Expect.throws(() => D#cfunc); |
| + D.loadLibrary().then((_) { |
| + var a = D#cfunc; |
| + Expect.equals("cfunc", a()); |
| + }); |
| +} |
| + |
| +main() { |
| + testStatic(); |
| + testInstance(); |
| + testPrefix(); |
| + testDeferred(); |
|
Florian Schneider
2015/07/20 17:22:07
As Ryan mentioned, equality for closurized getters
hausner
2015/07/20 17:47:26
The spec says this: iff identical(o1,o2) then o1#m
|
| +} |