From c6cc1ebf206900b1b5ddee5b95003cefe2bfb29f Mon Sep 17 00:00:00 2001 From: yp9522 Date: Mon, 11 Aug 2025 16:08:33 +0800 Subject: [PATCH] Widening_numeric_conversions_test Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICSH7J Signed-off-by: yp9522 --- .../ets/widening_numeric_conversions.ets | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 ets2panda/test/runtime/ets/widening_numeric_conversions.ets diff --git a/ets2panda/test/runtime/ets/widening_numeric_conversions.ets b/ets2panda/test/runtime/ets/widening_numeric_conversions.ets new file mode 100644 index 0000000000..5d84b8c6c0 --- /dev/null +++ b/ets2panda/test/runtime/ets/widening_numeric_conversions.ets @@ -0,0 +1,90 @@ +/* + * 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. + */ + +let byteVal: byte = 100; +let shortVal: short = 30000; +let intVal: int = 2147483647; +let longVal: long = 9223372036854775807; +let floatVal: float = 3.14.toFloat(); +enum EnumInt { + Zero = 0, + One = 1, + Max = 2147483647 +} +enum EnumLong: long { + Zero = 0, + One = 1, + Max = 9223372036854775807 +} +enum EnumDouble: double { + One = 1.0, + Pi = 3.14, +} +function main() { + let byteToShort: short = byteVal; + let byteToInt: int = byteVal; + let byteToLong: long = byteVal; + let byteToFloat: float = byteVal; + let byteToDouble: double = byteVal; + arktest.assertEQ(byteToShort, 100 as short); + arktest.assertEQ(byteToInt, 100 as int); + arktest.assertEQ(byteToLong, 100 as long); + arktest.assertEQ(byteToFloat, 100 as float); + arktest.assertEQ(byteToDouble, 100 as double); + + let shortToInt: int = shortVal; + let shortToLong: long = shortVal; + let shortToFloat: float = shortVal; + let shortToDouble: double = shortVal; + arktest.assertEQ(shortToInt, 30000 as int); + arktest.assertEQ(shortToLong, 30000 as long); + arktest.assertEQ(shortToFloat, 30000 as float); + arktest.assertEQ(shortToDouble, 30000 as double); + + let intToLong: long = intVal; + let intToFloat: float = intVal; + let intToDouble: double = intVal; + arktest.assertEQ(intToLong, 2147483647 as long); + arktest.assertEQ(intToFloat, 2147483647 as float); + arktest.assertEQ(intToDouble, 2147483647 as double); + + let longToFloat: float = longVal; + let longToDouble: double = longVal; + arktest.assertEQ(longToFloat, 9223372036854775807 as float); + arktest.assertEQ(longToDouble, 9223372036854775807 as double); + + let floatToDouble: double = floatVal; + arktest.assertEQ(floatToDouble, 3.14.toFloat()); + + let enmuIntToInt: int = EnumInt.Max; + let enmuIntToLong: long = EnumInt.Max; + let enmuIntToFloat: float = EnumInt.Max; + let enmuIntToDouble: double = EnumInt.Max; + arktest.assertEQ(enmuIntToInt, 2147483647 as int); + arktest.assertEQ(enmuIntToLong, 2147483647 as long); + arktest.assertEQ(enmuIntToFloat, 2147483647 as float); + arktest.assertEQ(enmuIntToDouble, 2147483647 as double); + + let enmuLongToLong: long = EnumLong.Max; + let enmuLongToFloat: float = EnumLong.Max; + let enmuLongToDouble: double = EnumLong.Max; + arktest.assertEQ(enmuLongToLong, 9223372036854775807 as long); + arktest.assertEQ(enmuLongToFloat, 9223372036854775807 as float); + arktest.assertEQ(enmuLongToDouble, 9223372036854775807 as double); + +// not yet implemented +// let enmuDoubleToDouble: double = EnumDouble.Pi; +// arktest.assertEQ(enmuDoubleToDouble, 3.14); +} -- Gitee