JSAbstractOperations { static String ToString(Object arg) { if (arg == null) { return "null"; } else if (Boolean.TRUE.equals(arg)) { return "true"; } else if (Boolean.FALSE.equals(arg)) { return "false"; } else if (arg instanceof String) { return (String) arg; } else if (arg instanceof Number) { return ToString((Number) arg); } Object primValue = ToPrimitive(arg, "String"); return ToString(primValue); }   static final BigInteger UINT_MAX_VALUE; static final Double UINT_MAX_VALUE_D; static final BigInteger SINT_MAX_VALUE; static final BigInteger USHORT_MAX_VALUE; }
@Test public void testToString01() { assertEquals("null", ToString(null)); assertEquals("false", ToString(false)); assertEquals("true", ToString(true)); assertEquals("abc", ToString("abc")); assertEquals("0", ToString(0)); assertEquals("NaN", ToString(NaN)); }
@Test public void testToString02() { assertEquals("2,4,8,16,32", ToString(Array(2, 4, 8, 16, 32))); Object myobj1 = new Object() { @SuppressWarnings("unused") public double toNumber() { return 12345; } public String toString() { return "67890"; } @SuppressWarnings("unused") public String valueOf() { return "[object MyObj]"; } }; assertEquals("67890", ToString(myobj1)); }
@Test public void testToString03() { assertEquals("0", ToString(+0)); assertEquals("0", ToString(-0)); assertEquals("-1234567890", ToString(-1234567890)); assertEquals("Infinity", ToString(Double.POSITIVE_INFINITY)); assertEquals("-Infinity", ToString(Double.NEGATIVE_INFINITY)); assertEquals("1", ToString(1)); assertEquals("10", ToString(10)); assertEquals("100", ToString(100)); assertEquals("12345", ToString(12345)); assertEquals("12345000", ToString(12345000)); assertEquals("-1", ToString(-1)); assertEquals("-10", ToString(-10)); assertEquals("-100", ToString(-100)); assertEquals("-12345", ToString(-12345)); assertEquals("-12345000", ToString(-12345000)); assertEquals("1.0000001", ToString(1.0000001)); assertEquals("-1.0000001", ToString(-1.0000001)); assertEquals("0.1", ToString(0.1)); assertEquals("-0.1", ToString(-0.1)); }