New J2K: add tests for some obsolete J2K issues

This commit is contained in:
Ilya Kirillov
2019-06-10 18:23:43 +03:00
parent 04fe51b0aa
commit 6d3967d922
29 changed files with 421 additions and 0 deletions
+9
View File
@@ -0,0 +1,9 @@
public class TestReturnsArray {
public String[] strings(int n) {
String[] result = new String[n];
for (int i = 0; i < n; ++i) {
result[i] = Integer.toString(i);
}
return result;
}
}
+9
View File
@@ -0,0 +1,9 @@
class TestReturnsArray {
fun strings(n: Int): Array<String?> {
val result: Array<String?> = arrayOfNulls(n)
for (i in 0 until n) {
result[i] = Integer.toString(i)
}
return result
}
}
+9
View File
@@ -0,0 +1,9 @@
package test;
public class TestAssignmentInReturn {
private String last;
public String foo(String s) {
return last = s;
}
}
+8
View File
@@ -0,0 +1,8 @@
package test
class TestAssignmentInReturn {
private var last: String? = null
fun foo(s: String): String? {
return s.also { last = it }
}
}
+26
View File
@@ -0,0 +1,26 @@
public class TestMutltipleCtorsWithJavadoc {
private String x;
private String y;
// ---
// Constructors
//
/**
* Javadoc for 1st ctor
* @param x
*/
public TestMutltipleCtorsWithJavadoc(String x) {
this.x = x;
}
/**
* Javadoc for 2nd ctor
* @param x
* @param y
*/
public TestMutltipleCtorsWithJavadoc(String x, String y) {
this(x);
this.y = y;
}
}
+22
View File
@@ -0,0 +1,22 @@
class TestMutltipleCtorsWithJavadoc
/**
* Javadoc for 1st ctor
* @param x
*/(private val x: String) {
private var y: String? = null
// ---
// Constructors
//
/**
* Javadoc for 2nd ctor
* @param x
* @param y
*/
constructor(x: String?, y: String?) : this(x!!) {
this.y = y
}
}
+12
View File
@@ -0,0 +1,12 @@
package test;
public class TestIntCompatibleAsArrayIndex {
private byte b;
private short s;
private int[] ints = new int[4];
public void foo(int i) {
ints[b] = i;
ints[s] = i;
}
}
+11
View File
@@ -0,0 +1,11 @@
package test
class TestIntCompatibleAsArrayIndex {
private val b: Byte = 0
private val s: Short = 0
private val ints = IntArray(4)
fun foo(i: Int) {
ints[b.toInt()] = i
ints[s.toInt()] = i
}
}
+5
View File
@@ -0,0 +1,5 @@
public class TestLongOfTwoInts {
public long foo(int x1, int x2) {
return x1 | ((long) x2 << 32);
}
}
+5
View File
@@ -0,0 +1,5 @@
class TestLongOfTwoInts {
fun foo(x1: Int, x2: Int): Long {
return (x1 or (x2.toLong() shl 32).toInt()).toLong()
}
}
+42
View File
@@ -0,0 +1,42 @@
public class TestPackagePrivateFieldInit {
Object start;
Object end;
Object handler;
String desc;
int type;
TestPackagePrivateFieldInit next;
static TestPackagePrivateFieldInit doStuff(TestPackagePrivateFieldInit h, Object start, Object end) {
if (h == null) {
return null;
} else {
h.next = doStuff(h.next, start, end);
}
int hstart = h.start.hashCode();
int hend = h.end.hashCode();
int s = start.hashCode();
int e = end == null ? Integer.MAX_VALUE : end.hashCode();
if (s < hend && e > hstart) {
if (s <= hstart) {
if (e >= hend) {
h = h.next;
} else {
h.start = end;
}
} else if (e >= hend) {
h.end = start;
} else {
TestPackagePrivateFieldInit g = new TestPackagePrivateFieldInit();
g.start = end;
g.end = h.end;
g.handler = h.handler;
g.desc = h.desc;
g.type = h.type;
g.next = h.next;
h.end = start;
h.next = g;
}
}
return h;
}
}
+45
View File
@@ -0,0 +1,45 @@
class TestPackagePrivateFieldInit {
internal var start: Any? = null
internal var end: Any? = null
internal var handler: Any? = null
internal var desc: String? = null
internal var type = 0
internal var next: TestPackagePrivateFieldInit? = null
companion object {
internal fun doStuff(h: TestPackagePrivateFieldInit?, start: Any, end: Any?): TestPackagePrivateFieldInit? {
var h = h
if (h == null) {
return null
} else {
h.next = doStuff(h.next, start, end)
}
val hstart = h.start.hashCode()
val hend = h.end.hashCode()
val s = start.hashCode()
val e = end?.hashCode() ?: Integer.MAX_VALUE
if (s < hend && e > hstart) {
if (s <= hstart) {
if (e >= hend) {
h = h.next
} else {
h.start = end
}
} else if (e >= hend) {
h.end = start
} else {
val g = TestPackagePrivateFieldInit()
g.start = end
g.end = h.end
g.handler = h.handler
g.desc = h.desc
g.type = h.type
g.next = h.next
h.end = start
h.next = g
}
}
return h
}
}
}
+7
View File
@@ -0,0 +1,7 @@
public class TestAssignmentInCondition {
private int i;
public void foo(int x) {
if ((i = x) > 0) System.out.println(">0");
}
}
+6
View File
@@ -0,0 +1,6 @@
class TestAssignmentInCondition {
private var i = 0
fun foo(x: Int) {
if (x.also { i = it } > 0) println(">0")
}
}
+5
View File
@@ -0,0 +1,5 @@
public class TestArithmWithChars {
public int foo(int x) {
return x - '0';
}
}
+5
View File
@@ -0,0 +1,5 @@
class TestArithmWithChars {
fun foo(x: Int): Int {
return x - '0'.toInt()
}
}
+5
View File
@@ -0,0 +1,5 @@
public class TestChar1st {
public int foo(int x) {
return 'z' + x;
}
}
+5
View File
@@ -0,0 +1,5 @@
class TestChar1st {
fun foo(x: Int): Int {
return 'z'.toInt() + x
}
}
+11
View File
@@ -0,0 +1,11 @@
// RUNTIME_WITH_FULL_JDK
import java.util.HashMap;
public class TestMethodReference {
private HashMap<String, String> hashMap = new HashMap<>();
public void update(String key, String msg) {
hashMap.merge(key, msg, String::concat);
}
}
+8
View File
@@ -0,0 +1,8 @@
import java.util.HashMap
class TestMethodReference {
private val hashMap: HashMap<String, String> = HashMap()
fun update(key: String, msg: String) {
hashMap.merge(key, msg) { obj: String, s: String -> obj + s }
}
}
+10
View File
@@ -0,0 +1,10 @@
// RUNTIME_WITH_FULL_JDK
import java.util.HashMap;
public class TestMethodReference {
private HashMap<String, String> hashMap = new HashMap<>();
public void update(String key, String msg) {
hashMap.merge(key, msg, String::concat);
}
}
+8
View File
@@ -0,0 +1,8 @@
import java.util.HashMap
class TestMethodReference {
private val hashMap: HashMap<String, String> = HashMap()
fun update(key: String, msg: String) {
hashMap.merge(key, msg) { obj: String, s: String -> obj + s }
}
}
+13
View File
@@ -0,0 +1,13 @@
// RUNTIME_WITH_FULL_JDK
import javax.swing.tree.DefaultMutableTreeNode;
import java.util.Enumeration;
public class TestJavaExpectedTypeInference {
public void test(DefaultMutableTreeNode node) {
for (Enumeration<DefaultMutableTreeNode> e = node.children(); e.hasMoreElements(); ) {
DefaultMutableTreeNode child = e.nextElement();
String name = (String) child.getUserObject();
System.out.println(name);
}
}
}
+14
View File
@@ -0,0 +1,14 @@
// ERROR: Type mismatch: inferred type is Enumeration<(raw) Any!>! but Enumeration<DefaultMutableTreeNode?>? was expected
import java.util.Enumeration
import javax.swing.tree.DefaultMutableTreeNode
class TestJavaExpectedTypeInference {
fun test(node: DefaultMutableTreeNode) {
val e: Enumeration<DefaultMutableTreeNode?>? = node.children()
while (e!!.hasMoreElements()) {
val child = e.nextElement()
val name = child!!.userObject as String
println(name)
}
}
}
+12
View File
@@ -0,0 +1,12 @@
// RUNTIME_WITH_FULL_JDK
import java.awt.image.AreaAveragingScaleFilter;
public class TestInterfaceStaticFieldReference extends AreaAveragingScaleFilter {
public TestInterfaceStaticFieldReference(int width, int height) {
super(width, height);
}
public void test() {
System.out.println(TOPDOWNLEFTRIGHT);
}
}
+9
View File
@@ -0,0 +1,9 @@
import java.awt.image.AreaAveragingScaleFilter
import java.awt.image.ImageConsumer
class TestInterfaceStaticFieldReference(width: Int, height: Int) :
AreaAveragingScaleFilter(width, height) {
fun test() {
println(ImageConsumer.TOPDOWNLEFTRIGHT)
}
}
+10
View File
@@ -0,0 +1,10 @@
public class ArrayInitializerBugKt {
private static final byte[] GREETING = { 'H', 'e', 'l', 'l', 'o', ',', ' ', 'b', 'u', 'g', '!' };
public static void main(String... args) {
String greeting = new String(GREETING);
System.out.println(greeting);
}
}
+20
View File
@@ -0,0 +1,20 @@
object ArrayInitializerBugKt {
private val GREETING = byteArrayOf(
'H'.toByte(),
'e'.toByte(),
'l'.toByte(),
'l'.toByte(),
'o'.toByte(),
','.toByte(),
' '.toByte(),
'b'.toByte(),
'u'.toByte(),
'g'.toByte(),
'!'.toByte()
)
fun main(vararg args: String?) {
val greeting = String(GREETING)
println(greeting)
}
}
@@ -2691,16 +2691,86 @@ public class NewJavaToKotlinConverterSingleFileTestGenerated extends AbstractNew
runTest("nj2k/testData/newJ2k/issues/kt-17379.java");
}
@TestMetadata("kt-19336.java")
public void testKt_19336() throws Exception {
runTest("nj2k/testData/newJ2k/issues/kt-19336.java");
}
@TestMetadata("kt-19346.java")
public void testKt_19346() throws Exception {
runTest("nj2k/testData/newJ2k/issues/kt-19346.java");
}
@TestMetadata("kt-19348.java")
public void testKt_19348() throws Exception {
runTest("nj2k/testData/newJ2k/issues/kt-19348.java");
}
@TestMetadata("kt-19352.java")
public void testKt_19352() throws Exception {
runTest("nj2k/testData/newJ2k/issues/kt-19352.java");
}
@TestMetadata("kt-19353.java")
public void testKt_19353() throws Exception {
runTest("nj2k/testData/newJ2k/issues/kt-19353.java");
}
@TestMetadata("kt-19357.java")
public void testKt_19357() throws Exception {
runTest("nj2k/testData/newJ2k/issues/kt-19357.java");
}
@TestMetadata("kt-19358.java")
public void testKt_19358() throws Exception {
runTest("nj2k/testData/newJ2k/issues/kt-19358.java");
}
@TestMetadata("kt-19359.java")
public void testKt_19359() throws Exception {
runTest("nj2k/testData/newJ2k/issues/kt-19359.java");
}
@TestMetadata("kt-19363.java")
public void testKt_19363() throws Exception {
runTest("nj2k/testData/newJ2k/issues/kt-19363.java");
}
@TestMetadata("kt-19604.java")
public void testKt_19604() throws Exception {
runTest("nj2k/testData/newJ2k/issues/kt-19604.java");
}
@TestMetadata("kt-19606.java")
public void testKt_19606() throws Exception {
runTest("nj2k/testData/newJ2k/issues/kt-19606.java");
}
@TestMetadata("kt-19634.java")
public void testKt_19634() throws Exception {
runTest("nj2k/testData/newJ2k/issues/kt-19634.java");
}
@TestMetadata("kt-19639.java")
public void testKt_19639() throws Exception {
runTest("nj2k/testData/newJ2k/issues/kt-19639.java");
}
@TestMetadata("kt-19652.java")
public void testKt_19652() throws Exception {
runTest("nj2k/testData/newJ2k/issues/kt-19652.java");
}
@TestMetadata("kt-19943.java")
public void testKt_19943() throws Exception {
runTest("nj2k/testData/newJ2k/issues/kt-19943.java");
}
@TestMetadata("kt-21189.java")
public void testKt_21189() throws Exception {
runTest("nj2k/testData/newJ2k/issues/kt-21189.java");
}
@TestMetadata("kt-31818.java")
public void testKt_31818() throws Exception {
runTest("nj2k/testData/newJ2k/issues/kt-31818.java");