diff --git a/ets2panda/test/runtime/ets/enum_stringEnum_as_union.ets b/ets2panda/test/runtime/ets/enum_stringEnum_as_union.ets new file mode 100644 index 0000000000000000000000000000000000000000..30308fa30261c5ed78c72cdfb99454f8be732b32 --- /dev/null +++ b/ets2panda/test/runtime/ets/enum_stringEnum_as_union.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +enum StringEnum { + A = "A", + B = "B", + C = "C" +} + +class C { + public a: string | StringEnum = StringEnum.A; +} + +interface I { + a: string | StringEnum; +} + +type UTA = string | StringEnum | number; + +function foo(a: string | StringEnum): string { + return a; +} + +function main() { + let a: UTA = StringEnum.A; + let b: string | number = a; + arktest.assertEQ(a, b); + arktest.assertEQ(b, "A"); + arktest.assertEQ(foo(StringEnum.B), "B"); + // class + let c: C = new C(); + arktest.assertEQ(c.a, "A"); + // interface + let i: I = { a: StringEnum.C }; + arktest.assertEQ(i.a, "C"); +}