test: add Test for Switch-Case with generic Records.
All checks were successful
Build and Test with Maven / Build-and-test-with-Maven (push) Successful in 6m55s
All checks were successful
Build and Test with Maven / Build-and-test-with-Maven (push) Successful in 6m55s
This commit is contained in:
parent
fbc9f1e755
commit
3ac3af2327
27
resources/bytecode/javFiles/GenericRecordSwitchCase.jav
Normal file
27
resources/bytecode/javFiles/GenericRecordSwitchCase.jav
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import java.lang.Object;
|
||||||
|
import java.lang.String;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
sealed interface List permits LinkedElem {}
|
||||||
|
|
||||||
|
|
||||||
|
public record LinkedElem<T>(T a,List l) implements List{} //Implementiert List und wird auch permittet
|
||||||
|
public record Elem<T>(T c) implements List{} //Implementiert List, wird aber nicht permittet
|
||||||
|
|
||||||
|
public class SwitchCaseHeritageDetection {
|
||||||
|
public main(o) {
|
||||||
|
return switch(o) {
|
||||||
|
case LinkedElem(a, Elem(e)) -> a ;
|
||||||
|
case LinkedElem(a, LinkedElem(e, Elem(f))) -> e;
|
||||||
|
default -> null;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -749,7 +749,6 @@ public class TestComplete {
|
|||||||
assertEquals(swtch.invoke(instance, r1), "Second Element is a Text");
|
assertEquals(swtch.invoke(instance, r1), "Second Element is a Text");
|
||||||
assertEquals(swtch.invoke(instance, r2), "Second Element is a Number");
|
assertEquals(swtch.invoke(instance, r2), "Second Element is a Number");
|
||||||
}
|
}
|
||||||
@Ignore("Not implemented")
|
|
||||||
@Test
|
@Test
|
||||||
public void testSwitchListRecord() throws Exception {
|
public void testSwitchListRecord() throws Exception {
|
||||||
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "SwitchRecordList.jav");
|
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "SwitchRecordList.jav");
|
||||||
@ -765,7 +764,7 @@ public class TestComplete {
|
|||||||
|
|
||||||
|
|
||||||
var constructorLinkedElem = linkedElem.getDeclaredConstructor(Integer.class, listInterface);
|
var constructorLinkedElem = linkedElem.getDeclaredConstructor(Integer.class, listInterface);
|
||||||
var constructorElem = elem.getConstructor(Integer.class);
|
var constructorElem = elem.getDeclaredConstructor(Integer.class);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -776,6 +775,33 @@ public class TestComplete {
|
|||||||
assertEquals(swtch.invoke(instance, listWithOneElement), 10);
|
assertEquals(swtch.invoke(instance, listWithOneElement), 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGenericRecordSwitchCase() throws Exception {
|
||||||
|
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "GenericRecordSwitchCase.jav");
|
||||||
|
|
||||||
|
var clazz = classFiles.get("SwitchCaseHeritageDetection");
|
||||||
|
|
||||||
|
var instance = clazz.getDeclaredConstructor().newInstance();
|
||||||
|
var swtch = clazz.getDeclaredMethod("main", Object.class);
|
||||||
|
|
||||||
|
var linkedElem = classFiles.get("LinkedElem");
|
||||||
|
var listInterface = classFiles.get("List");
|
||||||
|
var elem = classFiles.get("Elem");
|
||||||
|
|
||||||
|
|
||||||
|
var constructorLinkedElem = linkedElem.getDeclaredConstructor(Object.class, listInterface);
|
||||||
|
var constructorElem = elem.getConstructor(Object.class);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var listWithMoreThanOneElement = constructorLinkedElem.newInstance(5, constructorLinkedElem.newInstance(1, constructorElem.newInstance(5)));
|
||||||
|
assertEquals(swtch.invoke(instance, listWithMoreThanOneElement), 1);
|
||||||
|
|
||||||
|
var listWithOneElement = constructorLinkedElem.newInstance(5, constructorElem.newInstance(5));
|
||||||
|
assertEquals(swtch.invoke(instance, listWithOneElement), 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Ignore("Not implemented")
|
@Ignore("Not implemented")
|
||||||
@Test
|
@Test
|
||||||
public void testSwitch2() throws Exception {
|
public void testSwitch2() throws Exception {
|
||||||
|
Loading…
Reference in New Issue
Block a user