66import org .openzen .zenscript .scriptingexample .tests .SharedGlobals ;
77import org .openzen .zenscript .scriptingexample .tests .helpers .ZenCodeTest ;
88
9+ import java .util .ArrayList ;
910import java .util .Collections ;
1011import java .util .List ;
1112import java .util .function .BiFunction ;
@@ -17,7 +18,9 @@ public List<Class<?>> getRequiredClasses() {
1718 final List <Class <?>> requiredClasses = super .getRequiredClasses ();
1819 requiredClasses .add (FunctionalInterfaceTests .TestClass .class );
1920 requiredClasses .add (FunctionalInterfaceTests .StringModifier .class );
21+ requiredClasses .add (FunctionalInterfaceTests .IntModifier .class );
2022 requiredClasses .add (SharedGlobals .class );
23+ requiredClasses .add (Test2 .class );
2124 return requiredClasses ;
2225 }
2326
@@ -27,7 +30,7 @@ public List<String> getRequiredStdLibModules() {
2730 }
2831
2932 @ Test
30- void testFunctionalInterface () {
33+ void testFunctionalInterfaces () {
3134 addScript (
3235 "var modified = modifyString('test', (strings, context) => { return straightUpItself(strings); });\n " +
3336 "println(modified.length);" ,
@@ -41,6 +44,32 @@ void testFunctionalInterface() {
4144 logger .assertPrintOutput (0 , "1" );
4245 }
4346
47+ @ Test
48+ void testFunctionalInterface () {
49+ addScript (
50+ "var modified = modifyStrings([test_module.java_native.Test.instance()]);\n " +
51+ "println(modified.length);" ,
52+ "FunctionalInterfaceTests_testFunctionalInterfaces.zs" );
53+
54+ executeEngine ();
55+
56+ logger .assertNoErrors ();
57+ logger .assertNoWarnings ();
58+ logger .assertPrintOutputSize (1 );
59+ logger .assertPrintOutput (0 , "0" );
60+ }
61+
62+ @ Test
63+ void testFunctionalInterfacesAreDifferent () {
64+ addScript (
65+ "var modified = modifyInts([test_module.java_native.Test.instance()]);\n " ,
66+ "FunctionalInterfaceTests_testFunctionalInterfaces.zs" );
67+
68+ executeEngine (true );
69+ logger .assertHasErrors ();
70+ logger .errors ().assertLineContains (0 , "Cannot implicitly cast Test to function(arg0: List<int?>, arg1: bool): List<int?>" );
71+ }
72+
4473 @ Test
4574 void testBiFunction () {
4675 addScript (
@@ -63,6 +92,16 @@ public static List<String> modifyString(String baseString, StringModifier modifi
6392 return modifier .modify (Collections .singletonList (baseString ), false );
6493 }
6594
95+ @ ZenCodeGlobals .Global
96+ public static List <String > modifyStrings (StringModifier ... modifier ) {
97+ return new ArrayList <>();
98+ }
99+
100+ @ ZenCodeGlobals .Global
101+ public static List <String > modifyInts (IntModifier ... modifier ) {
102+ return new ArrayList <>();
103+ }
104+
66105 @ ZenCodeGlobals .Global
67106 public static List <String > stringFunction (String baseString , BiFunction <List <String >, Boolean , List <String >> function ) {
68107 return function .apply (Collections .singletonList (baseString ), false );
@@ -80,4 +119,29 @@ public interface StringModifier {
80119
81120 List <String > modify (List <String > strings , boolean context );
82121 }
122+
123+ @ FunctionalInterface
124+ @ ZenCodeType .Name ("test_module.java_native.IntModifier" )
125+ public interface IntModifier {
126+ List <Integer > modify (List <Integer > ints , boolean context );
127+ }
128+
129+ @ ZenCodeType .Name ("test_module.java_native.Test" )
130+ public static class Test2 implements StringModifier {
131+
132+ @ ZenCodeType .Constructor
133+ public Test2 () {
134+ }
135+
136+ @ ZenCodeType .Method
137+ public static Test2 instance () {
138+ return new Test2 ();
139+ }
140+
141+ @ Override
142+ public List <String > modify (List <String > strings , boolean context ) {
143+ return Collections .emptyList ();
144+ }
145+ }
146+
83147}
0 commit comments