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

Side by Side Diff: tests/language_strong/bool_check_test.dart

Issue 2985243002: Migrate block 44. (Closed)
Patch Set: Created 3 years, 4 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 import "package:expect/expect.dart";
6
7 bool typeChecksEnabled() {
8 try {
9 var i = 42;
10 String s = i;
11 } on TypeError catch (e) {
12 return true;
13 }
14 return false;
15 }
16
17 bool assertionsEnabled() {
18 try {
19 assert(false);
20 return false;
21 } on AssertionError catch (e) {
22 return true;
23 }
24 return false;
25 }
26
27 final bool typeChecksOn = typeChecksEnabled();
28 final bool assertionsOn = assertionsEnabled();
29
30 ifExpr(e) {
31 if (e)
32 return true;
33 else
34 return false;
35 }
36
37 bool ifNull() => ifExpr(null);
38 bool ifString() => ifExpr("true");
39
40 main() {
41 print("type checks: $typeChecksOn");
42 print("assertions: $assertionsOn");
43
44 if (typeChecksOn) {
45 Expect.throws(ifNull, (e) => e is AssertionError);
46 }
47 if (assertionsOn && !typeChecksOn) {
48 Expect.throws(ifNull, (e) => e is AssertionError);
49 }
50 if (!typeChecksOn && !assertionsOn) {
51 Expect.identical(false, ifNull());
52 }
53
54 if (!typeChecksOn) {
55 Expect.identical(false, ifString());
56 }
57 if (typeChecksOn) {
58 Expect.throws(ifString, (e) => e is TypeError);
59 }
60 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698