diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/StringBuilderTests.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/StringBuilderTests.java index 293eaeebe..0871b3da2 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/StringBuilderTests.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/StringBuilderTests.java @@ -8,6 +8,7 @@ import org.junit.Test; * @author Alexey Andreev */ public class StringBuilderTests { + @Test public void integerAppended() { StringBuilder sb = new StringBuilder(); sb.append(23); @@ -35,6 +36,34 @@ public class StringBuilderTests { assertEquals("2147483647", sb.toString()); } + @Test + public void longAppended() { + StringBuilder sb = new StringBuilder(); + sb.append(23L); + assertEquals("23", sb.toString()); + } + + @Test + public void negativeLongAppended() { + StringBuilder sb = new StringBuilder(); + sb.append(-23L); + assertEquals("-23", sb.toString()); + } + + @Test + public void largeLongAppended() { + StringBuilder sb = new StringBuilder(); + sb.append(12345678901234L); + assertEquals("12345678901234", sb.toString()); + } + + @Test + public void maxLongAppended() { + StringBuilder sb = new StringBuilder(); + sb.append(9223372036854775807L); + assertEquals("9223372036854775807", sb.toString()); + } + @Test public void appendsCodePoint() { StringBuilder sb = new StringBuilder(); diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TAbstractStringBuilder.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TAbstractStringBuilder.java index 5e0d210c6..305fbceb8 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TAbstractStringBuilder.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TAbstractStringBuilder.java @@ -67,6 +67,43 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ return this; } + protected TAbstractStringBuilder append(long value) { + boolean positive = true; + if (value < 0) { + positive = false; + value = -value; + } + if (value < 10) { + if (!positive) { + ensureCapacity(length + 2); + buffer[length++] = '-'; + } else { + ensureCapacity(length + 1); + } + buffer[length++] = (char)('0' + value); + } else { + int pos = 10; + int sz = 1; + while (pos < 1000000000000000000L && pos * 10 <= value) { + pos *= 10; + ++sz; + } + if (!positive) { + ++sz; + } + ensureCapacity(length + sz); + if (!positive) { + buffer[length++] = '-'; + } + while (pos > 0) { + buffer[length++] = (char)('0' + value / pos); + value %= pos; + pos /= 10; + } + } + return this; + } + protected TAbstractStringBuilder append(char c) { ensureCapacity(length + 1); buffer[length++] = c; diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TString.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TString.java index 0a66d0d8d..5138d6c1f 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TString.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TString.java @@ -415,8 +415,12 @@ public class TString extends TObject implements TSerializable, TComparable