Skip to content

Commit

Permalink
Unit test generic annotation functionality of AstCloner.
Browse files Browse the repository at this point in the history
The update to AstCloner was made as part of
ba5064f, but it couldn't be unit
tested until now due to the lack of parser support.

Bug: #44838
Change-Id: If2fd5ce41a46c3460b5f90ba854f22ae1baef11c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/182840
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
  • Loading branch information
stereotype441 authored and commit-bot@chromium.org committed Feb 5, 2021
1 parent 6b79335 commit d5fc9fb
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions pkg/analyzer/test/generated/utilities_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ class AstClonerTest {
_assertCloneUnitMember('@A.c() main() {}');
}

void test_visitAnnotation_constructor_generic() {
_assertCloneUnitMember('@A<int>.c() main() {}',
featureSet: FeatureSet.forTesting(
sdkVersion: '2.12',
additionalFeatures: [Feature.generic_metadata]));
}

void test_visitAnnotation_withComment() {
CompilationUnitMember clazz =
_parseUnitMember('/** comment */ @deprecated class A {}');
Expand Down Expand Up @@ -1160,8 +1167,8 @@ library l;''');
_assertClone(node);
}

void _assertCloneUnitMember(String code) {
AstNode node = _parseUnitMember(code);
void _assertCloneUnitMember(String code, {FeatureSet? featureSet}) {
AstNode node = _parseUnitMember(code, featureSet: featureSet);
_assertClone(node);
}

Expand All @@ -1178,10 +1185,10 @@ library l;''');
return body.block.statements.single;
}

CompilationUnit _parseUnit(String code) {
CompilationUnit _parseUnit(String code, {FeatureSet? featureSet}) {
GatheringErrorListener listener = GatheringErrorListener();
CharSequenceReader reader = CharSequenceReader(code);
var featureSet = FeatureSet.forTesting(sdkVersion: '2.2.2');
featureSet ??= FeatureSet.forTesting(sdkVersion: '2.2.2');
Scanner scanner = Scanner(TestSource(), reader, listener)
..configureFeatures(
featureSetForOverriding: featureSet,
Expand All @@ -1199,8 +1206,9 @@ library l;''');
return unit;
}

CompilationUnitMember _parseUnitMember(String code) {
CompilationUnit unit = _parseUnit(code);
CompilationUnitMember _parseUnitMember(String code,
{FeatureSet? featureSet}) {
CompilationUnit unit = _parseUnit(code, featureSet: featureSet);
return unit.declarations.single;
}

Expand Down

0 comments on commit d5fc9fb

Please sign in to comment.