Skip to content

Commit 39f39c0

Browse files
srawlinscommit-bot@chromium.org
authored andcommitted
analyzer: move tests for 4 codes to diagnostics/
Change-Id: Ida28ae6ef39314b724932c5ae1a9a3aa4a72a17f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/154220 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent d6dfbda commit 39f39c0

6 files changed

+235
-145
lines changed

pkg/analyzer/test/generated/compile_time_error_code.dart

Lines changed: 0 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -138,151 +138,6 @@ const C = 1 ~/ 0;
138138
await _check_constEvalTypeNum_binary("a % ''");
139139
}
140140

141-
test_constFormalParameter_fieldFormalParameter() async {
142-
await assertErrorsInCode(r'''
143-
class A {
144-
var x;
145-
A(const this.x) {}
146-
}
147-
''', [
148-
error(CompileTimeErrorCode.CONST_FORMAL_PARAMETER, 23, 12),
149-
error(ParserErrorCode.EXTRANEOUS_MODIFIER, 23, 5),
150-
]);
151-
}
152-
153-
test_constFormalParameter_simpleFormalParameter() async {
154-
await assertErrorsInCode('''
155-
f(const x) {}
156-
''', [
157-
error(CompileTimeErrorCode.CONST_FORMAL_PARAMETER, 2, 7),
158-
error(ParserErrorCode.EXTRANEOUS_MODIFIER, 2, 5),
159-
]);
160-
}
161-
162-
test_constInitializedWithNonConstValueFromDeferredClass() async {
163-
newFile('/test/lib/lib1.dart', content: '''
164-
library lib1;
165-
const V = 1;
166-
''');
167-
await assertErrorsInCode('''
168-
library root;
169-
import 'lib1.dart' deferred as a;
170-
const B = a.V;
171-
''', [
172-
error(
173-
CompileTimeErrorCode
174-
.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE_FROM_DEFERRED_LIBRARY,
175-
58,
176-
3),
177-
]);
178-
}
179-
180-
test_constInitializedWithNonConstValueFromDeferredClass_nested() async {
181-
newFile('/test/lib/lib1.dart', content: '''
182-
library lib1;
183-
const V = 1;
184-
''');
185-
await assertErrorsInCode('''
186-
library root;
187-
import 'lib1.dart' deferred as a;
188-
const B = a.V + 1;
189-
''', [
190-
error(
191-
CompileTimeErrorCode
192-
.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE_FROM_DEFERRED_LIBRARY,
193-
58,
194-
7),
195-
]);
196-
}
197-
198-
test_constInstanceField() async {
199-
await assertErrorsInCode(r'''
200-
class C {
201-
const int f = 0;
202-
}
203-
''', [
204-
error(CompileTimeErrorCode.CONST_INSTANCE_FIELD, 12, 5),
205-
]);
206-
}
207-
208-
test_constWithNonConst() async {
209-
await assertErrorsInCode(r'''
210-
class T {
211-
T(a, b, {c, d}) {}
212-
}
213-
f() { return const T(0, 1, c: 2, d: 3); }
214-
''', [
215-
error(CompileTimeErrorCode.CONST_WITH_NON_CONST, 46, 5),
216-
]);
217-
}
218-
219-
test_constWithNonConst_in_const_context() async {
220-
await assertErrorsInCode(r'''
221-
class A {
222-
const A(x);
223-
}
224-
class B {
225-
}
226-
main() {
227-
const A(B());
228-
}
229-
''', [
230-
error(CompileTimeErrorCode.CONST_WITH_NON_CONST, 57, 3),
231-
]);
232-
}
233-
234-
test_constWithNonConst_mixinApplication_constSuperConstructor() async {
235-
await assertNoErrorsInCode(r'''
236-
mixin M {}
237-
class A {
238-
const A();
239-
}
240-
class B = A with M;
241-
const b = const B();
242-
''');
243-
}
244-
245-
test_constWithNonConst_mixinApplication_constSuperConstructor_field() async {
246-
await assertErrorsInCode(r'''
247-
mixin M {
248-
int i = 0;
249-
}
250-
class A {
251-
const A();
252-
}
253-
class B = A with M;
254-
var b = const B();
255-
''', [
256-
error(CompileTimeErrorCode.CONST_WITH_NON_CONST, 78, 5),
257-
]);
258-
}
259-
260-
test_constWithNonConst_mixinApplication_constSuperConstructor_getter() async {
261-
await assertNoErrorsInCode(r'''
262-
mixin M {
263-
int get i => 0;
264-
}
265-
class A {
266-
const A();
267-
}
268-
class B = A with M;
269-
var b = const B();
270-
''');
271-
}
272-
273-
test_constWithNonConst_mixinApplication_constSuperConstructor_setter() async {
274-
await assertNoErrorsInCode(r'''
275-
mixin M {
276-
set(int i) {}
277-
}
278-
class A {
279-
const A();
280-
}
281-
class B = A with M;
282-
var b = const B();
283-
''');
284-
}
285-
286141
test_constWithNonConstantArgument_annotation() async {
287142
await assertErrorsInCode(r'''
288143
class A {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer/src/error/codes.dart';
6+
import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode;
7+
import 'package:test_reflective_loader/test_reflective_loader.dart';
8+
9+
import '../dart/resolution/driver_resolution.dart';
10+
11+
main() {
12+
defineReflectiveSuite(() {
13+
defineReflectiveTests(ConstFormalParameterTest);
14+
});
15+
}
16+
17+
@reflectiveTest
18+
class ConstFormalParameterTest extends DriverResolutionTest {
19+
test_fieldFormalParameter() async {
20+
await assertErrorsInCode(r'''
21+
class A {
22+
var x;
23+
A(const this.x) {}
24+
}
25+
''', [
26+
error(CompileTimeErrorCode.CONST_FORMAL_PARAMETER, 23, 12),
27+
error(ParserErrorCode.EXTRANEOUS_MODIFIER, 23, 5),
28+
]);
29+
}
30+
31+
test_simpleFormalParameter() async {
32+
await assertErrorsInCode('''
33+
f(const x) {}
34+
''', [
35+
error(CompileTimeErrorCode.CONST_FORMAL_PARAMETER, 2, 7),
36+
error(ParserErrorCode.EXTRANEOUS_MODIFIER, 2, 5),
37+
]);
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer/src/error/codes.dart';
6+
import 'package:test_reflective_loader/test_reflective_loader.dart';
7+
8+
import '../dart/resolution/driver_resolution.dart';
9+
10+
main() {
11+
defineReflectiveSuite(() {
12+
defineReflectiveTests(
13+
ConstInitializedWithNonConstantValueFromDeferredLibraryTest);
14+
});
15+
}
16+
17+
@reflectiveTest
18+
class ConstInitializedWithNonConstantValueFromDeferredLibraryTest
19+
extends DriverResolutionTest {
20+
test_deferred() async {
21+
newFile('/test/lib/lib1.dart', content: '''
22+
library lib1;
23+
const V = 1;
24+
''');
25+
await assertErrorsInCode('''
26+
library root;
27+
import 'lib1.dart' deferred as a;
28+
const B = a.V;
29+
''', [
30+
error(
31+
CompileTimeErrorCode
32+
.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE_FROM_DEFERRED_LIBRARY,
33+
58,
34+
3),
35+
]);
36+
}
37+
38+
test_nested() async {
39+
newFile('/test/lib/lib1.dart', content: '''
40+
library lib1;
41+
const V = 1;
42+
''');
43+
await assertErrorsInCode('''
44+
library root;
45+
import 'lib1.dart' deferred as a;
46+
const B = a.V + 1;
47+
''', [
48+
error(
49+
CompileTimeErrorCode
50+
.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE_FROM_DEFERRED_LIBRARY,
51+
58,
52+
7),
53+
]);
54+
}
55+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer/src/error/codes.dart';
6+
import 'package:test_reflective_loader/test_reflective_loader.dart';
7+
8+
import '../dart/resolution/driver_resolution.dart';
9+
10+
main() {
11+
defineReflectiveSuite(() {
12+
defineReflectiveTests(ConstInstanceFieldTest);
13+
});
14+
}
15+
16+
@reflectiveTest
17+
class ConstInstanceFieldTest extends DriverResolutionTest {
18+
test_class() async {
19+
await assertErrorsInCode(r'''
20+
class C {
21+
const int f = 0;
22+
}
23+
''', [
24+
error(CompileTimeErrorCode.CONST_INSTANCE_FIELD, 12, 5),
25+
]);
26+
}
27+
28+
test_mixin() async {
29+
await assertErrorsInCode(r'''
30+
mixin C {
31+
const int f = 0;
32+
}
33+
''', [
34+
error(CompileTimeErrorCode.CONST_INSTANCE_FIELD, 12, 5),
35+
]);
36+
}
37+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer/src/error/codes.dart';
6+
import 'package:test_reflective_loader/test_reflective_loader.dart';
7+
8+
import '../dart/resolution/driver_resolution.dart';
9+
10+
main() {
11+
defineReflectiveSuite(() {
12+
defineReflectiveTests(ConstWithNonConstTest);
13+
});
14+
}
15+
16+
@reflectiveTest
17+
class ConstWithNonConstTest extends DriverResolutionTest {
18+
test_inConstContext() async {
19+
await assertErrorsInCode(r'''
20+
class A {
21+
const A(x);
22+
}
23+
class B {
24+
}
25+
main() {
26+
const A(B());
27+
}
28+
''', [
29+
error(CompileTimeErrorCode.CONST_WITH_NON_CONST, 57, 3),
30+
]);
31+
}
32+
33+
test_mixinApplication_constSuperConstructor() async {
34+
await assertNoErrorsInCode(r'''
35+
mixin M {}
36+
class A {
37+
const A();
38+
}
39+
class B = A with M;
40+
const b = const B();
41+
''');
42+
}
43+
44+
test_mixinApplication_constSuperConstructor_field() async {
45+
await assertErrorsInCode(r'''
46+
mixin M {
47+
int i = 0;
48+
}
49+
class A {
50+
const A();
51+
}
52+
class B = A with M;
53+
var b = const B();
54+
''', [
55+
error(CompileTimeErrorCode.CONST_WITH_NON_CONST, 78, 5),
56+
]);
57+
}
58+
59+
test_mixinApplication_constSuperConstructor_getter() async {
60+
await assertNoErrorsInCode(r'''
61+
mixin M {
62+
int get i => 0;
63+
}
64+
class A {
65+
const A();
66+
}
67+
class B = A with M;
68+
var b = const B();
69+
''');
70+
}
71+
72+
test_mixinApplication_constSuperConstructor_setter() async {
73+
await assertNoErrorsInCode(r'''
74+
mixin M {
75+
set(int i) {}
76+
}
77+
class A {
78+
const A();
79+
}
80+
class B = A with M;
81+
var b = const B();
82+
''');
83+
}
84+
85+
test_nonConst() async {
86+
await assertErrorsInCode(r'''
87+
class T {
88+
T(a, b, {c, d}) {}
89+
}
90+
f() { return const T(0, 1, c: 2, d: 3); }
91+
''', [
92+
error(CompileTimeErrorCode.CONST_WITH_NON_CONST, 46, 5),
93+
]);
94+
}
95+
}

0 commit comments

Comments
 (0)