mirror of
https://github.com/dart-lang/sdk
synced 2024-11-05 18:22:09 +00:00
c5ff5b4011
Successfully migrated 28 tests. Need manual work on 1 test: - language_2/truncdiv_test.dart: (TODO) Merge from language/truncdiv_test.dart into this file. Bug: Change-Id: Iceba114915feba5ab4564b8b7265d684d23b4d0d Reviewed-on: https://dart-review.googlesource.com/12360 Commit-Queue: Janice Collins <jcollins@google.com> Reviewed-by: Janice Collins <jcollins@google.com> Reviewed-by: Jaime Wren <jwren@google.com>
111 lines
1.7 KiB
Dart
111 lines
1.7 KiB
Dart
// 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.
|
|
|
|
import "package:expect/expect.dart";
|
|
|
|
// 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;
|
|
}
|
|
|
|
Q get nono => throw "nono";
|
|
}
|
|
|
|
void test3() {
|
|
try {
|
|
throw throw throw "up";
|
|
} catch (e) {
|
|
Expect.equals("up", e);
|
|
}
|
|
|
|
dynamic 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);
|
|
}
|
|
}
|
|
|
|
void test4() {
|
|
var q = new Q();
|
|
Expect.throws(() => q.nono, (e) => e == "nono");
|
|
}
|
|
|
|
main() {
|
|
test1();
|
|
test2();
|
|
test3();
|
|
test4();
|
|
}
|