OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, 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 // Test that dart2js does not rewrite conditional into logical operators |
| 8 // in cases where it changes which falsy value is returned. |
| 9 |
| 10 posFalse(x, y) => x != null ? y : false; |
| 11 negFalse(x, y) => x != null ? !y : false; |
| 12 posNull(x, y) => x != null ? y : null; |
| 13 negNull(x, y) => x != null ? !y : null; |
| 14 |
| 15 main() { |
| 16 bool isCheckedMode = false; |
| 17 assert((isCheckedMode = true)); |
| 18 |
| 19 Expect.equals(false, posFalse(null, false)); |
| 20 Expect.equals(false, negFalse(null, false)); |
| 21 Expect.equals(null, posNull(null, false)); |
| 22 Expect.equals(null, negNull(null, false)); |
| 23 |
| 24 Expect.equals(false, posFalse(null, true)); |
| 25 Expect.equals(false, negFalse(null, true)); |
| 26 Expect.equals(null, posNull(null, true)); |
| 27 Expect.equals(null, negNull(null, true)); |
| 28 |
| 29 Expect.equals(false, posFalse([], false)); |
| 30 Expect.equals(true, negFalse([], false)); |
| 31 Expect.equals(false, posNull([], false)); |
| 32 Expect.equals(true, negNull([], false)); |
| 33 |
| 34 Expect.equals(true, posFalse([], true)); |
| 35 Expect.equals(false, negFalse([], true)); |
| 36 Expect.equals(true, posNull([], true)); |
| 37 Expect.equals(false, negNull([], true)); |
| 38 |
| 39 if (!isCheckedMode) { |
| 40 Expect.equals(null, posFalse([], null)); |
| 41 Expect.equals(true, negFalse([], null)); |
| 42 Expect.equals(null, posNull([], null)); |
| 43 Expect.equals(true, negNull([], null)); |
| 44 |
| 45 var y = {}; |
| 46 Expect.identical(y, posFalse([], y)); |
| 47 Expect.equals(true, negFalse([], y)); |
| 48 Expect.identical(y, posNull([], y)); |
| 49 Expect.equals(true, negNull([], y)); |
| 50 } |
| 51 } |
OLD | NEW |