7dd4259d87
Change-Id: Ie7b6ff9e62b3b8c78f6c04359cb72f77b249440c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/97240 Commit-Queue: Johnni Winther <johnniwinther@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com> Reviewed-by: Sigmund Cherem <sigmund@google.com>
89 lines
2.6 KiB
Dart
89 lines
2.6 KiB
Dart
// Copyright (c) 2017, 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.
|
|
|
|
/*element: main:[null]*/
|
|
main() {
|
|
enumValue();
|
|
enumIndex();
|
|
enumValues();
|
|
enumToString1();
|
|
enumToString2();
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// Access an enum value.
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
enum Enum1 {
|
|
/*strong.element: Enum1.a:[exact=Enum1]*/
|
|
/*omit.element: Enum1.a:[exact=Enum1]*/
|
|
a,
|
|
}
|
|
|
|
/*element: enumValue:[exact=Enum1]*/
|
|
enumValue() => Enum1.a;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// Access an enum 'index' property.
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
enum Enum2 {
|
|
/*strong.element: Enum2.a:[exact=Enum2]*/
|
|
/*omit.element: Enum2.a:[exact=Enum2]*/
|
|
a,
|
|
}
|
|
|
|
/*element: enumIndex:[exact=JSUInt31]*/
|
|
enumIndex() => Enum2.a. /*[exact=Enum2]*/ index;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// Access an enum 'values' property.
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
enum Enum3 {
|
|
/*strong.element: Enum3.a:[exact=Enum3]*/
|
|
/*omit.element: Enum3.a:[exact=Enum3]*/
|
|
a,
|
|
/*strong.element: Enum3.b:[exact=Enum3]*/
|
|
/*omit.element: Enum3.b:[exact=Enum3]*/
|
|
b,
|
|
}
|
|
|
|
/*element: enumValues:Container([exact=JSUnmodifiableArray], element: [exact=Enum3], length: 2)*/
|
|
enumValues() => Enum3.values;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// Call an enum 'toString' method on a singleton enum.
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
enum Enum4 {
|
|
/*strong.element: Enum4.a:[exact=Enum4]*/
|
|
/*omit.element: Enum4.a:[exact=Enum4]*/
|
|
a,
|
|
}
|
|
|
|
/*element: enumToString1:Value([exact=JSString], value: "Enum4.a")*/
|
|
enumToString1() {
|
|
return Enum4.a. /*invoke: [exact=Enum4]*/ toString();
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// Call an enum 'toString' method on an enum with multiple values.
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
enum Enum5 {
|
|
/*strong.element: Enum5.a:[exact=Enum5]*/
|
|
/*omit.element: Enum5.a:[exact=Enum5]*/
|
|
a,
|
|
/*strong.element: Enum5.b:[exact=Enum5]*/
|
|
/*omit.element: Enum5.b:[exact=Enum5]*/
|
|
b,
|
|
}
|
|
|
|
/*element: enumToString2:[exact=JSString]*/
|
|
enumToString2() {
|
|
Enum5.b. /*invoke: [exact=Enum5]*/ toString();
|
|
return Enum5.a. /*invoke: [exact=Enum5]*/ toString();
|
|
}
|