| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // Test that logical or-expressions don't introduce unnecessary nots. | 5 // Test that logical or-expressions don't introduce unnecessary nots. |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'package:async_helper/async_helper.dart'; | 8 import 'package:async_helper/async_helper.dart'; |
| 9 import 'compiler_helper.dart'; | 9 import 'compiler_helper.dart'; |
| 10 | 10 |
| 11 const String TEST_ONE = r""" | 11 const String TEST_ONE = r""" |
| 12 foo(bar, gee) { | 12 foo(bar, gee) { |
| 13 bool cond1 = bar(); | 13 bool cond1 = bar(); |
| 14 if (cond1 || gee()) gee(); | 14 if (cond1 || gee()) gee(); |
| 15 if (cond1 || gee()) gee(); | 15 if (cond1 || gee()) gee(); |
| 16 } | 16 } |
| 17 """; | 17 """; |
| 18 | 18 |
| 19 const String TEST_TWO = r""" | 19 const String TEST_TWO = r""" |
| 20 void foo(list, bar) { | 20 void foo(list, bar) { |
| 21 if (list == null) bar(); | 21 if (list == null) bar(); |
| 22 if (list == null || bar()) bar(); | 22 if (list == null || bar()) bar(); |
| 23 if (list == null || bar()) bar(); | 23 if (list == null || bar()) bar(); |
| 24 } | 24 } |
| 25 """; | 25 """; |
| 26 | 26 |
| 27 main() { | 27 main() { |
| 28 asyncTest(() => Future.wait([ | 28 asyncTest(() => Future.wait([ |
| 29 // We want something like: | 29 // We want something like: |
| 30 // var t1 = bar.call$0() === true; | 30 // var t1 = bar.call$0() === true; |
| 31 // if (t1 || gee.call$0() === true) gee.call$0(); | 31 // if (t1 || gee.call$0() === true) gee.call$0(); |
| 32 // if (t1 || gee.call$0() === true) gee.call$0(); | 32 // if (t1 || gee.call$0() === true) gee.call$0(); |
| 33 compileAndDoNotMatchFuzzy(TEST_ONE, 'foo', | 33 compileAndDoNotMatchFuzzy( |
| 34 r"""var x = [a-zA-Z0-9$.]+\(\) == true; | 34 TEST_ONE, |
| 35 'foo', |
| 36 r"""var x = [a-zA-Z0-9$.]+\(\) == true; |
| 35 if \(x \|\| [a-zA-Z0-9$.]+\(\) === true\) [^;]+; | 37 if \(x \|\| [a-zA-Z0-9$.]+\(\) === true\) [^;]+; |
| 36 if \(x \|\| [a-zA-Z0-9$.]+\(\) === true\) [^;]+;"""), | 38 if \(x \|\| [a-zA-Z0-9$.]+\(\) === true\) [^;]+;"""), |
| 37 | 39 |
| 38 | 40 // We want something like: |
| 39 // We want something like: | 41 // var t1 = list == null; |
| 40 // var t1 = list == null; | 42 // if (t1) bar.call$0(); |
| 41 // if (t1) bar.call$0(); | 43 // if (t1 || bar.call$0() === true) bar.call$0(); |
| 42 // if (t1 || bar.call$0() === true) bar.call$0(); | 44 // if (t1 || bar.call$0() === true) bar.call$0(); |
| 43 // if (t1 || bar.call$0() === true) bar.call$0(); | 45 compileAndMatchFuzzy( |
| 44 compileAndMatchFuzzy(TEST_TWO, 'foo', | 46 TEST_TWO, |
| 45 r"""var x = x == null; | 47 'foo', |
| 48 r"""var x = x == null; |
| 46 if \(x\) [^;]+; | 49 if \(x\) [^;]+; |
| 47 if \(x \|\| [a-zA-Z0-9$.]+\(\) === true\) [^;]+; | 50 if \(x \|\| [a-zA-Z0-9$.]+\(\) === true\) [^;]+; |
| 48 if \(x \|\| [a-zA-Z0-9$.]+\(\) === true\) [^;]+;"""), | 51 if \(x \|\| [a-zA-Z0-9$.]+\(\) === true\) [^;]+;"""), |
| 49 ])); | 52 ])); |
| 50 } | 53 } |
| OLD | NEW |