-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1207. More enhanced enums tests grammar tests added
- Loading branch information
sgrekhov
committed
Oct 12, 2021
1 parent
978d1f4
commit 051d27f
Showing
4 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) 2021, 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 The grammar of the enum declaration becomes: | ||
/// | ||
/// <enumType> ::= | ||
/// `enum' <identifier> <typeParameters>? <mixins>? <interfaces>? `{' | ||
/// <enumEntry> (`,' <enumEntry>)* (`,')? (`;' | ||
/// (<metadata> <classMemberDefinition>)* | ||
/// )? | ||
/// `}' | ||
/// | ||
/// <enumEntry> ::= <metadata> <identifier> <argumentPart>? | ||
/// | <metadata> <identifier> <typeArguments>? '.' | ||
/// | identifier> <arguments> | ||
/// | ||
/// @description Check that old syntax can be used together with the new one | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=enhanced-enums | ||
|
||
enum E { | ||
e1, | ||
e2(), | ||
e3; | ||
|
||
const E(); | ||
} | ||
|
||
main() { | ||
E.e1; | ||
E.e2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) 2021, 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 It is a compile-time error if the enum declaration contains any | ||
/// generative constructor which is not const. | ||
// | ||
// We can allow omitting the const on constructors since it’s required, so we | ||
// can just assume it’s there. That’s a convenience we can also add at any later | ||
// point. | ||
/// | ||
/// @description Check that it is a compile-time error if the enum declaration | ||
/// contains any generative constructor which is not const | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=enhanced-enums | ||
|
||
enum E { | ||
e1, | ||
e2, | ||
e3; | ||
E(); | ||
//^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
main() { | ||
E.e1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) 2021, 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 It is a compile-time error if the enum declaration contains any | ||
/// generative constructor which is not const. | ||
// | ||
// We can allow omitting the const on constructors since it’s required, so we | ||
// can just assume it’s there. That’s a convenience we can also add at any later | ||
// point. | ||
/// | ||
/// @description Check that it is a compile-time error if the enum declaration | ||
/// contains any generative constructor which is not const | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=enhanced-enums | ||
|
||
enum E { | ||
e1, | ||
e2, | ||
e3; | ||
const E(); | ||
|
||
E.named() : this(); | ||
//^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
main() { | ||
E.e1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) 2021, 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 It is a compile-time error if the enum declaration contains any | ||
/// generative constructor which is not const. | ||
// | ||
// We can allow omitting the const on constructors since it’s required, so we | ||
// can just assume it’s there. That’s a convenience we can also add at any later | ||
// point. | ||
/// | ||
/// @description Check that non constant factory constructor is allowed | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=enhanced-enums | ||
|
||
import "../../Utils/expect.dart"; | ||
|
||
enum E { | ||
e1, | ||
e2, | ||
e3; | ||
const E(); | ||
|
||
factory E.f() => e1; | ||
|
||
E get getInstance => E.f(); | ||
} | ||
|
||
main() { | ||
Expect.equals(E.e1, E.e2.getInstance); | ||
} |