-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add more tests for variables. Note that Language/Classes/Instance_Variables/constant_t01.dart, Language/Variables/covariant_t01.dart, Language/Variables/static_variable_t02.dart have syntax errors intentionally.
- Loading branch information
Showing
6 changed files
with
237 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) 2023, 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. | ||
|
||
/// @assertion It is a compile-time error for the declaration of a variable | ||
/// which is not an instance variable to include the modifier covariant. | ||
/// | ||
/// @description Checks that a compile-time error if not-instance variable has a | ||
/// modifier `covariant` | ||
/// @author [email protected] | ||
/**/covariant var c1 = 1; | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
/**/covariant int c2 = 2; | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
class C { | ||
static covariant var c3 = 3; | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
static covariant int c4 = 4; | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
main() { | ||
covariant var c5 = 5; | ||
//^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
covariant int c6 = 6; | ||
//^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright (c) 2023, 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. | ||
|
||
/// @assertion An ⟨initializedVariableDeclaration⟩ that declares two or more | ||
/// variables is equivalent to multiple variable declarations declaring the same | ||
/// set of variable names, in the same order, with the same initialization, | ||
/// type, and modifiers | ||
/// | ||
/// @description Checks that two or more variables is equivalent to multiple | ||
/// variable declarations declaring the same set of variable names, in the same | ||
/// order, with the same initialization, type, and modifiers | ||
/// @author [email protected] | ||
import "../../Utils/expect.dart"; | ||
|
||
var v1 = 1, v2, v3 = "3"; | ||
int? i1 = 1, i2, i3 = i1; | ||
final int fi1 = 1, fi2 = fi1, fi3 = fi2; | ||
|
||
class C { | ||
static var s1 = 1, s2, s3 = "3"; | ||
static int? si1 = 1, si2, si3 = si1; | ||
static final int sfi1 = 1, sfi2 = sfi1, sfi3 = sfi2; | ||
|
||
var _v1 = 1, _v2, _v3 = "3"; | ||
int? _i1 = 1, _i2, _i3 = 3; | ||
final int _fi1 = 1, _fi2 = 2; | ||
} | ||
|
||
main() { | ||
var lv1 = 1, lv2, lv3 = "3"; | ||
int? li1 = 1, li2, li3 = li1; | ||
final int lfi1 = 1, lfi2 = lfi1, lfi3 = lfi2; | ||
|
||
Expect.equals(1, v1); | ||
Expect.isNull(v2); | ||
Expect.equals("3", v3); | ||
Expect.equals(1, i1); | ||
Expect.isNull(i2); | ||
Expect.equals(1, i3); | ||
Expect.equals(1, fi1); | ||
Expect.equals(1, fi1); | ||
Expect.equals(1, fi3); | ||
|
||
Expect.equals(1, C.s1); | ||
Expect.isNull(C.s2); | ||
Expect.equals("3", C.s3); | ||
Expect.equals(1, C.si1); | ||
Expect.isNull(C.si2); | ||
Expect.equals(1, C.si3); | ||
Expect.equals(1, C.sfi1); | ||
Expect.equals(1, C.sfi1); | ||
Expect.equals(1, C.sfi3); | ||
|
||
C c = C(); | ||
Expect.equals(1, c._v1); | ||
Expect.isNull(c._v2); | ||
Expect.equals("3", c._v3); | ||
Expect.equals(1, c._i1); | ||
Expect.isNull(c._i2); | ||
Expect.equals(3, c._i3); | ||
Expect.equals(1, c._fi1); | ||
Expect.equals(1, c._fi1); | ||
|
||
Expect.equals(1, lv1); | ||
Expect.isNull(lv2); | ||
Expect.equals("3", lv3); | ||
Expect.equals(1, li1); | ||
Expect.isNull(li2); | ||
Expect.equals(1, li3); | ||
Expect.equals(1, lfi1); | ||
Expect.equals(1, lfi1); | ||
Expect.equals(1, lfi3); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright (c) 2023, 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. | ||
|
||
/// @assertion An ⟨initializedVariableDeclaration⟩ that declares two or more | ||
/// variables is equivalent to multiple variable declarations declaring the same | ||
/// set of variable names, in the same order, with the same initialization, | ||
/// type, and modifiers | ||
/// | ||
/// @description Checks that two or more variables is equivalent to multiple | ||
/// variable declarations declaring the same set of variable names, in the same | ||
/// order, with the same initialization, type, and modifiers. Test late | ||
/// variables. | ||
/// @author [email protected] | ||
import "../../Utils/expect.dart"; | ||
|
||
class Log { | ||
static String log = ""; | ||
static void clearLog() { | ||
log = ""; | ||
} | ||
|
||
int val; | ||
Log(this.val) { | ||
log += "$val;"; | ||
} | ||
} | ||
|
||
late var v1 = Log(1), v2 = Log(2); | ||
late final Log v3 = Log(3), v4 = v3; | ||
|
||
class C { | ||
static late var v5 = Log(5), v6 = Log(6); | ||
static late final Log v7 = Log(7), v8 = v7; | ||
|
||
late var v9 = Log(9), v10 = Log(10); | ||
late final Log v11 = Log(11), v12 = v11; | ||
} | ||
|
||
main() { | ||
late var v13 = Log(13), v14 = Log(14); | ||
late final Log v15 = Log(15), v16 = v15; | ||
|
||
Expect.equals("", Log.log); | ||
print(v1); | ||
Expect.equals("1;", Log.log); | ||
print(v2); | ||
Expect.equals("1;2;", Log.log); | ||
print(v4); | ||
Expect.equals("1;2;3;", Log.log); | ||
|
||
Log.clearLog(); | ||
print(C.v5); | ||
Expect.equals("5;", Log.log); | ||
print(C.v6); | ||
Expect.equals("5;6;", Log.log); | ||
print(C.v8); | ||
Expect.equals("5;6;7;", Log.log); | ||
|
||
Log.clearLog(); | ||
C c = C(); | ||
print(c.v9); | ||
Expect.equals("9;", Log.log); | ||
print(c.v10); | ||
Expect.equals("9;10;", Log.log); | ||
print(c.v12); | ||
Expect.equals("9;10;11;", Log.log); | ||
|
||
Log.clearLog(); | ||
print(v13); | ||
Expect.equals("13;", Log.log); | ||
print(v14); | ||
Expect.equals("13;14;", Log.log); | ||
print(v16); | ||
Expect.equals("13;14;15;", Log.log); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters