Skip to content

Commit

Permalink
Relax tests slightly to allow kotlin native behaviour that seems to b…
Browse files Browse the repository at this point in the history
…e still conforming with the spec.

PiperOrigin-RevId: 600401554
  • Loading branch information
stefanhaustein authored and Google Java Core Libraries committed Jan 22, 2024
1 parent 8dc5e98 commit 52654b7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,12 @@ private void assertCastFails(long value) {
}
}

@J2ktIncompatible // TODO(b/285538920): Fix and enable.
public void testCompare() {
for (char x : VALUES) {
for (char y : VALUES) {
// note: spec requires only that the sign is the same
assertWithMessage(x + ", " + y)
.that(Chars.compare(x, y))
.isEqualTo(Character.valueOf(x).compareTo(y));
.that(Math.signum(Chars.compare(x, y)))
.isEqualTo(Math.signum(Character.valueOf(x).compareTo(y)));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,27 +304,37 @@ public void testParseIntWithRadixLimits() {
}
}

@J2ktIncompatible // TODO(b/285538920): Exception mismatch
public void testParseIntThrowsExceptionForInvalidRadix() {
// Valid radix values are Character.MIN_RADIX to Character.MAX_RADIX,
// inclusive.
//
// Note: According to the spec, a NumberFormatException is thrown for a number that is not
// parseable, but the spec doesn't seem to say which exception is thrown for an invalid radix.
// In contrast to the JVM, Kotlin native throws an Illegal argument exception in this case
// (which seems to make more sense).
try {
UnsignedInts.parseUnsignedInt("0", Character.MIN_RADIX - 1);
fail();
} catch (NumberFormatException expected) {
} catch (IllegalArgumentException expected) {
// Kotlin native, see above
}

try {
UnsignedInts.parseUnsignedInt("0", Character.MAX_RADIX + 1);
fail();
} catch (NumberFormatException expected) {
} catch (IllegalArgumentException expected) {
// Kotlin native, see above
}

// The radix is used as an array index, so try a negative value.
try {
UnsignedInts.parseUnsignedInt("0", -1);
fail();
} catch (NumberFormatException expected) {
} catch (IllegalArgumentException expected) {
// Kotlin native, see above
}
}

Expand Down
6 changes: 2 additions & 4 deletions guava-tests/test/com/google/common/primitives/CharsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,12 @@ private void assertCastFails(long value) {
}
}

@J2ktIncompatible // TODO(b/285538920): Fix and enable.
public void testCompare() {
for (char x : VALUES) {
for (char y : VALUES) {
// note: spec requires only that the sign is the same
assertWithMessage(x + ", " + y)
.that(Chars.compare(x, y))
.isEqualTo(Character.valueOf(x).compareTo(y));
.that(Math.signum(Chars.compare(x, y)))
.isEqualTo(Math.signum(Character.valueOf(x).compareTo(y)));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,27 +304,37 @@ public void testParseIntWithRadixLimits() {
}
}

@J2ktIncompatible // TODO(b/285538920): Exception mismatch
public void testParseIntThrowsExceptionForInvalidRadix() {
// Valid radix values are Character.MIN_RADIX to Character.MAX_RADIX,
// inclusive.
//
// Note: According to the spec, a NumberFormatException is thrown for a number that is not
// parseable, but the spec doesn't seem to say which exception is thrown for an invalid radix.
// In contrast to the JVM, Kotlin native throws an Illegal argument exception in this case
// (which seems to make more sense).
try {
UnsignedInts.parseUnsignedInt("0", Character.MIN_RADIX - 1);
fail();
} catch (NumberFormatException expected) {
} catch (IllegalArgumentException expected) {
// Kotlin native, see above
}

try {
UnsignedInts.parseUnsignedInt("0", Character.MAX_RADIX + 1);
fail();
} catch (NumberFormatException expected) {
} catch (IllegalArgumentException expected) {
// Kotlin native, see above
}

// The radix is used as an array index, so try a negative value.
try {
UnsignedInts.parseUnsignedInt("0", -1);
fail();
} catch (NumberFormatException expected) {
} catch (IllegalArgumentException expected) {
// Kotlin native, see above
}
}

Expand Down

0 comments on commit 52654b7

Please sign in to comment.