Files
sdk/tests/compiler/dart2js/codegen/logical_expression_test.dart
T
Johnni Winther 6616ddeb88 Move dart2js unittests to subfolders
* All helpers in /helpers/
* Tests of user-facing behavior in /end_to_end/
* Tests of internal models and unittests of internal classes in /model/

Change-Id: Ic7a7e58aa01f92f8572514ae81230804f36af67e
Reviewed-on: https://dart-review.googlesource.com/72644
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2018-09-10 08:22:53 +00:00

53 lines
1.7 KiB
Dart

// Copyright (c) 2014, 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.
// Test that logical or-expressions don't introduce unnecessary nots.
import 'package:async_helper/async_helper.dart';
import '../helpers/compiler_helper.dart';
const String TEST_ONE = r"""
foo(bar, gee) {
bool cond1 = bar();
if (cond1 || gee()) gee();
if (cond1 || gee()) gee();
}
""";
const String TEST_TWO = r"""
void foo(list, bar) {
if (list == null) bar();
if (list == null || bar()) bar();
if (list == null || bar()) bar();
}
""";
main() {
runTests() async {
// We want something like:
// var t1 = bar.call$0() === true;
// if (t1 || gee.call$0() === true) gee.call$0();
// if (t1 || gee.call$0() === true) gee.call$0();
await compileAndDoNotMatchFuzzy(
TEST_ONE, 'foo', r"""var x = [a-zA-Z0-9$.]+\(\) == true;
if \(x \|\| [a-zA-Z0-9$.]+\(\) === true\) [^;]+;
if \(x \|\| [a-zA-Z0-9$.]+\(\) === true\) [^;]+;""");
// We want something like:
// var t1 = list == null;
// if (t1) bar.call$0();
// if (t1 || bar.call$0() === true) bar.call$0();
// if (t1 || bar.call$0() === true) bar.call$0();
await compileAndMatchFuzzy(TEST_TWO, 'foo', r"""var x = x == null;
if \(x\) [^;]+;
if \(x \|\| [a-zA-Z0-9$.]+\(\) === true\) [^;]+;
if \(x \|\| [a-zA-Z0-9$.]+\(\) === true\) [^;]+;""");
}
asyncTest(() async {
print('--test from kernel------------------------------------------------');
await runTests();
});
}