Skip to content

Commit 0c74931

Browse files
committed
#2119. Update assertions in const literals tests
1 parent 4c249d5 commit 0c74931

9 files changed

Lines changed: 168 additions & 92 deletions

Language/Expressions/Constants/literal_boolean_t01.dart

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,25 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
/// @assertion A constant expression is an expression whose value can never
6-
/// change, and that can be evaluated entirely at compile time.
7-
/// A constant expression is one of the following:
8-
/// . . .
9-
/// • A literal boolean.
10-
/// @description Checks that various literal booleans can be elements of a
11-
/// constant list literal and are, therefore, constant expressions.
5+
/// @assertion All usages of ’constant’ in Dart are associated with compile time.
6+
/// A potentially constant expression is an expression that will generally yield
7+
/// a constant value when the values of certain parameters are given. The
8+
/// constant expressions is a subset of the potentially constant expressions
9+
/// that can be evaluated at compile time.
10+
///
11+
/// The potentially constant expressions and constant expressions are the
12+
/// following:
13+
/// ...
14+
/// • A literal boolean, `true` or `false`, is a potentially constant and
15+
/// constant expression.
16+
///
17+
/// @description Checks that various literal booleans are constants.
1218
/// @author iefremov
1319
14-
import '../../../Utils/expect.dart';
15-
16-
final constList = const [
17-
true,
18-
false
19-
];
20+
const _true = true;
21+
const _false = false;
2022

2123
main() {
22-
Expect.isTrue(constList is List);
23-
Expect.runtimeIsType<List>(constList);
24+
print(_true);
25+
print(_false);
2426
}

Language/Expressions/Constants/literal_number_t01.dart

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,27 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
/// @assertion A constant expression is an expression whose value can never
6-
/// change, and that can be evaluated entirely at compile time.
7-
/// A constant expression is one of the following:
8-
/// • A literal number.
9-
/// @description Checks that 0xFFffFFffFFffFFff can be elements of a
10-
/// constant list literal and шы, therefore, constant expressions. Minus sign
5+
/// @assertion All usages of ’constant’ in Dart are associated with compile time.
6+
/// A potentially constant expression is an expression that will generally yield
7+
/// a constant value when the values of certain parameters are given. The
8+
/// constant expressions is a subset of the potentially constant expressions
9+
/// that can be evaluated at compile time.
10+
///
11+
/// The potentially constant expressions and constant expressions are the
12+
/// following:
13+
/// ...
14+
/// • A literal number is a potentially constant and constant expression if it
15+
/// evaluates to an instance of type `int` or `double`.
16+
///
17+
/// @description Checks that `0xFFffFFffFFffFFff` can be elements of a
18+
/// constant list literal and is, therefore, a constant expressions. Minus sign
1119
/// is not a part of a number literal so those are not included in this test.
12-
/// Should be excluded for the web runs as 0xFFffFFffFFffFFff is not allowed as
13-
/// a literal number there.
20+
/// Should be excluded for the web runs as `0xFFffFFffFFffFFff` is not allowed
21+
/// as a literal number there.
1422
/// @author iefremov
1523
16-
import '../../../Utils/expect.dart';
17-
18-
final constList = const [
19-
0xFFffFFffFFffFFff
20-
];
24+
const c = 0xFFffFFffFFffFFff;
2125

2226
main() {
23-
Expect.isTrue(constList is List);
24-
Expect.runtimeIsType<List>(constList);
27+
print(c);
2528
}

Language/Expressions/Constants/literal_number_t02.dart

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,32 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
/// @assertion A constant expression is an expression whose value can never
6-
/// change, and that can be evaluated entirely at compile time.
7-
/// A constant expression is one of the following:
8-
/// • A literal number.
5+
/// @assertion All usages of ’constant’ in Dart are associated with compile time.
6+
/// A potentially constant expression is an expression that will generally yield
7+
/// a constant value when the values of certain parameters are given. The
8+
/// constant expressions is a subset of the potentially constant expressions
9+
/// that can be evaluated at compile time.
10+
///
11+
/// The potentially constant expressions and constant expressions are the
12+
/// following:
13+
/// ...
14+
/// • A literal number is a potentially constant and constant expression if it
15+
/// evaluates to an instance of type `int` or `double`.
16+
///
917
/// @description Checks that various literal numbers can be elements of a
1018
/// constant list literal and are, therefore, constant expressions. Minus sign
1119
/// is not a part of a number literal so those are not included in this test.
1220
/// @note Should be OK both with dart and dart2js runs.
1321
/// @author iarkh@unipro.ru
1422
15-
import '../../../Utils/expect.dart';
16-
1723
final constList = const [
1824
0,
1925
1,
2026
2147483647,
21-
-.2147483648E10,
27+
.2147483648E10,
2228
.9223372036854775807,
2329
9223372036854775808E-100,
24-
-9223372036854775808e0,
30+
9223372036854775808e0,
2531
9223372036854775809e+9223372036854775809,
2632
92233720368547758080.9223372036854775808e-00124155125325235,
2733
92233720368547758080.9223372036854775808e+92233720368547758080,
@@ -31,6 +37,5 @@ final constList = const [
3137
];
3238

3339
main() {
34-
Expect.isTrue(constList is List);
35-
Expect.runtimeIsType<List>(constList);
40+
print(constList);
3641
}

Language/Expressions/Constants/literal_string_t01.dart

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,25 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
/// @assertion A constant expression is an expression whose value can never
6-
/// change, and that can be evaluated entirely at compile time.
7-
/// A constant expression is one of the following:
8-
/// . . .
9-
/// • A literal string where any interpolated expression is a compile-time
10-
/// constant that evaluates to a numeric, string or boolean value or to null.
5+
/// @assertion All usages of ’constant’ in Dart are associated with compile time.
6+
/// A potentially constant expression is an expression that will generally yield
7+
/// a constant value when the values of certain parameters are given. The
8+
/// constant expressions is a subset of the potentially constant expressions
9+
/// that can be evaluated at compile time.
10+
///
11+
/// The potentially constant expressions and constant expressions are the
12+
/// following:
13+
/// ...
14+
/// • A literal string with string interpolations with expressions `e1, ..., en`
15+
/// is a potentially constant expression if `e1, ..., en` are potentially
16+
/// constant expressions. The literal is further a constant expression if
17+
/// `e1, . . . , en` are constant expressions evaluating to instances of `int`,
18+
/// `double`, `String`, `bool`, or `Null`.
19+
///
1120
/// @description Checks that various literal strings can be elements of a
1221
/// constant list literal and are, therefore, constant expressions.
1322
/// @author iefremov
1423
15-
import '../../../Utils/expect.dart';
16-
1724
final constList = const [
1825
"",
1926
"test",
@@ -56,10 +63,7 @@ final constListConcatenation = const [
5663
];
5764

5865
main() {
59-
Expect.isTrue(constList is List);
60-
Expect.isTrue(constListInterpolation is List);
61-
Expect.isTrue(constListConcatenation is List);
62-
Expect.runtimeIsType<List>(constList);
63-
Expect.runtimeIsType<List>(constListInterpolation);
64-
Expect.runtimeIsType<List>(constListConcatenation);
66+
print(constList);
67+
print(constListInterpolation);
68+
print(constListConcatenation);
6569
}

Language/Expressions/Constants/literal_string_t02.dart

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,49 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
/// @assertion A constant expression is an expression whose value can never
6-
/// change, and that can be evaluated entirely at compile time.
7-
/// A constant expression is one of the following:
8-
/// . . .
9-
/// • A literal string where any interpolated expression is a compile-time
10-
/// constant that evaluates to a numeric, string or boolean value or to null.
5+
/// @assertion All usages of ’constant’ in Dart are associated with compile time.
6+
/// A potentially constant expression is an expression that will generally yield
7+
/// a constant value when the values of certain parameters are given. The
8+
/// constant expressions is a subset of the potentially constant expressions
9+
/// that can be evaluated at compile time.
10+
///
11+
/// The potentially constant expressions and constant expressions are the
12+
/// following:
13+
/// ...
14+
/// • A literal string with string interpolations with expressions `e1, ..., en`
15+
/// is a potentially constant expression if `e1, ..., en` are potentially
16+
/// constant expressions. The literal is further a constant expression if
17+
/// `e1, . . . , en` are constant expressions evaluating to instances of `int`,
18+
/// `double`, `String`, `bool`, or `Null`.
19+
///
1120
/// @description Checks that a string literal that involves string interpolation,
12-
/// that is a constant expression not evaluated to numeric, string or boolean
13-
/// value, cannot be assigned to a constant variable.
21+
/// that is a constant expression not evaluated to `int`, `double`, `String`,
22+
/// `bool`, or `Null` cannot be assigned to a constant variable.
1423
/// @author iefremov
1524
16-
const l = "${const {'k1': 1, 'k2': 2}}";
17-
// ^
25+
class C {
26+
const C();
27+
}
28+
29+
const c1 = "${const {'k1': 1, 'k2': 2}}";
30+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^
31+
// [analyzer] unspecified
32+
// [cfe] unspecified
33+
34+
const c2 = "${#foo}";
35+
// ^^^^^^^
36+
// [analyzer] unspecified
37+
// [cfe] unspecified
38+
39+
const c = C();
40+
41+
const c3 = "$c";
42+
// ^^
1843
// [analyzer] unspecified
1944
// [cfe] unspecified
2045

2146
main() {
22-
print(l);
47+
print(c1);
48+
print(c2);
49+
print(c3);
2350
}

Language/Expressions/Constants/literal_string_t03.dart

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,24 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
/// @assertion A constant expression is an expression whose value can never
6-
/// change, and that can be evaluated entirely at compile time.
7-
/// A constant expression is one of the following:
8-
/// . . .
9-
/// • A literal string where any interpolated expression is a compile-time
10-
/// constant that evaluates to a numeric, string or boolean value or to null.
5+
/// @assertion All usages of ’constant’ in Dart are associated with compile time.
6+
/// A potentially constant expression is an expression that will generally yield
7+
/// a constant value when the values of certain parameters are given. The
8+
/// constant expressions is a subset of the potentially constant expressions
9+
/// that can be evaluated at compile time.
10+
///
11+
/// The potentially constant expressions and constant expressions are the
12+
/// following:
13+
/// ...
14+
/// • A literal string with string interpolations with expressions `e1, ..., en`
15+
/// is a potentially constant expression if `e1, ..., en` are potentially
16+
/// constant expressions. The literal is further a constant expression if
17+
/// `e1, . . . , en` are constant expressions evaluating to instances of `int`,
18+
/// `double`, `String`, `bool`, or `Null`.
19+
///
1120
/// @description Checks that a string literal that involves string interpolation,
12-
/// that evaluates to a numeric value, but not a constant expression,
13-
/// cannot be assigned to a constant variable.
21+
/// that evaluates to a numeric value, but not a constant expression, cannot be
22+
/// assigned to a constant variable.
1423
/// @author msyabro
1524
1625
foo() => 1;

Language/Expressions/Constants/literal_string_t04.dart

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,21 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
/// @assertion A constant expression is an expression whose value can never
6-
/// change, and that can be evaluated entirely at compile time.
7-
/// A constant expression is one of the following:
8-
/// . . .
9-
/// • A literal string where any interpolated expression is a compile-time
10-
/// constant that evaluates to a numeric, string or boolean value or to null.
5+
/// @assertion All usages of ’constant’ in Dart are associated with compile time.
6+
/// A potentially constant expression is an expression that will generally yield
7+
/// a constant value when the values of certain parameters are given. The
8+
/// constant expressions is a subset of the potentially constant expressions
9+
/// that can be evaluated at compile time.
10+
///
11+
/// The potentially constant expressions and constant expressions are the
12+
/// following:
13+
/// ...
14+
/// • A literal string with string interpolations with expressions `e1, ..., en`
15+
/// is a potentially constant expression if `e1, ..., en` are potentially
16+
/// constant expressions. The literal is further a constant expression if
17+
/// `e1, . . . , en` are constant expressions evaluating to instances of `int`,
18+
/// `double`, `String`, `bool`, or `Null`.
19+
///
1120
/// @description Checks that a string literal that involves string interpolation,
1221
/// that evaluates to a bool value and is a constant expression can be assigned
1322
/// to a constant variable.

Language/Expressions/Constants/literal_string_t05.dart

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,21 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
/// @assertion A constant expression is an expression whose value can never
6-
/// change, and that can be evaluated entirely at compile time.
7-
/// A constant expression is one of the following:
8-
/// . . .
9-
/// • A literal string where any interpolated expression is a compile-time
10-
/// constant that evaluates to a numeric, string or boolean value or to null.
5+
/// @assertion All usages of ’constant’ in Dart are associated with compile time.
6+
/// A potentially constant expression is an expression that will generally yield
7+
/// a constant value when the values of certain parameters are given. The
8+
/// constant expressions is a subset of the potentially constant expressions
9+
/// that can be evaluated at compile time.
10+
///
11+
/// The potentially constant expressions and constant expressions are the
12+
/// following:
13+
/// ...
14+
/// • A literal string with string interpolations with expressions `e1, ..., en`
15+
/// is a potentially constant expression if `e1, ..., en` are potentially
16+
/// constant expressions. The literal is further a constant expression if
17+
/// `e1, . . . , en` are constant expressions evaluating to instances of `int`,
18+
/// `double`, `String`, `bool`, or `Null`.
19+
///
1120
/// @description Checks that a string literal that involves string interpolation,
1221
/// that evaluates to a string value, but not a constant expression, cannot be
1322
/// assigned to a constant variable.

Language/Expressions/Constants/literal_symbol_t01.dart

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,25 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
/// @assertion A constant expression is an expression whose value can never
6-
/// change, and that can be evaluated entirely at compile time.
7-
/// A constant expression is one of the following:
8-
/// . . .
9-
/// • A literal symbol.
5+
/// @assertion All usages of ’constant’ in Dart are associated with compile time.
6+
/// A potentially constant expression is an expression that will generally yield
7+
/// a constant value when the values of certain parameters are given. The
8+
/// constant expressions is a subset of the potentially constant expressions
9+
/// that can be evaluated at compile time.
10+
///
11+
/// The potentially constant expressions and constant expressions are the
12+
/// following:
13+
/// ...
14+
/// • A literal symbol is a potentially constant and constant expression.
15+
///
1016
/// @description Checks that literal symbol can be assigned to a constant
1117
/// variable.
1218
/// @author ilya
1319
14-
const i1 = #foo;
20+
import "../../../Utils/expect.dart";
21+
22+
const c = #foo;
1523

1624
main() {
17-
i1;
25+
Expect.identical(c, #foo);
1826
}

0 commit comments

Comments
 (0)