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

Unified Diff: tests/language/throw_expr_test.dart

Issue 10982051: Make throw an expression (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 months 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
« no previous file with comments | « tests/language/language_dart2js.status ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language/throw_expr_test.dart
===================================================================
--- tests/language/throw_expr_test.dart (revision 0)
+++ tests/language/throw_expr_test.dart (revision 0)
@@ -0,0 +1,96 @@
+// 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.
+
+// Dart test program for testing throw expressions.
+
+void test1() {
+ var x = 6;
+ try {
+ throw x = 10;
+ x = 0;
+ } catch(e) {
+ Expect.equals(10, e);
+ Expect.equals(10, x);
+ x = 15;
+ }
+ Expect.equals(15, x);
+ x = 100;
+ try {
+ throw x++;
+ x = 0;
+ } catch(e) {
+ Expect.equals(100, e);
+ Expect.equals(101, x);
+ x = 150;
+ }
+ Expect.equals(150, x);
+}
+
+void test2() {
+ var x = 6;
+ try {
+ throw x + 4;
+ } catch(e) {
+ Expect.equals(10, e);
+ Expect.equals(6, x);
+ x = 15;
+ }
+ Expect.equals(15, x);
+}
+
+foo(x, y) => throw "foo" "$x";
+
+bar(x, y) => throw "foo" "${throw x}";
+
+class Q {
+ var qqq;
+ f(x) { qqq = x; }
+}
+
+void test3() {
+ try {
+ throw throw throw "throw";
+ } catch(e) {
+ Expect.equals("throw", e);
+ }
siva 2012/09/26 21:09:12 I think the test will read much better if you chan
+
+ var x = 10;
+ try {
+ foo(x = 12, throw 7);
+ } catch(e) {
+ Expect.equals(7, e);
+ Expect.equals(12, x);
+ }
+
+ x = 10;
+ try {
+ foo(x++, 10);
+ } catch(e) {
+ Expect.equals("foo10", e);
+ Expect.equals(11, x);
+ }
+
+ x = 100;
+ try {
+ bar(++x, 10);
+ } catch(e) {
+ Expect.equals(101, e);
+ Expect.equals(101, x);
+ }
+
+ x = null;
+ try {
+ x = new Q();
+ x..f(11) ..qqq = throw 77 ..f(22);
+ } catch(e) {
+ Expect.equals(77, e);
+ Expect.equals(11, x.qqq);
+ }
+}
+
+main() {
+ test1();
+ test2();
+ test3();
+}
« no previous file with comments | « tests/language/language_dart2js.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698