Files
sdk/tests/compiler/dart2js/codegen/class_codegen_test.dart
T
Stephen Adams 38467cca03 Track always-initialized-to-null fields
Change-Id: Idb4d3a0395ce73eaaa4fc15a8df3bceaa4821b4f
Reviewed-on: https://dart-review.googlesource.com/57525
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2018-06-04 21:05:01 +00:00

107 lines
2.0 KiB
Dart

// Copyright (c) 2012, 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 parameters keep their names in the output.
import "package:expect/expect.dart";
import "package:async_helper/async_helper.dart";
import '../compiler_helper.dart';
const String TEST_ONE = r"""
class A { }
class B { }
main() {
new A();
new B();
}
""";
const String TEST_TWO = r"""
class A { }
class B extends A { }
main() {
new A();
new B();
}
""";
const String TEST_THREE = r"""
class B extends A { }
class A { }
main() {
new B();
new A();
}
""";
const String TEST_FOUR = r"""
var g = 0;
class A {
var x = g++;
}
class B extends A {
var y = g++;
var z = g++;
}
main() {
new B();
}
""";
const String TEST_FIVE = r"""
class A {
var a;
A(a) : this.a = a {}
}
main() {
new A(3);
}
""";
twoClasses() async {
String generated = await compileAll(TEST_ONE);
Expect.isTrue(generated.contains(new RegExp('A: {[ \n]*"\\^": "Object;"')));
Expect.isTrue(generated.contains(new RegExp('B: {[ \n]*"\\^": "Object;"')));
}
subClass() async {
checkOutput(String generated) {
Expect.isTrue(generated.contains(new RegExp('A: {[ \n]*"\\^": "Object;"')));
Expect.isTrue(generated.contains(new RegExp('B: {[ \n]*"\\^": "A;"')));
}
checkOutput(await compileAll(TEST_TWO));
checkOutput(await compileAll(TEST_THREE));
}
fieldTest() async {
String generated = await compileAll(TEST_FOUR);
Expect.isTrue(generated
.contains(new RegExp('B: {[ \n]*"\\^": "A;y,z,x",[ \n]*static:')));
}
constructor1() async {
String generated = await compileAll(TEST_FIVE);
Expect.isTrue(generated.contains(new RegExp(r"new [$A-Z]+\.A\(a\);")));
}
main() {
runTests() async {
await twoClasses();
await subClass();
await fieldTest();
await constructor1();
}
asyncTest(() async {
print('--test from kernel------------------------------------------------');
await runTests();
});
}