Skip to content

Commit

Permalink
[tests] add tests for binary literal
Browse files Browse the repository at this point in the history
  • Loading branch information
kLabz committed Apr 4, 2024
1 parent dd9da8f commit 484e5e0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
13 changes: 13 additions & 0 deletions tests/unit/src/unit/TestMisc.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
12 changes: 12 additions & 0 deletions tests/unit/src/unit/TestNumericSeparator.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
10 changes: 9 additions & 1 deletion tests/unit/src/unit/TestNumericSuffixes.hx
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,12 @@ class TestNumericSuffixes extends Test {
eq(0xFFFFFFFFFFFFFFFFi64 + "", "-1");
eq(0x7FFFFFFFFFFFFFFFi64 + "", "9223372036854775807");
}
}

public function testBinSuffixes() {
eq(0b11111111111111111111111111111111i32, -1);
eq(0b11111111111111111111111111111111u32, (0b11111111111111111111111111111111i32 : UInt));
eq(0b11111111111111111111111111111111i64 + "", "4294967295");
eq(0b1111111111111111111111111111111111111111111111111111111111111111i64 + "", "-1");
eq(0b0111111111111111111111111111111111111111111111111111111111111111i64 + "", "9223372036854775807");
}
}

0 comments on commit 484e5e0

Please sign in to comment.