package jetbrains.mps.closures.test; /*Generated by MPS */ import junit.framework.TestCase; import jetbrains.mps.baseLanguage.closures.runtime._FunctionTypes; import jetbrains.mps.baseLanguage.closures.util.Constants; import jetbrains.mps.baseLanguage.closures.runtime.Wrappers; import junit.framework.Assert; public class FunctionTypes_Test extends TestCase { public void test_functionTypeAdapter_simple() throws Exception { _FunctionTypes._return_P0_E0<? extends Integer> fun1 = new _FunctionTypes._return_P0_E0<Integer>() { public Integer invoke() { return 1; } }; _FunctionTypes._return_P0_E0<? extends Integer> fun2 = fun1; _FunctionTypes._return_P0_E0<? extends Number> fun3 = fun1; fun3 = fun2; this.accept_int(fun1); this.accept_int(fun2); this.accept_Integer(fun2); this.accept_Number(fun2); this.accept_int(new _FunctionTypes._return_P0_E0<Integer>() { public Integer invoke() { return 1; } }); this.accept_Integer(new _FunctionTypes._return_P0_E0<Integer>() { public Integer invoke() { return (Integer) 1; } }); this.accept_Number(new _FunctionTypes._return_P0_E0<Integer>() { public Integer invoke() { return (Integer) 1; } }); } public void test_exceptions() throws Exception { _FunctionTypes._void_P0_E1<? extends Exception> throwsException = new _FunctionTypes._void_P0_E1<Exception>() { public void invoke() throws Exception { throw new Exception(); } }; _FunctionTypes._void_P0_E1<? extends InterruptedException> throwsRuntimeException = new _FunctionTypes._void_P0_E1<InterruptedException>() { public void invoke() throws InterruptedException { throw new InterruptedException(); } }; throwsException = throwsRuntimeException; _FunctionTypes._void_P0_E0 throwsOne = new _FunctionTypes._void_P0_E0() { public void invoke() { throw new IllegalArgumentException(); } }; _FunctionTypes._void_P0_E2<? extends IllegalAccessException, ? extends InterruptedException> throwsTwo = new _FunctionTypes._void_P0_E2<IllegalAccessException, InterruptedException>() { public void invoke() throws IllegalAccessException, InterruptedException { if (0 == 0) { throw new InterruptedException(); } else { throw new IllegalAccessException(); } } }; if (!(Constants.ONLY_CLOSURE_LITERAL_AS_FUNCTION_TYPE)) { } } public void test_exceptionsYield() throws Exception { if (!(Constants.ONLY_CLOSURE_LITERAL_AS_FUNCTION_TYPE)) { } } public void test_functionTypeAdapter_complex() throws Exception { _FunctionTypes._return_P1_E0<? extends Integer, ? super Integer> fun1 = new _FunctionTypes._return_P1_E0<Integer, Integer>() { public Integer invoke(Integer i) { return i.intValue(); } }; _FunctionTypes._return_P1_E0<? extends Integer, ? super Integer> fun2 = new _FunctionTypes._return_P1_E0<Integer, Integer>() { public Integer invoke(Integer i) { return Integer.valueOf(i); } }; fun1 = fun2; fun2 = fun1; _FunctionTypes._return_P1_E0<? extends Integer, ? super Object> fun3 = new _FunctionTypes._return_P1_E0<Integer, Object>() { public Integer invoke(Object o) { return o.hashCode(); } }; _FunctionTypes._return_P1_E0<? extends Integer, ? super String> fun4 = new _FunctionTypes._return_P1_E0<Integer, String>() { public Integer invoke(String s) { return s.length(); } }; fun4 = fun3; this.accept_int_from_int(new _FunctionTypes._return_P1_E0<Integer, Integer>() { public Integer invoke(Integer i) { return i.intValue(); } }); this.accept_int_from_int(fun1); this.accept_int_from_int(fun2); this.accept_int_from_Integer(new _FunctionTypes._return_P1_E0<Integer, Integer>() { public Integer invoke(Integer i) { return Integer.valueOf(i); } }); this.accept_int_from_Integer(fun1); this.accept_int_from_Integer(fun2); this.accept_Integer_from_int(new _FunctionTypes._return_P1_E0<Integer, Integer>() { public Integer invoke(Integer i) { return i.intValue(); } }); this.accept_Integer_from_int(fun1); this.accept_Integer_from_int(fun2); this.accept_Integer_from_Object(new _FunctionTypes._return_P1_E0<Integer, Object>() { public Integer invoke(Object o) { return o.hashCode(); } }); this.accept_Integer_from_Object(fun3); this.accept_Number_from_String(new _FunctionTypes._return_P1_E0<Integer, String>() { public Integer invoke(String s) { return s.length(); } }); this.accept_Number_from_String(new _FunctionTypes._return_P1_E0<Integer, Object>() { public Integer invoke(Object o) { return o.hashCode(); } }); this.accept_Number_from_String(fun3); this.accept_Number_from_String(fun4); } public void test_return_null() throws Exception { final Wrappers._boolean b = new Wrappers._boolean(true); _FunctionTypes._return_P0_E0<? extends String> ret_string = new _FunctionTypes._return_P0_E0<String>() { public String invoke() { if (b.value) { return "foo"; } else { return null; } } }; Assert.assertSame("foo", ret_string.invoke()); b.value = false; Assert.assertNull(ret_string.invoke()); ret_string = new _FunctionTypes._return_P0_E0<String>() { public String invoke() { return null; } }; Assert.assertNull(ret_string.invoke()); } public void test_specifiedInterface() throws Exception { _FunctionTypes._return_P1_E0<? extends Integer, ? super Boolean> ssdf = new _FunctionTypes._return_P1_E0<Integer, Boolean>() { public Integer invoke(Boolean b) { return 0; } }; } public FunctionTypes_Test() { } public void accept_int(_FunctionTypes._return_P0_E0<? extends Integer> fun) { } public void accept_Integer(_FunctionTypes._return_P0_E0<? extends Integer> fun) { } public void accept_Number(_FunctionTypes._return_P0_E0<? extends Number> fun) { } public void accept_int_from_int(_FunctionTypes._return_P1_E0<? extends Integer, ? super Integer> fun) { } public void accept_int_from_Integer(_FunctionTypes._return_P1_E0<? extends Integer, ? super Integer> fun) { } public void accept_Integer_from_int(_FunctionTypes._return_P1_E0<? extends Integer, ? super Integer> fun) { } public void accept_Integer_from_Object(_FunctionTypes._return_P1_E0<? extends Integer, ? super Object> fun) { } public void accept_Number_from_String(_FunctionTypes._return_P1_E0<? extends Number, ? super String> fun) { } }