Skip to content

Commit dfad9f3

Browse files
DanTupCommit Queue
authored andcommitted
[analysis_server] Update element visitor tests not require useLineEndingsForPlatform=false
See #60234 Change-Id: Idaf96d95f0e694366cfff30dbc62f86eaca0bc72 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/441802 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Auto-Submit: Danny Tuppeny <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]>
1 parent e885432 commit dfad9f3

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

pkg/analysis_server/test/services/search/element_visitors_test.dart

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'package:analysis_server/src/services/search/element_visitors.dart';
66
import 'package:analyzer/dart/element/element.dart';
7+
import 'package:analyzer/src/test_utilities/test_code_format.dart';
78
import 'package:test/test.dart';
89
import 'package:test_reflective_loader/test_reflective_loader.dart';
910

@@ -17,53 +18,57 @@ void main() {
1718

1819
@reflectiveTest
1920
class FindElementByNameOffsetTest extends AbstractSingleUnitTest {
21+
late TestCode code;
22+
23+
late List<int> offsets = code.positions.map((p) => p.offset).toList();
24+
2025
LibraryFragment get testUnitFragment => testUnit.declaredFragment!;
2126

2227
@override
23-
void setUp() {
24-
useLineEndingsForPlatform = false;
25-
super.setUp();
28+
Future<void> resolveTestCode(String content) {
29+
code = TestCode.parse(normalizeSource(content));
30+
return super.resolveTestCode(code.code);
2631
}
2732

2833
Future<void> test_class() async {
2934
await resolveTestCode(r'''
30-
class AAA {}
31-
class BBB {}
35+
class /*0*/AAA {}
36+
class /*1*/BBB {}
3237
''');
33-
_assertElement(6, ElementKind.CLASS, 'AAA');
34-
_assertElement(19, ElementKind.CLASS, 'BBB');
38+
_assertElement(offsets[0], ElementKind.CLASS, 'AAA');
39+
_assertElement(offsets[1], ElementKind.CLASS, 'BBB');
3540
}
3641

3742
Future<void> test_function() async {
3843
await resolveTestCode(r'''
39-
void aaa() {}
40-
void bbb() {}
44+
void /*0*/aaa() {}
45+
void /*1*/bbb() {}
4146
''');
42-
_assertElement(5, ElementKind.FUNCTION, 'aaa');
43-
_assertElement(19, ElementKind.FUNCTION, 'bbb');
47+
_assertElement(offsets[0], ElementKind.FUNCTION, 'aaa');
48+
_assertElement(offsets[1], ElementKind.FUNCTION, 'bbb');
4449
}
4550

4651
Future<void> test_null() async {
4752
await resolveTestCode(r'''
48-
class AAA {}
53+
/*0*/c/*1*/lass/*2*/ A/*3*/AA {}
4954
class BBB {}
5055
''');
5156

52-
expect(findFragmentByNameOffset(testUnitFragment, 0), isNull);
53-
expect(findFragmentByNameOffset(testUnitFragment, 1), isNull);
57+
expect(findFragmentByNameOffset(testUnitFragment, offsets[0]), isNull);
58+
expect(findFragmentByNameOffset(testUnitFragment, offsets[1]), isNull);
5459

55-
expect(findFragmentByNameOffset(testUnitFragment, 5), isNull);
56-
expect(findFragmentByNameOffset(testUnitFragment, 7), isNull);
60+
expect(findFragmentByNameOffset(testUnitFragment, offsets[2]), isNull);
61+
expect(findFragmentByNameOffset(testUnitFragment, offsets[3]), isNull);
5762
}
5863

5964
Future<void> test_topLevelVariable() async {
6065
await resolveTestCode(r'''
61-
int? aaa, bbb;
62-
int? ccc;
66+
int? /*0*/aaa, /*1*/bbb;
67+
int? /*2*/ccc;
6368
''');
64-
_assertElement(5, ElementKind.TOP_LEVEL_VARIABLE, 'aaa');
65-
_assertElement(10, ElementKind.TOP_LEVEL_VARIABLE, 'bbb');
66-
_assertElement(20, ElementKind.TOP_LEVEL_VARIABLE, 'ccc');
69+
_assertElement(offsets[0], ElementKind.TOP_LEVEL_VARIABLE, 'aaa');
70+
_assertElement(offsets[1], ElementKind.TOP_LEVEL_VARIABLE, 'bbb');
71+
_assertElement(offsets[2], ElementKind.TOP_LEVEL_VARIABLE, 'ccc');
6772
}
6873

6974
void _assertElement(int nameOffset, ElementKind kind, String name) {

pkg/analysis_server/test/src/services/correction/fix/add_reopen_test.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ class AddReopenBulkTest extends BulkFixProcessorTest {
2222
String get lintCode => LintNames.implicit_reopen;
2323

2424
Future<void> test_singleFile() async {
25-
useLineEndingsForPlatform = false;
26-
2725
await resolveTestCode('''
2826
final class F {}
2927
sealed class S extends F {}

0 commit comments

Comments
 (0)