test: characterize TEdgePart

Freezes the single trait default before the port: conductsRedstone returns
false, TEdgePart extends TSlottedPart, and the $class static holds the
default rather than dispatching, so an overriding part gets its own value
from a direct call but false from the bridge.

The member is abstract on the reference interface, so a Java class cannot
inherit it today; the test part mirrors the forwarder Scala emits instead,
which keeps the file compiling before and after the port.

Adds a frozen Scala 2.11.5 consumer compiled against the reference dev jar
at f2f1870. OpenComputers is the only consumer, and it links against
$init$ rather than conductsRedstone.

61 plain-JVM tests, all passing against the untouched Scala.
This commit is contained in:
Algent committed 2026-08-14 21:28:51 +02:00
1 parent f2f1870931
commit f82b5d2294
5 files changed
+156

No files matched your search

@@ -0,0 +1,58 @@
package codechicken.multipart;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
class EdgePartCharacterizationTest {
@Test
void edgePartsDoNotConductRedstoneByDefault() {
assertFalse(new ForwardingPart().conductsRedstone());
}
/** The bridge holds the trait default rather than dispatching, so an override does not change what it returns. */
@Test
void deprecatedBridgeReturnsTheTraitDefaultEvenWhenOverridden() {
assertFalse(TEdgePart$class.conductsRedstone(new ForwardingPart()));
assertTrue(new ConductingPart().conductsRedstone());
assertFalse(TEdgePart$class.conductsRedstone(new ConductingPart()));
}
@Test
void edgePartIsASlottedPart() {
ForwardingPart part = new ForwardingPart();
assertTrue(part instanceof TSlottedPart);
assertEquals(1 << 15, part.getSlotMask());
}
/** Mirrors the forwarder Scala emits for a class mixing in the trait without overriding it. */
private static class ForwardingPart extends TMultiPart implements TEdgePart {
@Override
public String getType() {
return "test:edge";
}
@Override
public int getSlotMask() {
return 1 << 15;
}
@Override
public boolean conductsRedstone() {
return TEdgePart$class.conductsRedstone(this);
}
}
private static final class ConductingPart extends ForwardingPart {
@Override
public boolean conductsRedstone() {
return true;
}
}
}
@@ -0,0 +1,53 @@
package codechicken.multipart;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Objects;
import java.util.Scanner;
import org.junit.jupiter.api.Test;
/**
* Loads a Scala class compiled against the reference dev jar, whose forwarder calls TEdgePart$class.conductsRedstone
* and whose constructor calls TEdgePart$class.$init$. OpenComputers links against the latter.
*/
class TEdgePartBinaryCompatibilityTest {
@Test
void referenceScalaImplementorStillLinksThroughTheBridge() throws Exception {
Class<?> fixtureClass = new FixtureClassLoader(TEdgePart.class.getClassLoader()).define(loadFixture());
Object fixture = fixtureClass.getDeclaredConstructor().newInstance();
assertTrue(fixture instanceof TEdgePart);
assertTrue(fixture instanceof TSlottedPart);
assertTrue(fixture instanceof TMultiPart);
TEdgePart part = (TEdgePart) fixture;
assertFalse(part.conductsRedstone());
assertEquals(1 << 15, part.getSlotMask());
}
private static byte[] loadFixture() {
InputStream input = Objects.requireNonNull(
TEdgePartBinaryCompatibilityTest.class.getResourceAsStream("/compat/ReferenceScalaEdgePart.class.b64"));
try (Scanner scanner = new Scanner(input, StandardCharsets.US_ASCII.name()).useDelimiter("\\A")) {
return Base64.getMimeDecoder().decode(scanner.next());
}
}
private static final class FixtureClassLoader extends ClassLoader {
private FixtureClassLoader(ClassLoader parent) {
super(parent);
}
private Class<?> define(byte[] bytecode) {
return defineClass(null, bytecode, 0, bytecode.length);
}
}
}