Skip to content

Commit

Permalink
Add more edge cases to long testing.
Browse files Browse the repository at this point in the history
A patch made to GWT last year introduced a bug in turning Longs to
strings - while the same patch was made to J2CL, it did not have an
issue with signs, so these tests should pass as-is. With that said,
there was no test coverage for values that are positive as longs, but
negative when treated as an int, with all high bits set.

See gwtproject/gwt#9769

Closes #155

PiperOrigin-RevId: 464563372
  • Loading branch information
niloc132 authored and copybara-github committed Aug 1, 2022
1 parent 07925da commit eaffe6c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions jre/javatests/com/google/j2cl/jre/java/lang/LongTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ public void testToBinaryString() {
assertEquals(
"1111111111111111111111111111111111111111111111111111111111111111",
Long.toBinaryString(-1));

// Test int MAX+1 and int -1, as both are positive longs, but negative ints
assertEquals(
"10000000000000000000000000000000", Long.toBinaryString(((long) Integer.MAX_VALUE) + 1));
assertEquals("11111111111111111111111111111111", Long.toBinaryString(4294967295L));
}

public void testToHexString() {
Expand All @@ -262,6 +267,8 @@ public void testToHexString() {
assertEquals("1234500000000", Long.toHexString(0x1234500000000L));
assertEquals("fff1234500000000", Long.toHexString(0xFFF1234500000000L));
assertEquals("ffffffffffffffff", Long.toHexString(-1));
assertEquals("80000000", Long.toHexString(((long) Integer.MAX_VALUE) + 1));
assertEquals("ffffffff", Long.toHexString(4294967295L));
}

public void testToOctalString() {
Expand All @@ -270,6 +277,8 @@ public void testToOctalString() {
assertEquals("1000000000000000000000", Long.toOctalString(Long.MIN_VALUE));
assertEquals("777777777777777777777", Long.toOctalString(Long.MAX_VALUE));
assertEquals("1777777777777777777777", Long.toOctalString(-1));
assertEquals("20000000000", Long.toOctalString(((long) Integer.MAX_VALUE) + 1));
assertEquals("37777777777", Long.toOctalString(4294967295L));
}

public void testToString() {
Expand All @@ -281,6 +290,8 @@ public void testToString() {
assertEquals("80765", Long.toString(80765L));
assertEquals("-2147483648", Long.toString((long) Integer.MIN_VALUE));
assertEquals("2147483647", Long.toString((long) Integer.MAX_VALUE));
assertEquals("2147483648", Long.toString(((long) Integer.MAX_VALUE) + 1));
assertEquals("4294967295", Long.toString(4294967295L));
assertEquals("-89000000005", Long.toString(-89000000005L));
assertEquals("89000000005", Long.toString(89000000005L));
assertEquals("-9223372036854775808", Long.toString(Long.MIN_VALUE));
Expand Down

0 comments on commit eaffe6c

Please sign in to comment.