| OLD | NEW |
| (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) { if (e) return true; else return false; } |
| 31 bool ifNull() => ifExpr(null); |
| 32 bool ifString() => ifExpr("true"); |
| 33 |
| 34 main() { |
| 35 print("type checks: $typeChecksOn"); |
| 36 print("assertions: $assertionsOn"); |
| 37 |
| 38 if (typeChecksOn) { |
| 39 Expect.throws(ifNull, (e) => e is AssertionError); |
| 40 } |
| 41 if (assertionsOn && !typeChecksOn) { |
| 42 Expect.throws(ifNull, (e) => e is AssertionError); |
| 43 } |
| 44 if (!typeChecksOn && !assertionsOn) { |
| 45 Expect.identical(false, ifNull()); |
| 46 } |
| 47 |
| 48 if (!typeChecksOn) { |
| 49 Expect.identical(false, ifString()); |
| 50 } |
| 51 if (typeChecksOn) { |
| 52 Expect.throws(ifString, (e) => e is TypeError); |
| 53 } |
| 54 } |
| OLD | NEW |