Skip to content

Commit f2c7a35

Browse files
srawlinscommit-bot@chromium.org
authored andcommitted
analyzer: Migrate four tests to use null safety; tidy up constant/evaluation_test
Bug: #44666 Change-Id: Ic21b1f7ad03cf2049d1db672aa9e314da3dd3a49 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/186121 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 5d99c6b commit f2c7a35

File tree

4 files changed

+127
-163
lines changed

4 files changed

+127
-163
lines changed

pkg/analyzer/test/src/dart/constant/evaluation_test.dart

+124-151
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import 'package:analyzer/dart/analysis/features.dart';
66
import 'package:analyzer/error/error.dart';
77
import 'package:analyzer/error/listener.dart';
8-
import 'package:analyzer/src/dart/analysis/experiments.dart';
98
import 'package:analyzer/src/dart/element/element.dart';
109
import 'package:analyzer/src/error/codes.dart';
1110
import 'package:analyzer/src/generated/constant.dart';
@@ -18,14 +17,126 @@ import '../resolution/context_collection_resolution.dart';
1817
main() {
1918
defineReflectiveSuite(() {
2019
defineReflectiveTests(ConstantVisitorTest);
21-
defineReflectiveTests(ConstantVisitorWithNullSafetyWithTripleShiftTest);
22-
defineReflectiveTests(ConstantVisitorWithNullSafetyTest);
20+
defineReflectiveTests(ConstantVisitorWithoutNullSafetyTest);
2321
});
2422
}
2523

2624
@reflectiveTest
2725
class ConstantVisitorTest extends ConstantVisitorTestSupport
28-
with ConstantVisitorTestCases {}
26+
with ConstantVisitorTestCases {
27+
test_visitAsExpression_potentialConstType() async {
28+
await assertNoErrorsInCode('''
29+
const num three = 3;
30+
31+
class C<T extends num> {
32+
final T w;
33+
const C() : w = three as T;
34+
}
35+
36+
void main() {
37+
const C<int>().w;
38+
}
39+
''');
40+
}
41+
42+
test_visitBinaryExpression_gtGtGt_negative_fewerBits() async {
43+
await resolveTestCode('''
44+
const c = 0xFFFFFFFF >>> 8;
45+
''');
46+
DartObjectImpl result = _evaluateConstant('c');
47+
expect(result.type, typeProvider.intType);
48+
expect(result.toIntValue(), 0xFFFFFF);
49+
}
50+
51+
test_visitBinaryExpression_gtGtGt_negative_moreBits() async {
52+
await resolveTestCode('''
53+
const c = 0xFFFFFFFF >>> 33;
54+
''');
55+
DartObjectImpl result = _evaluateConstant('c');
56+
expect(result.type, typeProvider.intType);
57+
expect(result.toIntValue(), 0);
58+
}
59+
60+
test_visitBinaryExpression_gtGtGt_negative_moreThan64Bits() async {
61+
await resolveTestCode('''
62+
const c = 0xFFFFFFFF >>> 65;
63+
''');
64+
DartObjectImpl result = _evaluateConstant('c');
65+
expect(result.type, typeProvider.intType);
66+
expect(result.toIntValue(), 0);
67+
}
68+
69+
test_visitBinaryExpression_gtGtGt_negative_negativeBits() async {
70+
await resolveTestCode('''
71+
const c = 0xFFFFFFFF >>> -2;
72+
''');
73+
_evaluateConstantOrNull('c',
74+
errorCodes: [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]);
75+
}
76+
77+
test_visitBinaryExpression_gtGtGt_negative_zeroBits() async {
78+
await resolveTestCode('''
79+
const c = 0xFFFFFFFF >>> 0;
80+
''');
81+
DartObjectImpl result = _evaluateConstant('c');
82+
expect(result.type, typeProvider.intType);
83+
expect(result.toIntValue(), 0xFFFFFFFF);
84+
}
85+
86+
test_visitBinaryExpression_gtGtGt_positive_fewerBits() async {
87+
await resolveTestCode('''
88+
const c = 0xFF >>> 3;
89+
''');
90+
DartObjectImpl result = _evaluateConstant('c');
91+
expect(result.type, typeProvider.intType);
92+
expect(result.toIntValue(), 0x1F);
93+
}
94+
95+
test_visitBinaryExpression_gtGtGt_positive_moreBits() async {
96+
await resolveTestCode('''
97+
const c = 0xFF >>> 9;
98+
''');
99+
DartObjectImpl result = _evaluateConstant('c');
100+
expect(result.type, typeProvider.intType);
101+
expect(result.toIntValue(), 0);
102+
}
103+
104+
test_visitBinaryExpression_gtGtGt_positive_moreThan64Bits() async {
105+
await resolveTestCode('''
106+
const c = 0xFF >>> 65;
107+
''');
108+
DartObjectImpl result = _evaluateConstant('c');
109+
expect(result.type, typeProvider.intType);
110+
expect(result.toIntValue(), 0);
111+
}
112+
113+
test_visitBinaryExpression_gtGtGt_positive_negativeBits() async {
114+
await resolveTestCode('''
115+
const c = 0xFF >>> -2;
116+
''');
117+
_evaluateConstantOrNull('c',
118+
errorCodes: [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]);
119+
}
120+
121+
test_visitBinaryExpression_gtGtGt_positive_zeroBits() async {
122+
await resolveTestCode('''
123+
const c = 0xFF >>> 0;
124+
''');
125+
DartObjectImpl result = _evaluateConstant('c');
126+
expect(result.type, typeProvider.intType);
127+
expect(result.toIntValue(), 0xFF);
128+
}
129+
130+
test_visitSimpleIdentifier_className() async {
131+
await resolveTestCode('''
132+
const a = C;
133+
class C {}
134+
''');
135+
DartObjectImpl result = _evaluateConstant('a');
136+
expect(result.type, typeProvider.typeType);
137+
assertType(result.toTypeValue(), 'C*');
138+
}
139+
}
29140

30141
@reflectiveTest
31142
mixin ConstantVisitorTestCases on ConstantVisitorTestSupport {
@@ -281,16 +392,6 @@ class B {
281392
expect(result, isNull);
282393
}
283394

284-
test_visitAsExpression_null() async {
285-
await resolveTestCode('''
286-
const a = null;
287-
const b = a as A;
288-
class A {}
289-
''');
290-
DartObjectImpl result = _evaluateConstant('b');
291-
expect(result.type, typeProvider.nullType);
292-
}
293-
294395
test_visitAsExpression_potentialConst() async {
295396
await assertNoErrorsInCode('''
296397
class A {
@@ -939,16 +1040,6 @@ const b = B('');
9391040
]);
9401041
}
9411042

942-
test_visitSimpleIdentifier_className() async {
943-
await resolveTestCode('''
944-
const a = C;
945-
class C {}
946-
''');
947-
DartObjectImpl result = _evaluateConstant('a');
948-
expect(result.type, typeProvider.typeType);
949-
assertType(result.toTypeValue(), 'C');
950-
}
951-
9521043
test_visitSimpleIdentifier_dynamic() async {
9531044
await resolveTestCode('''
9541045
const a = dynamic;
@@ -1017,10 +1108,7 @@ const b = 3;''');
10171108
}
10181109
}
10191110

1020-
class ConstantVisitorTestSupport extends PubPackageResolutionTest
1021-
with WithoutNullSafetyMixin {
1022-
// TODO(https://github.com/dart-lang/sdk/issues/44666): Use null safety in
1023-
// test cases.
1111+
class ConstantVisitorTestSupport extends PubPackageResolutionTest {
10241112
DartObjectImpl _evaluateConstant(
10251113
String name, {
10261114
List<ErrorCode>? errorCodes,
@@ -1076,130 +1164,15 @@ class ConstantVisitorTestSupport extends PubPackageResolutionTest
10761164
}
10771165

10781166
@reflectiveTest
1079-
class ConstantVisitorWithNullSafetyTest extends ConstantVisitorTestSupport
1080-
with WithNullSafetyMixin {
1081-
test_visitAsExpression_potentialConstType() async {
1082-
await assertNoErrorsInCode('''
1083-
const num three = 3;
1084-
1085-
class C<T extends num> {
1086-
final T w;
1087-
const C() : w = three as T;
1088-
}
1089-
1090-
void main() {
1091-
const C<int>().w;
1092-
}
1093-
''');
1094-
}
1095-
}
1096-
1097-
@reflectiveTest
1098-
class ConstantVisitorWithNullSafetyWithTripleShiftTest
1099-
extends ConstantVisitorTestSupport {
1100-
@override
1101-
String get testPackageLanguageVersion =>
1102-
'${ExperimentStatus.currentVersion.major}.'
1103-
'${ExperimentStatus.currentVersion.minor}';
1104-
1105-
@override
1106-
void setUp() {
1107-
super.setUp();
1108-
1109-
writeTestPackageAnalysisOptionsFile(
1110-
AnalysisOptionsFileConfig(
1111-
experiments: [
1112-
EnableString.triple_shift,
1113-
],
1114-
),
1115-
);
1116-
}
1117-
1118-
test_visitBinaryExpression_gtGtGt_negative_fewerBits() async {
1119-
await resolveTestCode('''
1120-
const c = 0xFFFFFFFF >>> 8;
1121-
''');
1122-
DartObjectImpl result = _evaluateConstant('c');
1123-
expect(result.type, typeProvider.intType);
1124-
expect(result.toIntValue(), 0xFFFFFF);
1125-
}
1126-
1127-
test_visitBinaryExpression_gtGtGt_negative_moreBits() async {
1128-
await resolveTestCode('''
1129-
const c = 0xFFFFFFFF >>> 33;
1130-
''');
1131-
DartObjectImpl result = _evaluateConstant('c');
1132-
expect(result.type, typeProvider.intType);
1133-
expect(result.toIntValue(), 0);
1134-
}
1135-
1136-
test_visitBinaryExpression_gtGtGt_negative_moreThan64Bits() async {
1137-
await resolveTestCode('''
1138-
const c = 0xFFFFFFFF >>> 65;
1139-
''');
1140-
DartObjectImpl result = _evaluateConstant('c');
1141-
expect(result.type, typeProvider.intType);
1142-
expect(result.toIntValue(), 0);
1143-
}
1144-
1145-
test_visitBinaryExpression_gtGtGt_negative_negativeBits() async {
1146-
await resolveTestCode('''
1147-
const c = 0xFFFFFFFF >>> -2;
1148-
''');
1149-
_evaluateConstantOrNull('c',
1150-
errorCodes: [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]);
1151-
}
1152-
1153-
test_visitBinaryExpression_gtGtGt_negative_zeroBits() async {
1154-
await resolveTestCode('''
1155-
const c = 0xFFFFFFFF >>> 0;
1156-
''');
1157-
DartObjectImpl result = _evaluateConstant('c');
1158-
expect(result.type, typeProvider.intType);
1159-
expect(result.toIntValue(), 0xFFFFFFFF);
1160-
}
1161-
1162-
test_visitBinaryExpression_gtGtGt_positive_fewerBits() async {
1163-
await resolveTestCode('''
1164-
const c = 0xFF >>> 3;
1165-
''');
1166-
DartObjectImpl result = _evaluateConstant('c');
1167-
expect(result.type, typeProvider.intType);
1168-
expect(result.toIntValue(), 0x1F);
1169-
}
1170-
1171-
test_visitBinaryExpression_gtGtGt_positive_moreBits() async {
1172-
await resolveTestCode('''
1173-
const c = 0xFF >>> 9;
1174-
''');
1175-
DartObjectImpl result = _evaluateConstant('c');
1176-
expect(result.type, typeProvider.intType);
1177-
expect(result.toIntValue(), 0);
1178-
}
1179-
1180-
test_visitBinaryExpression_gtGtGt_positive_moreThan64Bits() async {
1181-
await resolveTestCode('''
1182-
const c = 0xFF >>> 65;
1183-
''');
1184-
DartObjectImpl result = _evaluateConstant('c');
1185-
expect(result.type, typeProvider.intType);
1186-
expect(result.toIntValue(), 0);
1187-
}
1188-
1189-
test_visitBinaryExpression_gtGtGt_positive_negativeBits() async {
1190-
await resolveTestCode('''
1191-
const c = 0xFF >>> -2;
1192-
''');
1193-
_evaluateConstantOrNull('c',
1194-
errorCodes: [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]);
1195-
}
1196-
1197-
test_visitBinaryExpression_gtGtGt_positive_zeroBits() async {
1167+
class ConstantVisitorWithoutNullSafetyTest extends ConstantVisitorTestSupport
1168+
with ConstantVisitorTestCases, WithoutNullSafetyMixin {
1169+
test_visitAsExpression_null() async {
11981170
await resolveTestCode('''
1199-
const c = 0xFF >>> 0;
1171+
const a = null;
1172+
const b = a as A;
1173+
class A {}
12001174
''');
1201-
DartObjectImpl result = _evaluateConstant('c');
1202-
expect(result.type, typeProvider.intType);
1203-
expect(result.toIntValue(), 0xFF);
1175+
DartObjectImpl result = _evaluateConstant('b');
1176+
expect(result.type, typeProvider.nullType);
12041177
}
12051178
}

pkg/analyzer/test/src/dart/resolution/export_test.dart

+1-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ main() {
1414
}
1515

1616
@reflectiveTest
17-
class ExportResolutionTest extends PubPackageResolutionTest
18-
with WithoutNullSafetyMixin {
19-
// TODO(https://github.com/dart-lang/sdk/issues/44666): Use null safety in
20-
// test cases.
17+
class ExportResolutionTest extends PubPackageResolutionTest {
2118
test_configurations_default() async {
2219
newFile('$testPackageLibPath/a.dart', content: 'class A {}');
2320
newFile('$testPackageLibPath/a_html.dart', content: 'class A {}');

pkg/analyzer/test/src/dart/resolution/import_test.dart

+1-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ main() {
1313
}
1414

1515
@reflectiveTest
16-
class ImportDirectiveResolutionTest extends PubPackageResolutionTest
17-
with WithoutNullSafetyMixin {
18-
// TODO(https://github.com/dart-lang/sdk/issues/44666): Use null safety in
19-
// test cases.
16+
class ImportDirectiveResolutionTest extends PubPackageResolutionTest {
2017
test_configurations_default() async {
2118
newFile('$testPackageLibPath/a.dart', content: 'class A {}');
2219
newFile('$testPackageLibPath/a_html.dart', content: 'class A {}');

pkg/analyzer/test/src/dart/resolution/prefix_element_test.dart

+1-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ main() {
1616
}
1717

1818
@reflectiveTest
19-
class PrefixElementTest extends PubPackageResolutionTest
20-
with WithoutNullSafetyMixin {
21-
// TODO(https://github.com/dart-lang/sdk/issues/44666): Use null safety in
22-
// test cases.
19+
class PrefixElementTest extends PubPackageResolutionTest {
2320
test_scope_lookup() async {
2421
newFile('$testPackageLibPath/a.dart', content: r'''
2522
var foo = 0;

0 commit comments

Comments
 (0)