Skip to content

Commit

Permalink
#1207. More enhanced enums tests grammar tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed Oct 12, 2021
1 parent 978d1f4 commit 051d27f
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 0 deletions.
34 changes: 34 additions & 0 deletions LanguageFeatures/Enhanced-Enum/grammar_A04_t03.dart
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;
}
30 changes: 30 additions & 0 deletions LanguageFeatures/Enhanced-Enum/grammar_A05_t01.dart
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;
}
32 changes: 32 additions & 0 deletions LanguageFeatures/Enhanced-Enum/grammar_A05_t02.dart
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;
}
32 changes: 32 additions & 0 deletions LanguageFeatures/Enhanced-Enum/grammar_A05_t03.dart
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);
}

0 comments on commit 051d27f

Please sign in to comment.