module lang::flybytes::tests::InterfaceTests
rascal-0.40.17
flybytes-0.2.8
Usage
import lang::flybytes::tests::InterfaceTests;
Source code
http://github.com/usethesource/flybytes/blob/main/src/lang/flybytes/tests/InterfaceTests.rsc
Dependencies
import lang::flybytes::Syntax;
import lang::flybytes::Compiler;
function interfA
Class interfA()
function interfB
Class interfB()
function implInvokeInterface
Class implInvokeInterface()
function implInvokeVirtual
Class implInvokeVirtual()
function interfDefault
Class interfDefault()
function implInvokeDefault
Class implInvokeDefault()
Tests
test implementAbstractMethodInvokeVirtual
test bool implementAbstractMethodInvokeVirtual() {
// load the classes together
cs = loadClasses([interfA(), interfB(), implInvokeVirtual()], prefix=just(|project://flybytes/generated/|));
// get a mirror instance of the class that implements the two interfaces
c = cs["Impl_A"];
i = c.newInstance(constructorDesc([]),[]);
// call test method which uses two implemented interface methods
return i.invoke(methodDesc(\void(), "testMethod", []), []).toValue(#bool);
}
test implementAbstractMethodInvokeInterface
test bool implementAbstractMethodInvokeInterface() {
// load the classes together
cs = loadClasses([interfA(), interfB(), implInvokeInterface()], prefix=just(|project://flybytes/generated/|));
// get a mirror instance of the class that implements the two interfaces
c = cs["Impl_A"];
i = c.newInstance(constructorDesc([]),[]);
// call test method which uses two implemented interface methods
return i.invoke(methodDesc(\void(), "testMethod", []), []).toValue(#bool);
}
test testInterfaceDefaultMethod
test bool testInterfaceDefaultMethod() {
// load the classes together, default methods require version 1.8
cs = loadClasses([interfDefault(), implInvokeDefault()], prefix=just(|project://flybytes/generated/|), version=v1_8());
// get a mirror instance of the class that implements the two interfaces
c = cs["Impl_B"];
i = c.newInstance(constructorDesc([]),[]);
// call test method which uses two implemented interface methods
return i.invoke(methodDesc(\void(), "testMethod", []), []).toValue(#bool);
}