dart-sdk/tests/language_strong/static_field_test.dart
Bob Nystrom 6c757957db Move the dev_compiler strong mode tests into sdk/tests/.
DDC's codegen test copies those files to a local "gen" directory so
that it can do stuff like splitting out the multitests before it
compiles them to JS.

I left all of that alone, so the rest of DDC's test infrastructure is
unchanged. The very first step that builds the "gen" directory just
copies from sdk/tests/..._strong/... instead and the rest is good to go.

I did not move not_yet_strong_tests.dart somewhere more accessible yet
because I'm not sure if kernel needs it or where it should go.

I did not create any status files because DDC doesn't need them and
there are no test suites for the new directories for the other
platforms.
2016-12-09 11:09:55 -08:00

118 lines
2.8 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.
// Dart test program for testing setting/getting/initializing static fields.
import "package:expect/expect.dart";
class First {
First() {}
static var a;
static var b;
static const int c = 1;
static setValues() {
a = 24;
b = 10;
return a + b + c;
}
}
class InitializerTest {
static var one;
static var two = 2;
static var three = 2;
static checkValueOfThree() {
// We need to keep this check separate to prevent three from
// getting initialized before the += is executed.
Expect.equals(3, three);
}
static void testStaticFieldInitialization() {
Expect.equals(null, one);
Expect.equals(2, two);
one = 11;
two = 22;
Expect.equals(11, one);
Expect.equals(22, two);
// Assignment operators exercise a different code path. Make sure
// that initialization works here as well.
three += 1;
checkValueOfThree();
}
}
class StaticFieldTest {
static testMain() {
First.a = 3;
First.b = First.a;
Expect.equals(3, First.a);
Expect.equals(First.a, First.b);
First.b = (First.a = 10);
Expect.equals(10, First.a);
Expect.equals(10, First.b);
First.b = First.a = 15;
Expect.equals(15, First.a);
Expect.equals(15, First.b);
Expect.equals(35, First.setValues());
Expect.equals(24, First.a);
Expect.equals(10, First.b);
}
}
class StaticField1RunNegativeTest {
static /// 01: static type warning, runtime error
var x;
testMain() {
var foo = new StaticField1RunNegativeTest();
print(x); // Used to compile 'x' and force any errors.
var result = foo.x;
}
}
class StaticField1aRunNegativeTest {
static /// 02: static type warning, runtime error
void m() {}
testMain() {
var foo = new StaticField1aRunNegativeTest();
print(m); // Used to compile 'm' and force any errors.
var result = foo.m;
}
}
class StaticField2RunNegativeTest {
static /// 03: static type warning, runtime error
var x;
testMain() {
var foo = new StaticField2RunNegativeTest();
print(x); // Used to compile 'x' and force any errors.
foo.x = 1;
}
}
class StaticField2aRunNegativeTest {
static /// 04: static type warning, runtime error
void m() {}
testMain() {
var foo = new StaticField2aRunNegativeTest();
print(m); // Used to compile 'm' and force any errors.
foo.m = 1; /// 04:continued
}
}
main() {
StaticFieldTest.testMain();
InitializerTest.testStaticFieldInitialization();
new StaticField1RunNegativeTest().testMain();
new StaticField1aRunNegativeTest().testMain();
new StaticField2RunNegativeTest().testMain();
new StaticField2aRunNegativeTest().testMain();
}