Skip to content

Commit

Permalink
#1207. More Enhanced enums semantics tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed Oct 21, 2021
1 parent 8128e67 commit 0510180
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 1 deletion.
2 changes: 1 addition & 1 deletion LanguageFeatures/Enhanced-Enum/grammar_A09_t04.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ enum E1<T> {
e2<String>(),
e3<bool>();

T call(T t) => t
T call(T t) => t;
}

enum E2<T> {
Expand Down
46 changes: 46 additions & 0 deletions LanguageFeatures/Enhanced-Enum/semantics_A03_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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 If no generative constructors were declared, and no unnamed
/// factory constructor was added, a default generative constructor
/// const Name._$(this.index, this._$name); is added.
///
/// @description Check the case when enum has no generative constructor
/// specified
/// @author [email protected]
// SharedOptions=--enable-experiment=enhanced-enums

import "../../Utils/expect.dart";

enum E1 {
e1,
e2,
e3;

factory E1.f(int index) => values[i];
}

enum E2 {
e1(),
e2(),
e3();

factory E2.f(int index) => values[i];
}

main() {
Expect.equals(0, E1.e1.index);
Expect.equals(1, E1.e2.index);
Expect.equals(2, E1.e3.index);
Expect.equals("E1.e1", E1.e1.toString());
Expect.equals("E1.e2", E1.e2.toString());
Expect.equals("E1.e3", E1.e3.toString());
Expect.equals(0, E2.e1.index);
Expect.equals(1, E2.e2.index);
Expect.equals(2, E2.e3.index);
Expect.equals("E2.e1", E2.e1.toString());
Expect.equals("E2.e2", E2.e2.toString());
Expect.equals("E2.e3", E2.e3.toString());
}
30 changes: 30 additions & 0 deletions LanguageFeatures/Enhanced-Enum/semantics_A04_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 If no toString member was declared, add
/// String toString() => “Name.${_$name}”;.
///
/// @description Check that if no toString member was declared, then
/// String toString() => “Name.${_$name}”; is added.
/// @author [email protected]
// SharedOptions=--enable-experiment=enhanced-enums

import "../../Utils/expect.dart";

enum E<T> {
e1<int>(42),
e2<String>("42"),
e3<bool>(false);

final T _t;

const E(this._t);
}

main() {
Expect.equals("E.e1", E.e1.toString());
Expect.equals("E.e2", E.e2.toString());
Expect.equals("E.e3", E.e3.toString());
}
43 changes: 43 additions & 0 deletions LanguageFeatures/Enhanced-Enum/semantics_A04_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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 If no toString member was declared, add
/// String toString() => “Name.${_$name}”;.
///
/// @description Check that if 'toString' member specified, then it is called
/// instead of the default one
/// @author [email protected]
// SharedOptions=--enable-experiment=enhanced-enums

import "../../Utils/expect.dart";

enum E1 {
e1,
e2,
e3;

String toString() => "Enum E1.${this.name}";
}

enum E2<T> {
e1<int>(42),
e2<String>("Lily was here"),
e3<bool>(false);

final T _t;

const E2(this._t);

String toString() => "E2<$T>.${this.name}($_t)";
}

main() {
Expect.equals("Enum E1.e1", E1.e1.toString());
Expect.equals("Enum E1.e2", E1.e2.toString());
Expect.equals("Enum E1.e3", E1.e3.toString());
Expect.equals("E2<int>.e1(42)", E2.e1.toString());
Expect.equals("E2<String>.e2(Lily was here)", E2.e2.toString());
Expect.equals("E2<bool>.e3(false)", E2.e3.toString());
}
45 changes: 45 additions & 0 deletions LanguageFeatures/Enhanced-Enum/semantics_A05_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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 For each <enumEntry> with name id and index i in the
/// comma-separated list of enum entries, a static constant is added as follows:
///
/// id ↦ static const Name id = Name._$(i, "id"); — equivalent to id().
/// id(args) ↦ static const Name id = Name._$(i, “id”, args); — if Name is not
/// generic
/// id<types>(args) ↦
/// static const Name<types> id = Name<types>._$(i, “id”, args);
/// id.named(args) ↦ static const Name id = Name._$named(i, “id”, args); — if
/// Name is not generic
/// id<types>.named(args) ↦
/// static const Name<types> id = Name<types>._$named(i, “id”, args);
///
/// @description Check that it is a compile time error if member is called with
/// a wrong type
/// @author [email protected]
// SharedOptions=--enable-experiment=enhanced-enums

enum E<T> {
e1<int>(),
e2<String>(),
e3<bool>();

T foo(T t) => t;
}

main() {
E.e1.foo("42");
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified
E.e2.foo(42);
// ^^
// [analyzer] unspecified
// [cfe] unspecified
E.e3.foo(42);
// ^^
// [analyzer] unspecified
// [cfe] unspecified
}

0 comments on commit 0510180

Please sign in to comment.