f8086c81ae
Collects files from `package:async_helper` and `tests/language` that are generally useful, so that all test-related helpers are in `package:expect`. Moves the two libraries from `package:async_helper` into `package:expect`, and the `tests/language/static_type_helper.dart` file too. Deprecates `async_minitest.dart`, to follow `minitest.dart`, expecting the Flutter use of it to have been fixed to not break on deprecation (I believe Flutter no longer breaks builds on deprecations at all). Patch 1 is the actual change. Patch 2+4+8 is changing all existing references to the files. Patch 6 ignores deprecation in files still using `async_minitest.dart`. 3+5+7+9 are updating this text to make the numbers match. Then it's just test-expectations and small tweaks from there. Change-Id: I1b665135b5fef9b9a0c3b340ffe9daf874d0174c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/373120 Reviewed-by: Nate Bosch <nbosch@google.com> Reviewed-by: Devon Carew <devoncarew@google.com> Commit-Queue: Lasse Nielsen <lrn@google.com>
97 lines
2.1 KiB
Dart
97 lines
2.1 KiB
Dart
// Copyright (c) 2015, 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.
|
|
|
|
library bitops2_test;
|
|
|
|
import 'dart:async';
|
|
import 'package:expect/async_helper.dart';
|
|
import '../helpers/compiler_helper.dart';
|
|
|
|
const COMMON = r"""
|
|
int g1 = 0, g2 = 0;
|
|
int sink1 = 0, sink2 = 0;
|
|
|
|
main() {
|
|
for (int i = 0; i < 0x100000000; i = i + (i >> 4) + 1) {
|
|
g1 = g2 = i;
|
|
sink1 = callFoo(i, 1 - i, i);
|
|
sink2 = callFoo(2 - i, i, 3 - i);
|
|
}
|
|
}
|
|
""";
|
|
|
|
const String TEST1 = r"""
|
|
int foo(int param) {
|
|
return (param & 0xFF0000) >> 16;
|
|
// Shift mask reduction.
|
|
// present: 'return param >>> 16 & 255;'
|
|
// absent: 'FF0000'
|
|
// absent: '16711680'
|
|
}
|
|
""";
|
|
|
|
const String TEST2 = r"""
|
|
int foo(int param) {
|
|
param &= 0xFFFFFFFF;
|
|
if (param == 0) return -1;
|
|
return param << 0;
|
|
// Shift-by-zero reduction.
|
|
// present: 'return param;'
|
|
}
|
|
""";
|
|
|
|
const String TEST3 = r"""
|
|
int foo(int param) {
|
|
param &= 0xFFFFFFFF;
|
|
if (param == 0) return -1;
|
|
return ((param >> 8) & 7) << 8;
|
|
// Shift-mask-unshift reduction.
|
|
// present: 'return param & 1792;'
|
|
}
|
|
""";
|
|
|
|
const String TEST4 = r"""
|
|
foo(int color) {
|
|
int alpha = 100;
|
|
int red = (color & 0xFF0000) >> 16;
|
|
int green = (color & 0xFF00) >> 8;
|
|
int blue = (color & 0xFF) >> 0;
|
|
|
|
return (alpha & 255) << 24 |
|
|
(red & 255) << 16 |
|
|
(green & 255) << 8 |
|
|
(blue & 255) << 0;
|
|
|
|
// present: 'color & 16777215 | 1677721600'
|
|
// absent: '<<'
|
|
// absent: '>>'
|
|
}
|
|
""";
|
|
|
|
main() {
|
|
runTests() async {
|
|
Future check(String test) {
|
|
String program = COMMON + '\n\n' + test;
|
|
if (!test.contains('callFoo')) {
|
|
program += 'int callFoo(int a, int b, int c) => foo(a);\n';
|
|
}
|
|
return compile(program,
|
|
entry: 'main',
|
|
methodName: 'foo',
|
|
disableTypeInference: false,
|
|
check: checkerForAbsentPresent(test));
|
|
}
|
|
|
|
await check(TEST1);
|
|
await check(TEST2);
|
|
await check(TEST3);
|
|
await check(TEST4);
|
|
}
|
|
|
|
asyncTest(() async {
|
|
print('--test from kernel------------------------------------------------');
|
|
await runTests();
|
|
});
|
|
}
|