fun String?.plus(other: Any?) : String
This commit is contained in:
@@ -26,6 +26,41 @@ public class FunctionGenTest extends CodegenTestCase {
|
||||
|
||||
}
|
||||
|
||||
public void testNullableAnyToString () throws InvocationTargetException, IllegalAccessException {
|
||||
loadText("fun foo(x: Any?) = x.toString()");
|
||||
System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
assertEquals("something", foo.invoke(null, "something"));
|
||||
assertEquals("null", foo.invoke(null, new Object[]{null}));
|
||||
|
||||
}
|
||||
|
||||
public void testNullableStringPlus () throws InvocationTargetException, IllegalAccessException {
|
||||
loadText("fun foo(x: String?, y: Any?) = x + y");
|
||||
String text = generateToText();
|
||||
assertTrue(text.contains(".stringPlus"));
|
||||
System.out.println(text);
|
||||
Method foo = generateFunction();
|
||||
assertEquals("something239", foo.invoke(null, "something", 239));
|
||||
assertEquals("null239", foo.invoke(null, null, 239));
|
||||
assertEquals("239null", foo.invoke(null, "239", null));
|
||||
assertEquals("nullnull", foo.invoke(null, null, null));
|
||||
|
||||
}
|
||||
|
||||
public void testNonNullableStringPlus () throws InvocationTargetException, IllegalAccessException {
|
||||
loadText("fun foo(x: String, y: Any?) = x + y + 120");
|
||||
String text = generateToText();
|
||||
assertFalse(text.contains(".stringPlus"));
|
||||
System.out.println(text);
|
||||
Method foo = generateFunction();
|
||||
assertEquals("something239120", foo.invoke(null, "something", 239));
|
||||
assertEquals("null239120", foo.invoke(null, null, 239));
|
||||
assertEquals("239null120", foo.invoke(null, "239", null));
|
||||
assertEquals("nullnull120", foo.invoke(null, null, null));
|
||||
|
||||
}
|
||||
|
||||
public void testAnyEqualsNullable () throws InvocationTargetException, IllegalAccessException {
|
||||
loadText("fun foo(x: Any?) = x.equals(\"lala\")");
|
||||
System.out.println(generateToText());
|
||||
|
||||
Reference in New Issue
Block a user