From 484e5e0200abbffa1149424eda7d19ca6571b426 Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Thu, 4 Apr 2024 11:43:52 +0200 Subject: [PATCH] [tests] add tests for binary literal --- tests/unit/src/unit/TestMisc.hx | 13 +++++++++++++ tests/unit/src/unit/TestNumericSeparator.hx | 12 ++++++++++++ tests/unit/src/unit/TestNumericSuffixes.hx | 10 +++++++++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/tests/unit/src/unit/TestMisc.hx b/tests/unit/src/unit/TestMisc.hx index 12750493311..a4135266e6e 100644 --- a/tests/unit/src/unit/TestMisc.hx +++ b/tests/unit/src/unit/TestMisc.hx @@ -613,4 +613,17 @@ class TestMisc extends Test { var values = AbstractEnumTools.getValues(MyEnumAbstract); eq(values.join(","), "1,2,3"); } + + function testIntLiterals() { + eq(15, 0xF); + eq(255, 0xFF); + eq(305419896, 0x12345678); + eq(162254319, 0x09ABCDEF); + + eq(0, 0b0); + eq(1, 0b1); + eq(2, 0b10); + eq(8, 0b1000); + eq(0xFFFFFFFF, 0b11111111111111111111111111111111); + } } diff --git a/tests/unit/src/unit/TestNumericSeparator.hx b/tests/unit/src/unit/TestNumericSeparator.hx index 4cf3bf53bdb..5e3dda62618 100644 --- a/tests/unit/src/unit/TestNumericSeparator.hx +++ b/tests/unit/src/unit/TestNumericSeparator.hx @@ -10,6 +10,10 @@ class TestNumericSeparator extends Test { eq(0x12_0, 0x120); eq(0x1_2_0, 0x120); + // bin int + eq(0b11_0, 0b110); + eq(0b1_1_0, 0b110); + // normal float feq(12.3_4, 12.34); feq(1_2.34, 12.34); @@ -36,6 +40,10 @@ class TestNumericSeparator extends Test { eq(0x12_0i32, 0x120i32); eq(0x1_2_0i32, 0x120i32); + // bin int + eq(0b11_0i32, 0b110i32); + eq(0b1_1_0i32, 0b110i32); + // normal float feq(12.3_4f64, 12.34f64); feq(1_2.34f64, 12.34f64); @@ -59,6 +67,10 @@ class TestNumericSeparator extends Test { eq(0x12_0_i32, 0x120i32); eq(0x1_2_0_i32, 0x120i32); + // bin int + eq(0b11_0_i32, 0b110i32); + eq(0b1_1_0_i32, 0b110i32); + // normal float feq(12.3_4_f64, 12.34f64); feq(1_2.34_f64, 12.34f64); diff --git a/tests/unit/src/unit/TestNumericSuffixes.hx b/tests/unit/src/unit/TestNumericSuffixes.hx index ef651805727..745f4be39a1 100644 --- a/tests/unit/src/unit/TestNumericSuffixes.hx +++ b/tests/unit/src/unit/TestNumericSuffixes.hx @@ -26,4 +26,12 @@ class TestNumericSuffixes extends Test { eq(0xFFFFFFFFFFFFFFFFi64 + "", "-1"); eq(0x7FFFFFFFFFFFFFFFi64 + "", "9223372036854775807"); } -} \ No newline at end of file + + public function testBinSuffixes() { + eq(0b11111111111111111111111111111111i32, -1); + eq(0b11111111111111111111111111111111u32, (0b11111111111111111111111111111111i32 : UInt)); + eq(0b11111111111111111111111111111111i64 + "", "4294967295"); + eq(0b1111111111111111111111111111111111111111111111111111111111111111i64 + "", "-1"); + eq(0b0111111111111111111111111111111111111111111111111111111111111111i64 + "", "9223372036854775807"); + } +}