Skip to content

Commit

Permalink
dart-lang#2559. Fix metadata tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed Dec 17, 2024
1 parent 3e8abbe commit 8f491e7
Show file tree
Hide file tree
Showing 20 changed files with 142 additions and 65 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion A compile-time error occurs if a declaration with the basename
/// `augmented` occurs in a location where any enclosing declaration is
/// augmenting.
///
/// @description Checks that it is not an error to use metadata named
/// `augmented` on class-like augmenting declaration.
/// @author [email protected]
// SharedOptions=--enable-experiment=macros

const augmented = 0;

@augmented
class C {}

@augmented
augment class C {}

@augmented
mixin M {}

@augmented
augment mixin M {}

@augmented
enum E {
e0;
}

@augmented
augment enum E {
e1;
}

class A {}

@augmented
extension Ext on A {}

@augmented
augment extension Ext {}

@augmented
extension type ET(int _) {}

@augmented
augment extension type ET {}

main() {
print(C);
print(M);
print(E);
print(A);
print(ET);
}
4 changes: 2 additions & 2 deletions LanguageFeatures/Augmentation-libraries/metadata_A01_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ main() {
var symbol = MirrorSystem .getSymbol("topLevelVariable");
DeclarationMirror varMirror =
libraryMirror.declarations[symbol] as DeclarationMirror;
Expect.equals('.Meta',
Expect.equals('metadata_A01_t01.Meta',
MirrorSystem.getName(varMirror.metadata[0].type.qualifiedName));

testType(C);
Expand All @@ -75,7 +75,7 @@ void testType(Type t) {
Symbol symbol = MirrorSystem .getSymbol(name);
DeclarationMirror varMirror =
classMirror.declarations[symbol] as DeclarationMirror;
Expect.equals('.Meta',
Expect.equals('metadata_A01_t01.Meta',
MirrorSystem.getName(varMirror.metadata[0].type.qualifiedName));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion /// @assertion All declarations can be augmented with metadata annotations
/// @assertion All declarations can be augmented with metadata annotations
/// and/or doc comments directly preceding an augmenting declaration.
///
/// In both cases, these should be appended to existing metadata or doc
Expand Down
26 changes: 15 additions & 11 deletions LanguageFeatures/Augmentation-libraries/metadata_A01_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class Meta2 {
const Meta2();
}

var expected = ['metadata_A01_t02.Meta1', 'metadata_A01_t02.Meta2'];

@Meta1()
String topLevelVariable = "Top-level variable";

Expand All @@ -47,6 +49,7 @@ mixin M {

enum E {
e0;

@Meta1()
static String staticVariable = "Static variable";
@Meta1()
Expand All @@ -68,13 +71,14 @@ extension type ET(int id) {
main() {
Symbol libName = MirrorSystem.getSymbol('metadata_A01_t02');
LibraryMirror libraryMirror = currentMirrorSystem().findLibrary(libName);
var symbol = MirrorSystem .getSymbol("topLevelVariable");
var symbol = MirrorSystem.getSymbol("topLevelVariable");
DeclarationMirror varMirror =
libraryMirror.declarations[symbol] as DeclarationMirror;
Expect.equals('.Meta1',
MirrorSystem.getName(varMirror.metadata[0].type.qualifiedName));
Expect.equals('.Meta2',
MirrorSystem.getName(varMirror.metadata[1].type.qualifiedName));
libraryMirror.declarations[symbol] as DeclarationMirror;
print(MirrorSystem.getName(varMirror.metadata[0].type.qualifiedName));
Expect.isTrue(expected.contains(MirrorSystem.getName(
varMirror.metadata[0].type.qualifiedName)));
Expect.isTrue(expected.contains(MirrorSystem.getName(
varMirror.metadata[1].type.qualifiedName)));

testType(C);
testType(M);
Expand All @@ -87,12 +91,12 @@ void testType(Type t) {
ClassMirror classMirror = reflectClass(t);
var varNames = ['staticVariable', 'instanceVariable'];
for (var name in varNames) {
Symbol symbol = MirrorSystem .getSymbol(name);
Symbol symbol = MirrorSystem.getSymbol(name);
DeclarationMirror varMirror =
classMirror.declarations[symbol] as DeclarationMirror;
Expect.equals('.Meta1',
MirrorSystem.getName(varMirror.metadata[0].type.qualifiedName));
Expect.equals('.Meta2',
MirrorSystem.getName(varMirror.metadata[1].type.qualifiedName));
Expect.isTrue(expected.contains(MirrorSystem.getName(
varMirror.metadata[0].type.qualifiedName)));
Expect.isTrue(expected.contains(MirrorSystem.getName(
varMirror.metadata[1].type.qualifiedName)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion /// @assertion All declarations can be augmented with metadata annotations
/// @assertion All declarations can be augmented with metadata annotations
/// and/or doc comments directly preceding an augmenting declaration.
///
/// In both cases, these should be appended to existing metadata or doc
Expand Down
4 changes: 2 additions & 2 deletions LanguageFeatures/Augmentation-libraries/metadata_A01_t03.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ main() {
var symbol = MirrorSystem .getSymbol("topLevelGetter");
DeclarationMirror varMirror =
libraryMirror.declarations[symbol] as DeclarationMirror;
Expect.equals('.Meta',
Expect.equals('metadata_A01_t03.Meta',
MirrorSystem.getName(varMirror.metadata[0].type.qualifiedName));

testType(C);
Expand All @@ -77,7 +77,7 @@ void testType(Type t) {
Symbol symbol = MirrorSystem .getSymbol(name);
DeclarationMirror varMirror =
classMirror.declarations[symbol] as DeclarationMirror;
Expect.equals('.Meta',
Expect.equals('metadata_A01_t03.Meta',
MirrorSystem.getName(varMirror.metadata[0].type.qualifiedName));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion /// @assertion All declarations can be augmented with metadata annotations
/// @assertion All declarations can be augmented with metadata annotations
/// and/or doc comments directly preceding an augmenting declaration.
///
/// In both cases, these should be appended to existing metadata or doc
Expand Down
18 changes: 10 additions & 8 deletions LanguageFeatures/Augmentation-libraries/metadata_A01_t04.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class Meta2 {
const Meta2();
}

var expected = ['metadata_A01_t04.Meta1', 'metadata_A01_t04.Meta2'];

@Meta1()
String get topLevelGetter => "Top-level getter";

Expand Down Expand Up @@ -75,10 +77,10 @@ main() {
var symbol = MirrorSystem .getSymbol("topLevelGetter");
DeclarationMirror varMirror =
libraryMirror.declarations[symbol] as DeclarationMirror;
Expect.equals('.Meta1',
MirrorSystem.getName(varMirror.metadata[0].type.qualifiedName));
Expect.equals('.Meta2',
MirrorSystem.getName(varMirror.metadata[1].type.qualifiedName));
Expect.isTrue(expected.contains(MirrorSystem.getName(
varMirror.metadata[0].type.qualifiedName)));
Expect.isTrue(expected.contains(MirrorSystem.getName(
varMirror.metadata[1].type.qualifiedName)));

testType(C);
testType(M);
Expand All @@ -94,9 +96,9 @@ void testType(Type t) {
Symbol symbol = MirrorSystem .getSymbol(name);
DeclarationMirror varMirror =
classMirror.declarations[symbol] as DeclarationMirror;
Expect.equals('.Meta1',
MirrorSystem.getName(varMirror.metadata[0].type.qualifiedName));
Expect.equals('.Meta2',
MirrorSystem.getName(varMirror.metadata[1].type.qualifiedName));
Expect.isTrue(expected.contains(
MirrorSystem.getName(varMirror.metadata[0].type.qualifiedName)));
Expect.isTrue(expected.contains(
MirrorSystem.getName(varMirror.metadata[1].type.qualifiedName)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion /// @assertion All declarations can be augmented with metadata annotations
/// @assertion All declarations can be augmented with metadata annotations
/// and/or doc comments directly preceding an augmenting declaration.
///
/// In both cases, these should be appended to existing metadata or doc
Expand Down
4 changes: 2 additions & 2 deletions LanguageFeatures/Augmentation-libraries/metadata_A01_t05.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ main() {
var symbol = MirrorSystem .getSymbol("topLevelSetter=");
DeclarationMirror varMirror =
libraryMirror.declarations[symbol] as DeclarationMirror;
Expect.equals('.Meta',
Expect.equals('metadata_A01_t05.Meta',
MirrorSystem.getName(varMirror.metadata[0].type.qualifiedName));

testType(C);
Expand All @@ -77,7 +77,7 @@ void testType(Type t) {
Symbol symbol = MirrorSystem .getSymbol(name);
DeclarationMirror varMirror =
classMirror.declarations[symbol] as DeclarationMirror;
Expect.equals('.Meta',
Expect.equals('metadata_A01_t05.Meta',
MirrorSystem.getName(varMirror.metadata[0].type.qualifiedName));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion /// @assertion All declarations can be augmented with metadata annotations
/// @assertion All declarations can be augmented with metadata annotations
/// and/or doc comments directly preceding an augmenting declaration.
///
/// In both cases, these should be appended to existing metadata or doc
Expand Down
18 changes: 10 additions & 8 deletions LanguageFeatures/Augmentation-libraries/metadata_A01_t06.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class Meta2 {
const Meta2();
}

var expected = ['metadata_A01_t06.Meta1', 'metadata_A01_t06.Meta2'];

@Meta1()
void set topLevelSetter(String _) {}

Expand Down Expand Up @@ -75,10 +77,10 @@ main() {
var symbol = MirrorSystem .getSymbol("topLevelSetter=");
DeclarationMirror varMirror =
libraryMirror.declarations[symbol] as DeclarationMirror;
Expect.equals('.Meta1',
MirrorSystem.getName(varMirror.metadata[0].type.qualifiedName));
Expect.equals('.Meta2',
MirrorSystem.getName(varMirror.metadata[1].type.qualifiedName));
Expect.isTrue(expected.contains(MirrorSystem.getName(
varMirror.metadata[0].type.qualifiedName)));
Expect.isTrue(expected.contains(MirrorSystem.getName(
varMirror.metadata[1].type.qualifiedName)));

testType(C);
testType(M);
Expand All @@ -94,9 +96,9 @@ void testType(Type t) {
Symbol symbol = MirrorSystem .getSymbol(name);
DeclarationMirror varMirror =
classMirror.declarations[symbol] as DeclarationMirror;
Expect.equals('.Meta1',
MirrorSystem.getName(varMirror.metadata[0].type.qualifiedName));
Expect.equals('.Meta2',
MirrorSystem.getName(varMirror.metadata[0].type.qualifiedName));
Expect.isTrue(expected.contains(MirrorSystem.getName(
varMirror.metadata[0].type.qualifiedName)));
Expect.isTrue(expected.contains(MirrorSystem.getName(
varMirror.metadata[1].type.qualifiedName)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion /// @assertion All declarations can be augmented with metadata annotations
/// @assertion All declarations can be augmented with metadata annotations
/// and/or doc comments directly preceding an augmenting declaration.
///
/// In both cases, these should be appended to existing metadata or doc
Expand Down
4 changes: 2 additions & 2 deletions LanguageFeatures/Augmentation-libraries/metadata_A01_t07.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ main() {
var symbol = MirrorSystem .getSymbol("topLevelFunction");
DeclarationMirror varMirror =
libraryMirror.declarations[symbol] as DeclarationMirror;
Expect.equals('.Meta',
Expect.equals('metadata_A01_t07.Meta',
MirrorSystem.getName(varMirror.metadata[0].type.qualifiedName));

testType(C);
Expand All @@ -77,7 +77,7 @@ void testType(Type t) {
Symbol symbol = MirrorSystem .getSymbol(name);
DeclarationMirror varMirror =
classMirror.declarations[symbol] as DeclarationMirror;
Expect.equals('.Meta',
Expect.equals('metadata_A01_t07.Meta',
MirrorSystem.getName(varMirror.metadata[0].type.qualifiedName));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion /// @assertion All declarations can be augmented with metadata annotations
/// @assertion All declarations can be augmented with metadata annotations
/// and/or doc comments directly preceding an augmenting declaration.
///
/// In both cases, these should be appended to existing metadata or doc
Expand Down
16 changes: 11 additions & 5 deletions LanguageFeatures/Augmentation-libraries/metadata_A01_t08.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class Meta2 {
const Meta2();
}

var expected = ['metadata_A01_t08.Meta1', 'metadata_A01_t08.Meta2'];

@Meta1()
void topLevelFunction() {}

Expand Down Expand Up @@ -70,13 +72,15 @@ extension type ET(int id) {
}

main() {
Symbol libName = MirrorSystem.getSymbol('metadata_A01_t07');
Symbol libName = MirrorSystem.getSymbol('metadata_A01_t08');
LibraryMirror libraryMirror = currentMirrorSystem().findLibrary(libName);
var symbol = MirrorSystem .getSymbol("topLevelFunction");
DeclarationMirror varMirror =
libraryMirror.declarations[symbol] as DeclarationMirror;
Expect.equals('.Meta',
MirrorSystem.getName(varMirror.metadata[0].type.qualifiedName));
Expect.isTrue(expected.contains(MirrorSystem.getName(
varMirror.metadata[0].type.qualifiedName)));
Expect.isTrue(expected.contains(MirrorSystem.getName(
varMirror.metadata[1].type.qualifiedName)));

testType(C);
testType(M);
Expand All @@ -92,7 +96,9 @@ void testType(Type t) {
Symbol symbol = MirrorSystem .getSymbol(name);
DeclarationMirror varMirror =
classMirror.declarations[symbol] as DeclarationMirror;
Expect.equals('.Meta',
MirrorSystem.getName(varMirror.metadata[0].type.qualifiedName));
Expect.isTrue(expected.contains(MirrorSystem.getName(
varMirror.metadata[0].type.qualifiedName)));
Expect.isTrue(expected.contains(MirrorSystem.getName(
varMirror.metadata[1].type.qualifiedName)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion /// @assertion All declarations can be augmented with metadata annotations
/// @assertion All declarations can be augmented with metadata annotations
/// and/or doc comments directly preceding an augmenting declaration.
///
/// In both cases, these should be appended to existing metadata or doc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion /// @assertion All declarations can be augmented with metadata annotations
/// @assertion All declarations can be augmented with metadata annotations
/// and/or doc comments directly preceding an augmenting declaration.
///
/// In both cases, these should be appended to existing metadata or doc
Expand Down
Loading

0 comments on commit 8f491e7

Please sign in to comment.