mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
More tests added
This commit is contained in:
parent
ac0df0ca6b
commit
c8528ef91a
|
@ -104,7 +104,7 @@ public class ObjectNativeGenerator implements Generator, DependencyPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateWrap(GeneratorContext context, SourceWriter writer) {
|
private void generateWrap(GeneratorContext context, SourceWriter writer) {
|
||||||
writer.append("return ").append(context.getParameterName(1));
|
writer.append("return ").append(context.getParameterName(1)).append(";").newLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void achieveWrap(DependencyChecker checker, MethodReference method) {
|
private void achieveWrap(DependencyChecker checker, MethodReference method) {
|
||||||
|
|
|
@ -47,7 +47,7 @@ class TAbstractStringBuilder extends TObject implements TSerializable {
|
||||||
} else {
|
} else {
|
||||||
int pos = 10;
|
int pos = 10;
|
||||||
int sz = 1;
|
int sz = 1;
|
||||||
while (pos <= 1000000000 && pos <= value) {
|
while (pos < 1000000000 && pos * 10 <= value) {
|
||||||
pos *= 10;
|
pos *= 10;
|
||||||
++sz;
|
++sz;
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,6 @@ class TAbstractStringBuilder extends TObject implements TSerializable {
|
||||||
if (!positive) {
|
if (!positive) {
|
||||||
buffer[length++] = '-';
|
buffer[length++] = '-';
|
||||||
}
|
}
|
||||||
pos /= 10;
|
|
||||||
while (pos > 0) {
|
while (pos > 0) {
|
||||||
buffer[length++] = (char)('0' + value / pos);
|
buffer[length++] = (char)('0' + value / pos);
|
||||||
value %= pos;
|
value %= pos;
|
||||||
|
|
|
@ -45,9 +45,4 @@ class TObjectTests {
|
||||||
public void properInstanceDetected() {
|
public void properInstanceDetected() {
|
||||||
assertTrue(Object.class.isInstance(new Object()));
|
assertTrue(Object.class.isInstance(new Object()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void alwaysFails() {
|
|
||||||
fail();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,10 +8,30 @@ import org.junit.Test;
|
||||||
* @author Alexey Andreev
|
* @author Alexey Andreev
|
||||||
*/
|
*/
|
||||||
class TStringBuilderTests {
|
class TStringBuilderTests {
|
||||||
@Test
|
|
||||||
public void integerAppended() {
|
public void integerAppended() {
|
||||||
TStringBuilder sb = new TStringBuilder();
|
TStringBuilder sb = new TStringBuilder();
|
||||||
sb.append(23);
|
sb.append(23);
|
||||||
assertEquals("23", sb.toString());
|
assertEquals("23", sb.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void largeIntegerAppended() {
|
||||||
|
TStringBuilder sb = new TStringBuilder();
|
||||||
|
sb.append(123456);
|
||||||
|
assertEquals("123456", sb.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void negativeIntegerAppended() {
|
||||||
|
TStringBuilder sb = new TStringBuilder();
|
||||||
|
sb.append(-23);
|
||||||
|
assertEquals("-23", sb.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void maxIntegerAppended() {
|
||||||
|
TStringBuilder sb = new TStringBuilder();
|
||||||
|
sb.append(2147483647);
|
||||||
|
assertEquals("2147483647", sb.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,12 +20,12 @@ class TSystemTests {
|
||||||
assertSame(a, dest[2]);
|
assertSame(a, dest[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(expected = IndexOutOfBoundsException.class)
|
||||||
public void failsToCopyArraysWithInvalidIndexes() {
|
public void failsToCopyArraysWithInvalidIndexes() {
|
||||||
TSystem.arraycopy(TObject.wrap(new TObject[0]), 0, TObject.wrap(new TObject[0]), 0, 1);
|
TSystem.arraycopy(TObject.wrap(new TObject[0]), 0, TObject.wrap(new TObject[0]), 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(expected = ArrayStoreException.class)
|
||||||
public void failsToCopyArraysWithIncompatibleElements() {
|
public void failsToCopyArraysWithIncompatibleElements() {
|
||||||
TSystem.arraycopy(TObject.wrap(new TObject[1]), 0, TObject.wrap(new int[1]), 0, 1);
|
TSystem.arraycopy(TObject.wrap(new TObject[1]), 0, TObject.wrap(new int[1]), 0, 1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,7 +119,16 @@ public class ClasslibTestGenerator {
|
||||||
for (MethodReference method : methods) {
|
for (MethodReference method : methods) {
|
||||||
writer.append("runTestCase(").appendClass(cls.getName()).append(".").appendMethod(cons)
|
writer.append("runTestCase(").appendClass(cls.getName()).append(".").appendMethod(cons)
|
||||||
.append("(), \"" + method.getDescriptor().getName() + "\", \"").appendMethod(method)
|
.append("(), \"" + method.getDescriptor().getName() + "\", \"").appendMethod(method)
|
||||||
.append("\");").newLine();
|
.append("\", [");
|
||||||
|
MethodHolder methodHolder = classSource.getClassHolder(method.getClassName()).getMethod(
|
||||||
|
method.getDescriptor());
|
||||||
|
AnnotationHolder annot = methodHolder.getAnnotations().get("org.junit.Test");
|
||||||
|
AnnotationValue expectedAnnot = annot.getValues().get("expected");
|
||||||
|
if (expectedAnnot != null) {
|
||||||
|
String className = ((ValueType.Object)expectedAnnot.getJavaClass()).getClassName();
|
||||||
|
writer.appendClass(className);
|
||||||
|
}
|
||||||
|
writer.append("]);").newLine();
|
||||||
}
|
}
|
||||||
writer.outdent().append("})").newLine();
|
writer.outdent().append("})").newLine();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
currentTestReportBody = null;
|
currentTestReportBody = null;
|
||||||
|
|
||||||
runTestCase = function(instance, methodName, realMethodName) {
|
runTestCase = function(instance, methodName, realMethodName, expectedExceptions) {
|
||||||
var row = document.createElement("tr");
|
var row = document.createElement("tr");
|
||||||
currentTestReportBody.appendChild(row);
|
currentTestReportBody.appendChild(row);
|
||||||
var nameCell = document.createElement("td");
|
var nameCell = document.createElement("td");
|
||||||
|
@ -12,14 +12,33 @@ runTestCase = function(instance, methodName, realMethodName) {
|
||||||
row.appendChild(exceptionCell);
|
row.appendChild(exceptionCell);
|
||||||
try {
|
try {
|
||||||
instance[realMethodName]();
|
instance[realMethodName]();
|
||||||
|
if (expectedExceptions.length > 0) {
|
||||||
|
statusCell.appendChild(document.createTextNode("expected exception not thrown"));
|
||||||
|
} else {
|
||||||
statusCell.appendChild(document.createTextNode("ok"));
|
statusCell.appendChild(document.createTextNode("ok"));
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if (isExpectedException(e, expectedExceptions)) {
|
||||||
|
statusCell.appendChild(document.createTextNode("ok"));
|
||||||
|
} else {
|
||||||
statusCell.appendChild(document.createTextNode("unexpected exception"));
|
statusCell.appendChild(document.createTextNode("unexpected exception"));
|
||||||
var exceptionText = document.createElement("pre");
|
var exceptionText = document.createElement("pre");
|
||||||
exceptionText.appendChild(document.createTextNode(e.stack));
|
exceptionText.appendChild(document.createTextNode(e.stack));
|
||||||
exceptionCell.appendChild(exceptionText);
|
exceptionCell.appendChild(exceptionText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
isExpectedException = function(e, expectedExceptions) {
|
||||||
|
if (e.$javaException !== undefined) {
|
||||||
|
for (var i = 0; i < expectedExceptions.length; ++i) {
|
||||||
|
if (expectedExceptions[i] === e.$javaException.$class) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
testClass = function(className, classTests) {
|
testClass = function(className, classTests) {
|
||||||
var table = document.createElement("table");
|
var table = document.createElement("table");
|
||||||
|
|
|
@ -496,6 +496,7 @@ public class ProgramParser {
|
||||||
NegateInstruction insn = new NegateInstruction(operandType);
|
NegateInstruction insn = new NegateInstruction(operandType);
|
||||||
insn.setOperand(getVariable(operand));
|
insn.setOperand(getVariable(operand));
|
||||||
insn.setReceiver(getVariable(receiver));
|
insn.setReceiver(getVariable(receiver));
|
||||||
|
builder.add(insn);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void emitCast(ValueType targetType, int value, int result) {
|
private void emitCast(ValueType targetType, int value, int result) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user