Index: tests/language/throw_expression_test.dart |
=================================================================== |
--- tests/language/throw_expression_test.dart (revision 0) |
+++ tests/language/throw_expression_test.dart (revision 0) |
@@ -0,0 +1,66 @@ |
+// Copyright (c) 2012, 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. |
+ |
+foo(a, b, c) {} |
+ |
+class A { |
+ foo() => 42; |
+} |
+ |
+void main() { |
+ Expect.throws( |
+ () => foo(throw 1, 2, 3), |
+ (e) => e == 1); |
+ Expect.throws( |
+ () => foo(1, throw 2, 3), |
+ (e) => e == 2); |
+ Expect.throws( |
+ () => foo(1, 2, throw 3), |
+ (e) => e == 3); |
+ Expect.throws( |
+ () => throw 3 + 7, |
+ (e) => e == 10); |
+ Expect.throws( |
+ () => -throw 3, |
+ (e) => e == 3); |
+ Expect.throws( |
+ () => throw -3, |
+ (e) => e == -3); |
+ Expect.throws( |
+ () => throw 3 * 7, |
+ (e) => e == 21); |
+ Expect.throws( |
+ () => throw new A()..foo(), |
+ (e) => e is A); |
+ Expect.throws( |
+ ([a]) => throw ?a ? 1 : 2, |
+ (e) => e == 2); |
+ Expect.throws( |
+ ([a]) => throw ?a, |
+ (e) => e == false); |
+ Expect.throws( |
+ () => throw +42, |
+ (e) => e == 42); |
+ Expect.throws( |
+ () => throw [], |
+ (e) => e is List); |
+ Expect.throws( |
+ () => throw [42], |
+ (e) => e is List); |
+ Expect.throws( |
+ () => throw (42), |
+ (e) => e == 42); |
+ Expect.throws( |
+ () => throw {}, |
+ (e) => e is Map); |
+ var value = 42; |
+ Expect.throws( |
+ () => throw ++value, |
+ (e) => e == 43); |
+ Expect.throws( |
+ () => throw --value, |
+ (e) => e == 42); |
+ |
+ throw (); /// 01: compile-time error |
+} |