mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 22:31:50 +00:00
Migrate language_2/metadata to NNBD.
Change-Id: I0243e6112ea3dc31e69a2c1395e08575ab5cb276 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/149561 Auto-Submit: Bob Nystrom <rnystrom@google.com> Commit-Queue: Erik Ernst <eernst@google.com> Reviewed-by: Erik Ernst <eernst@google.com>
This commit is contained in:
parent
e1ece8fcbc
commit
9d6fd6e25d
25
tests/language/metadata/cyclic_test.dart
Normal file
25
tests/language/metadata/cyclic_test.dart
Normal file
|
@ -0,0 +1,25 @@
|
|||
// Copyright (c) 2014, 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.
|
||||
|
||||
// Check that metadata on a class 'Super' using subtypes of 'Super' are not
|
||||
// considered as cyclic inheritance or lead to crashes.
|
||||
|
||||
@Sub1(0) //# 01: ok
|
||||
class Super {
|
||||
final field;
|
||||
@Sub2(1) //# 02: ok
|
||||
const Super(this.field);
|
||||
}
|
||||
|
||||
class Sub1 extends Super {
|
||||
const Sub1(var field) : super(field);
|
||||
}
|
||||
|
||||
class Sub2 extends Super {
|
||||
const Sub2(var field) : super(field);
|
||||
}
|
||||
|
||||
void main() {
|
||||
print(new Super(1));
|
||||
}
|
13
tests/language/metadata/lib.dart
Normal file
13
tests/language/metadata/lib.dart
Normal file
|
@ -0,0 +1,13 @@
|
|||
// Copyright (c) 2012, 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.
|
||||
|
||||
library metadata.dart;
|
||||
|
||||
class Alien {
|
||||
final String qwrrkz;
|
||||
const Alien(this.qwrrkz);
|
||||
const Alien.unknown() : qwrrkz = "???";
|
||||
}
|
||||
|
||||
const Klingon = const Alien("Klingon");
|
62
tests/language/metadata/metadata_test.dart
Normal file
62
tests/language/metadata/metadata_test.dart
Normal file
|
@ -0,0 +1,62 @@
|
|||
// Copyright (c) 2012, 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.
|
||||
|
||||
// Test ensuring that compiler can parse metadata. Need to add negative
|
||||
// test cases with illegal metadata annotations.
|
||||
|
||||
library metadata_test.dart;
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "lib.dart" as Meta;
|
||||
|
||||
class Tag {
|
||||
final String annotation;
|
||||
const Tag(this.annotation);
|
||||
}
|
||||
|
||||
const meta1 = 1;
|
||||
const meta2 = const Tag("meta2");
|
||||
|
||||
const extern = const Tag("external");
|
||||
|
||||
@meta1
|
||||
var topLevelVar;
|
||||
@Meta.Alien.unknown()
|
||||
List unknownUnknowns = [];
|
||||
|
||||
@meta1
|
||||
typedef int DingDong<@meta2 T>(@meta1 event);
|
||||
|
||||
@meta1
|
||||
class A<@Tag("typeParam") T> {
|
||||
@meta1
|
||||
@meta2
|
||||
static String staticField = "s";
|
||||
|
||||
@Meta.Alien("ET")
|
||||
int foo(@meta1 bool fool, {@meta1 @Tag("opt") x: 100}) {
|
||||
g() => 10;
|
||||
return x * g();
|
||||
}
|
||||
|
||||
@Tag(r"timewarp")
|
||||
List<int> getNextWeeksLottoNumbers() => [1, 2, 3, 4, 5, 6];
|
||||
}
|
||||
|
||||
@meta1
|
||||
main() {
|
||||
@meta1
|
||||
var a = new A();
|
||||
Expect.equals(0, a.foo(false, x: 0));
|
||||
|
||||
for (@Tag("loopvar")
|
||||
int i = 0;
|
||||
i < 10;
|
||||
i++) {
|
||||
// Do something.
|
||||
}
|
||||
|
||||
@meta1
|
||||
var s = r'This is a raw \\ string.';
|
||||
}
|
15
tests/language/metadata/scope1_test.dart
Normal file
15
tests/language/metadata/scope1_test.dart
Normal file
|
@ -0,0 +1,15 @@
|
|||
// Copyright (c) 2014, 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.
|
||||
|
||||
// Test that a type variable is not in scope for metadata declared on the type
|
||||
// declaration.
|
||||
|
||||
@deprecated
|
||||
typedef Foo
|
||||
<deprecated> // //# 01: ok
|
||||
();
|
||||
|
||||
main() {
|
||||
Foo? f = null;
|
||||
}
|
15
tests/language/metadata/scope2_test.dart
Normal file
15
tests/language/metadata/scope2_test.dart
Normal file
|
@ -0,0 +1,15 @@
|
|||
// Copyright (c) 2014, 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.
|
||||
|
||||
// Test that a type variable is not in scope for metadata declared on the type
|
||||
// declaration.
|
||||
|
||||
@deprecated
|
||||
class Foo
|
||||
<deprecated> // //# 01: ok
|
||||
{}
|
||||
|
||||
main() {
|
||||
Foo? f = null;
|
||||
}
|
14
tests/language/metadata/self_test.dart
Normal file
14
tests/language/metadata/self_test.dart
Normal file
|
@ -0,0 +1,14 @@
|
|||
// Copyright (c) 2014, 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.
|
||||
|
||||
// Test that metadata refer to the annotated declaration.
|
||||
|
||||
@Foo()
|
||||
class Foo {
|
||||
const Foo();
|
||||
}
|
||||
|
||||
main() {
|
||||
Foo f = const Foo();
|
||||
}
|
Loading…
Reference in a new issue