Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Unified Diff: tests/language/throw_expression_test.dart

Issue 11497009: Revive throw as an expression but not for rethrow. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
+}

Powered by Google App Engine
This is Rietveld 408576698