From dbfc4a3fe5ec00a041265513e3101c045f6990e4 Mon Sep 17 00:00:00 2001 From: turgutbababalim Date: Wed, 10 Sep 2025 10:57:55 +0300 Subject: [PATCH] Numeric type support for enum Issue: ICBVYD Description: Tests added for numeric enum support Signed-off-by: turgutbababalim --- .../constant_unary_minus.params.yaml | 1 + .../enum_numeric.ets} | 0 .../enum_numeric.params.yaml} | 54 +++++++++++++++++++ .../enum_numeric_n.ets} | 0 .../enum_numeric_n.params.yaml} | 29 +++++++++- .../enum_type_anno.params.yaml | 46 +++++++++++++--- .../enum_type_anno_n.params.yaml | 28 +++++++++- 7 files changed, 148 insertions(+), 10 deletions(-) rename static_core/plugins/ets/tests/ets-templates/11.enumerations/{04.enumeration_double_values/enum_double.ets => 04.enumeration_numeric_values/enum_numeric.ets} (100%) rename static_core/plugins/ets/tests/ets-templates/11.enumerations/{04.enumeration_double_values/enum_double.params.yaml => 04.enumeration_numeric_values/enum_numeric.params.yaml} (49%) rename static_core/plugins/ets/tests/ets-templates/11.enumerations/{04.enumeration_double_values/enum_double_n.ets => 04.enumeration_numeric_values/enum_numeric_n.ets} (100%) rename static_core/plugins/ets/tests/ets-templates/11.enumerations/{04.enumeration_double_values/enum_double_n.params.yaml => 04.enumeration_numeric_values/enum_numeric_n.params.yaml} (71%) diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/33.constant_expression/check_enum/constant_unary_minus.params.yaml b/static_core/plugins/ets/tests/ets-templates/07.expressions/33.constant_expression/check_enum/constant_unary_minus.params.yaml index 25f23420f1..a4c73eca5a 100644 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/33.constant_expression/check_enum/constant_unary_minus.params.yaml +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/33.constant_expression/check_enum/constant_unary_minus.params.yaml @@ -24,3 +24,4 @@ cases: - { type: long, value: -50000, expected: 50000 } - { type: float, value: -120.2f, expected: 120.2 } - { type: number, value: -5050.9, expected: 5050.9 } + diff --git a/static_core/plugins/ets/tests/ets-templates/11.enumerations/04.enumeration_double_values/enum_double.ets b/static_core/plugins/ets/tests/ets-templates/11.enumerations/04.enumeration_numeric_values/enum_numeric.ets similarity index 100% rename from static_core/plugins/ets/tests/ets-templates/11.enumerations/04.enumeration_double_values/enum_double.ets rename to static_core/plugins/ets/tests/ets-templates/11.enumerations/04.enumeration_numeric_values/enum_numeric.ets diff --git a/static_core/plugins/ets/tests/ets-templates/11.enumerations/04.enumeration_double_values/enum_double.params.yaml b/static_core/plugins/ets/tests/ets-templates/11.enumerations/04.enumeration_numeric_values/enum_numeric.params.yaml similarity index 49% rename from static_core/plugins/ets/tests/ets-templates/11.enumerations/04.enumeration_double_values/enum_double.params.yaml rename to static_core/plugins/ets/tests/ets-templates/11.enumerations/04.enumeration_numeric_values/enum_numeric.params.yaml index b14e92f9f3..174b2a8102 100644 --- a/static_core/plugins/ets/tests/ets-templates/11.enumerations/04.enumeration_double_values/enum_double.params.yaml +++ b/static_core/plugins/ets/tests/ets-templates/11.enumerations/04.enumeration_numeric_values/enum_numeric.params.yaml @@ -46,3 +46,57 @@ cases: arktest.assertEQ( "" + Enum.first, "-1.1" ) arktest.assertEQ( "" + Enum.second, "-1.2" ) arktest.assertEQ( "" + Enum.third, "-42.43" ) + + - decl: |- + enum Enum: byte { first = -2, second = -1, third = 0, fourth = 1 } + use: |- + arktest.assertEQ( "" + Enum.first, "-2" ) + arktest.assertEQ( "" + Enum.second, "-1" ) + arktest.assertEQ( "" + Enum.third, "0" ) + arktest.assertEQ( "" + Enum.fourth, "1" ) + + - decl: |- + enum Enum: byte { first = -2, second = -1, third = 0, fourth = 1 } + use: |- + arktest.assertEQ( "" + Enum.first, "-2" ) + arktest.assertEQ( "" + Enum.second, "-1" ) + arktest.assertEQ( "" + Enum.third, "0" ) + arktest.assertEQ( "" + Enum.fourth, "1" ) + + - decl: |- + enum Enum: short { first = -300, second = -1, third = 0, fourth = 300 } + use: |- + arktest.assertEQ( "" + Enum.first, "-300" ) + arktest.assertEQ( "" + Enum.second, "-1" ) + arktest.assertEQ( "" + Enum.third, "0" ) + arktest.assertEQ( "" + Enum.fourth, "300" ) + + - decl: |- + const a: byte = 0 + const b: short = 200 + enum Enum: int { first = a, second = b } + use: |- + arktest.assertEQ( "" + Enum.first, "0" ) + arktest.assertEQ( "" + Enum.second, "200" ) + + - decl: |- + type customDouble = double + const a: float = 2.2f + enum Enum: customDouble { first = a, second = 2344.44f } + use: |- + arktest.assertEQ( "" + Enum.first, "2.2" ) + arktest.assertEQ( "" + Enum.second, "2344.44" ) + + - decl: |- + enum Enum: byte { a, b, c = 0x5, d } + use: |- + arktest.assertEQ( Enum.a, 0x0 ) + arktest.assertEQ( Enum.b, 0x1 ) + arktest.assertEQ( Enum.d, 0x6 ) + + - decl: |- + enum Enum: short { a, b, c = 5, d } + use: |- + arktest.assertEQ( Enum.a, 0 ) + arktest.assertEQ( Enum.b, 1 ) + arktest.assertEQ( Enum.d, 6 ) \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/11.enumerations/04.enumeration_double_values/enum_double_n.ets b/static_core/plugins/ets/tests/ets-templates/11.enumerations/04.enumeration_numeric_values/enum_numeric_n.ets similarity index 100% rename from static_core/plugins/ets/tests/ets-templates/11.enumerations/04.enumeration_double_values/enum_double_n.ets rename to static_core/plugins/ets/tests/ets-templates/11.enumerations/04.enumeration_numeric_values/enum_numeric_n.ets diff --git a/static_core/plugins/ets/tests/ets-templates/11.enumerations/04.enumeration_double_values/enum_double_n.params.yaml b/static_core/plugins/ets/tests/ets-templates/11.enumerations/04.enumeration_numeric_values/enum_numeric_n.params.yaml similarity index 71% rename from static_core/plugins/ets/tests/ets-templates/11.enumerations/04.enumeration_double_values/enum_double_n.params.yaml rename to static_core/plugins/ets/tests/ets-templates/11.enumerations/04.enumeration_numeric_values/enum_numeric_n.params.yaml index 78d8734180..86f21ae0be 100644 --- a/static_core/plugins/ets/tests/ets-templates/11.enumerations/04.enumeration_double_values/enum_double_n.params.yaml +++ b/static_core/plugins/ets/tests/ets-templates/11.enumerations/04.enumeration_numeric_values/enum_numeric_n.params.yaml @@ -55,4 +55,31 @@ cases: enum Enum2 { first = -1.4, second = -42.32 } use: |- let v: Enum1 = Enum1.first - let q: Enum2 = v as Enum2 // not allowed conversion \ No newline at end of file + let q: Enum2 = v as Enum2 // not allowed conversion + + - decl: |- + let a: int = 2 + enum Enum1 { first = a } + use: |- + arktest.assertEQ( Enum1.first.valueOf(), 2 ) + + - decl: |- + enum Enum1: byte { first = 500} // Too large for byte + use: |- + arktest.assertEQ( Enum2.first.valueOf(), 500 ) + + - decl: |- + enum Enum1: byte { a = 254, b, c, d, e, f, g, h } // Generated big value + use: |- + arktest.assertEQ( Enum2.a.valueOf(), 254 ) + + - decl: |- + enum Enum1: short { a = 254.3 } // Cannot assign + use: |- + arktest.assertEQ( Enum2.a.valueOf(), 254.3 ) + + - decl: |- + enum Enum1: short { a = 254.3 } // Cannot assign + use: |- + arktest.assertEQ( Enum2.a.valueOf(), 254.3 ) + \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/11.enumerations/05.enumeration_type_annotation/enum_type_anno.params.yaml b/static_core/plugins/ets/tests/ets-templates/11.enumerations/05.enumeration_type_annotation/enum_type_anno.params.yaml index 6542818c47..65c5d4733e 100644 --- a/static_core/plugins/ets/tests/ets-templates/11.enumerations/05.enumeration_type_annotation/enum_type_anno.params.yaml +++ b/static_core/plugins/ets/tests/ets-templates/11.enumerations/05.enumeration_type_annotation/enum_type_anno.params.yaml @@ -21,7 +21,16 @@ cases: arktest.assertEQ( Enum.third.valueOf(), 4.5 ) - decl: |- - enum Enum: int { first = 1, second = 2, third = 3 } + type customType = double + enum Enum: customType { first = 2.3, second = 3.4, third = 4.5 } + use: |- + arktest.assertEQ( Enum.first.valueOf(), 2.3 ) + arktest.assertEQ( Enum.second.valueOf(), 3.4 ) + arktest.assertEQ( Enum.third.valueOf(), 4.5 ) + + - decl: |- + type customType = int + enum Enum: customType { first = 1, second = 2, third = 3 } use: |- arktest.assertEQ( Enum.first.valueOf(), 1 ) arktest.assertEQ( Enum.second.valueOf(), 2 ) @@ -33,20 +42,43 @@ cases: arktest.assertEQ( Enum.first.valueOf(), 100 ) - decl: |- - const a: double = 1.23 - const b: double = 1.234 - enum Enum: double { first = a, second = b, third = b - 1.1 } + const a: short = 1 + const b: short = 1 + enum Enum: short { first = a, second = b, third = b - 1 } use: |- arktest.assertEQ( Enum.first.valueOf(), a ) arktest.assertEQ( Enum.second.valueOf(), b ) - arktest.assertEQ( Enum.third.valueOf(), b - 1.1 ) + arktest.assertEQ( Enum.third.valueOf(), b - 1 ) - decl: |- const a: int = 1 const b: int = 2 - enum Enum: int { first = a, second = b, third = b - 1 } + enum Enum: byte { first = a, second = b, third = b - 1 } + use: |- + arktest.assertEQ( Enum.first.valueOf(), a ) + arktest.assertEQ( Enum.second.valueOf(), b ) + arktest.assertEQ( Enum.third.valueOf(), b - 1 ) + + - decl: |- + const a: int = 1 + const b: int = 2 + enum Enum: byte { first = a, second = b, third = b - 1 } use: |- arktest.assertEQ( Enum.first.valueOf(), a ) arktest.assertEQ( Enum.second.valueOf(), b ) arktest.assertEQ( Enum.third.valueOf(), b - 1 ) - \ No newline at end of file + + - decl: |- + enum Enum: int { first = 1 } + use: |- + arktest.assertEQ( Enum.first.valueOf() instanceof int, true ) + + - decl: |- + enum Enum: double { first = 1.2 } + use: |- + arktest.assertEQ( Enum.first.valueOf() instanceof double, true ) + + - decl: |- + enum Enum: string { first = "test" } + use: |- + arktest.assertEQ( Enum.first.valueOf() instanceof string, true ) diff --git a/static_core/plugins/ets/tests/ets-templates/11.enumerations/05.enumeration_type_annotation/enum_type_anno_n.params.yaml b/static_core/plugins/ets/tests/ets-templates/11.enumerations/05.enumeration_type_annotation/enum_type_anno_n.params.yaml index ad2fda9e5f..64ec3bcda1 100644 --- a/static_core/plugins/ets/tests/ets-templates/11.enumerations/05.enumeration_type_annotation/enum_type_anno_n.params.yaml +++ b/static_core/plugins/ets/tests/ets-templates/11.enumerations/05.enumeration_type_annotation/enum_type_anno_n.params.yaml @@ -14,7 +14,8 @@ --- cases: - decl: |- - enum Enum: int { first = 1.2, second = 1.3, third = 1.4 } + type customType = int + enum Enum: customType { first = 1.2, second = 1.3, third = 1.4 } use: |- arktest.assertEQ( Enum.first.valueOf(), 1.2 ) arktest.assertEQ( Enum.second.valueOf(), .1.3 ) @@ -25,6 +26,19 @@ cases: use: |- arktest.assertEQ( Enum.first.valueOf(), 1.0 ) + - decl: |- + type customType = double + enum Enum: customType { first = 1.0, second = 1, third } // wrong init type + use: |- + arktest.assertEQ( Enum.first.valueOf(), 1.0 ) + + - decl: |- + class editType {} + type customType = editType + enum Enum: customType { first = 1.0, second = 1, third } // wrong init type + use: |- + arktest.assertEQ( Enum.first.valueOf(), 1.0 ) + - decl: |- enum Enum: Array { first = 1.0, second = "A", third } // wrong init type use: |- @@ -51,4 +65,14 @@ cases: enum Enum2: Unknown { first = -1.4, second = -42.32 } use: |- let v: Unkown - let q: Enum2 = v as Enum2 // not allowed conversion \ No newline at end of file + let q: Enum2 = v as Enum2 // not allowed conversion + + - decl: |- + enum Enum: int { first = 2.2 } + use: |- + arktest.assertEQ( Enum.first.valueOf() instanceof int, true ) + + - decl: |- + enum Enum: btye { first = "2" } + use: |- + arktest.assertEQ( Enum.first.valueOf() instanceof byte, true ) \ No newline at end of file -- Gitee