Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Unified Diff: tests/compiler/dart2js/kernel/loops_test.dart

Issue 2377813002: kernel->ssa: implement for-in loops (Closed)
Patch Set: fix another import Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/compiler/dart2js/kernel/helper.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/compiler/dart2js/kernel/loops_test.dart
diff --git a/tests/compiler/dart2js/kernel/loops_test.dart b/tests/compiler/dart2js/kernel/loops_test.dart
index 6535e95a3a66a0ddcda2d8c8672bed438c5485a3..a619c360bebf77e7c05da189e1bad412cf13cb46 100644
--- a/tests/compiler/dart2js/kernel/loops_test.dart
+++ b/tests/compiler/dart2js/kernel/loops_test.dart
@@ -7,7 +7,7 @@ import 'package:test/test.dart';
import 'helper.dart' show check;
main() {
- test('for-loop', () {
+ test('for loop', () {
String code = '''
main() {
var a = 0;
@@ -19,7 +19,7 @@ main() {
return check(code);
});
- test('while-loop', () {
+ test('while loop', () {
String code = '''
main() {
var a = 0;
@@ -30,4 +30,46 @@ main() {
}''';
return check(code);
});
+
+ test('for-in loop', () {
+ String code = '''
+main() {
+ var sum = 0;
+ for (var a in [1, 2, 3]) {
+ sum += a;
+ }
+ return sum;
+}''';
+ // TODO(het): Check that the code is alpha-equivalent. That is,
+ // the same except for variable names.
+ return check(code);
+ }, skip: "The output is the same, with one variable renamed");
+
+ test('for-in loop optimized', () {
+ String code = '''
+main() {
+ var sum = 0;
+ for (var a in [1, 2, 3]) {
+ sum += a;
+ }
+ return sum;
+}''';
+ // This is the same test as above, but by enabling type inference
+ // we allow the compiler to detect that it can iterate over the
+ // array using indexing.
+ return check(code, disableTypeInference: false);
+ });
+
+ test('for-in loop top-level variable', () {
+ String code = '''
+var a = 0;
+main() {
+ var sum = 0;
+ for (a in [1, 2, 3]) {
+ sum += a;
+ }
+ return sum;
+}''';
+ return check(code, disableTypeInference: false);
+ });
}
« no previous file with comments | « tests/compiler/dart2js/kernel/helper.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698