Reorganized SAM-related test data.

This commit is contained in:
Evgeny Gerashchenko
2013-06-27 23:10:09 +04:00
parent 8a51f908f7
commit e017645c97
130 changed files with 364 additions and 358 deletions

View File

@@ -0,0 +1,3 @@
interface JavaInterface {
void run(Runnable r);
}

View File

@@ -0,0 +1,11 @@
class Impl: JavaInterface {
override fun run(r: Runnable?) {
r?.run()
}
}
fun box(): String {
var v = "FAIL"
Impl().run { v = "OK" }
return v
}

View File

@@ -0,0 +1,7 @@
import java.util.*;
class JavaClass {
public static void sortIntList(List<Integer> list, Comparator<Integer> comparator) {
Collections.sort(list, comparator);
}
}

View File

@@ -0,0 +1,8 @@
import java.util.*
fun box(): String {
val list = ArrayList(Arrays.asList(3, 2, 4, 8, 1, 5))
val expected = ArrayList(Arrays.asList(8, 5, 4, 3, 2, 1))
JavaClass.sortIntList(list, { a, b -> b - a })
return if (list == expected) "OK" else list.toString()
}

View File

@@ -0,0 +1,11 @@
class JavaClass {
private Runnable r;
public JavaClass(Runnable r) {
this.r = r;
}
public void run() {
r.run();
}
}

View File

@@ -0,0 +1,5 @@
fun box(): String {
var v = "FAIL"
JavaClass { v = "OK" }.run()
return v
}

View File

@@ -0,0 +1,7 @@
import java.io.*;
class JavaClass {
public static String invokeFilter(FileFilter f, File file1, File file2) {
return f.accept(file1) + " " + f.accept(file2);
}
}

View File

@@ -0,0 +1,11 @@
import java.io.*
fun box(): String {
val ACCEPT_NAME = "test"
val WRONG_NAME = "wrong"
val result = JavaClass.invokeFilter({ file -> ACCEPT_NAME == file?.getName() }, File(ACCEPT_NAME), File(WRONG_NAME))
if (result != "true false") return "Wrong result: $result"
return "OK"
}

View File

@@ -0,0 +1,5 @@
class JavaClass {
public void run(Runnable r) {
r.run();
}
}

View File

@@ -0,0 +1,8 @@
class KotlinSubclass: JavaClass() {
}
fun box(): String {
var v = "FAIL"
KotlinSubclass().run { v = "OK" }
return v
}

View File

@@ -0,0 +1,13 @@
class Super {
public String lastCalled = null;
void foo(Runnable r) {
lastCalled = "super";
}
}
class Sub extends Super {
void foo(jet.Function0<jet.Unit> r) {
lastCalled = "sub";
}
}

View File

@@ -0,0 +1,15 @@
fun box(): String {
val sub = Sub()
(sub : Super).foo{ }
if (sub.lastCalled != "super") {
return "FAIL: ${sub.lastCalled} instead of super"
}
sub.foo{ }
if (sub.lastCalled != "sub") {
return "FAIL: ${sub.lastCalled} instead of sub"
}
return "OK"
}

View File

@@ -0,0 +1,7 @@
class Super {
public String lastCalled = null;
void foo(Runnable r) {
lastCalled = "super";
}
}

View File

@@ -0,0 +1,21 @@
class Sub() : Super() {
override fun foo(r : (() -> Unit)?) {
lastCalled = "sub"
}
}
fun box(): String {
val sub = Sub()
(sub : Super).foo{ }
if (sub.lastCalled != "super") {
return "FAIL: ${sub.lastCalled} instead of super"
}
sub.foo{ }
if (sub.lastCalled != "sub") {
return "FAIL: ${sub.lastCalled} instead of sub"
}
return "OK"
}

View File

@@ -0,0 +1,8 @@
class Super {
void safeInvoke(Runnable r) {
if (r != null) r.run();
}
}
class Sub extends Super {
}

View File

@@ -0,0 +1,7 @@
fun box(): String {
var r = "FAIL"
val sub = Sub()
sub.safeInvoke(null)
sub.safeInvoke { r = "OK" }
return r
}

View File

@@ -0,0 +1,6 @@
class JavaClass {
public static void run(Runnable r1, Runnable r2) {
r1.run();
r2.run();
}
}

View File

@@ -0,0 +1,6 @@
fun box(): String {
var v = "FAIL"
val f = { v = "O" }
JavaClass.run(f, { v += "K" })
return v
}

View File

@@ -0,0 +1,7 @@
import java.util.*;
class JavaClass {
public static void sortIntList(List<Integer> list, Comparator<Integer> comparator) {
Collections.sort(list, comparator);
}
}

View File

@@ -0,0 +1,10 @@
import java.util.*
fun box(): String {
val list = ArrayList(Arrays.asList(3, 2, 4, 8, 1, 5))
val expected = ArrayList(Arrays.asList(8, 5, 4, 3, 2, 1))
val f = { (a: Int, b: Int) -> b - a }
JavaClass.sortIntList(list, f)
return if (list == expected) "OK" else list.toString()
}

View File

@@ -0,0 +1,11 @@
class JavaClass {
private Runnable r;
public JavaClass(Runnable r) {
this.r = r;
}
public void run() {
r.run();
}
}

View File

@@ -0,0 +1,6 @@
fun box(): String {
var v = "FAIL"
val f = { v = "OK" }
JavaClass(f).run()
return v
}

View File

@@ -0,0 +1,5 @@
class JavaClass {
public static String run(Runnable r) {
return r == null ? "OK" : "FAIL";
}
}

View File

@@ -0,0 +1,4 @@
fun box(): String {
val f: (() -> Unit)? = null
return JavaClass.run(f)!!
}

View File

@@ -0,0 +1,5 @@
class JavaClass {
public static void run(Runnable r) {
r.run();
}
}

View File

@@ -0,0 +1,6 @@
fun box(): String {
var v = "FAIL"
val f = { v = "OK" }
JavaClass.run(f)
return v
}

View File

@@ -0,0 +1,40 @@
import org.jetbrains.annotations.NotNull;
class Container {
@NotNull
Value get(Runnable i) {
i.run();
return new Value();
}
void set(Runnable i, @NotNull Value value) {
i.run();
}
}
class Value {
@NotNull Value plus(Runnable i) {
i.run();
return this;
}
@NotNull Value minus(Runnable i) {
i.run();
return this;
}
@NotNull Value times(Runnable i) {
i.run();
return this;
}
@NotNull Value div(Runnable i) {
i.run();
return this;
}
@NotNull Value mod(Runnable i) {
i.run();
return this;
}
}

View File

@@ -0,0 +1,30 @@
fun box(): String {
var c = Container()
var indexAccess = 0
// TODO uncomment when KT-3723 is fixed
//var v1 = "FAIL"
//c[{ indexAccess++ }] += { v1 = "OK" }
//if (v1 != "OK") return "plus: $v1"
//
//var v2 = "FAIL"
//c[{ indexAccess++ }] -= { v2 = "OK" }
//if (v2 != "OK") return "minus: $v2"
//
//var v3 = "FAIL"
//c[{ indexAccess++ }] *= { v3 = "OK" }
//if (v3 != "OK") return "times: $v3"
//
//var v4 = "FAIL"
//c[{ indexAccess++ }] /= { v4 = "OK" }
//if (v4 != "OK") return "div: $v4"
//
//var v5 = "FAIL"
//c[{ indexAccess++ }] %= { v5 = "OK" }
//if (v5 != "OK") return "mod: $v5"
//
//if (indexAccess != 10) return indexAccess
return "OK"
}

View File

@@ -0,0 +1,21 @@
class JavaClass {
void plusAssign(Runnable i) {
i.run();
}
void minusAssign(Runnable i) {
i.run();
}
void timesAssign(Runnable i) {
i.run();
}
void divAssign(Runnable i) {
i.run();
}
void modAssign(Runnable i) {
i.run();
}
}

View File

@@ -0,0 +1,25 @@
fun box(): String {
val obj = JavaClass()
var v1 = "FAIL"
obj += { v1 = "OK" }
if (v1 != "OK") return "plus: $v1"
var v2 = "FAIL"
obj -= { v2 = "OK" }
if (v2 != "OK") return "minus: $v2"
var v3 = "FAIL"
obj *= { v3 = "OK" }
if (v3 != "OK") return "times: $v3"
var v4 = "FAIL"
obj /= { v4 = "OK" }
if (v4 != "OK") return "div: $v4"
var v5 = "FAIL"
obj %= { v5 = "OK" }
if (v5 != "OK") return "mod: $v5"
return "OK"
}

View File

@@ -0,0 +1,26 @@
class JavaClass {
JavaClass plus(Runnable i) {
i.run();
return this;
}
JavaClass minus(Runnable i) {
i.run();
return this;
}
JavaClass times(Runnable i) {
i.run();
return this;
}
JavaClass div(Runnable i) {
i.run();
return this;
}
JavaClass mod(Runnable i) {
i.run();
return this;
}
}

View File

@@ -0,0 +1,25 @@
fun box(): String {
var obj = JavaClass()
var v1 = "FAIL"
obj += { v1 = "OK" }
if (v1 != "OK") return "plus: $v1"
var v2 = "FAIL"
obj -= { v2 = "OK" }
if (v2 != "OK") return "minus: $v2"
var v3 = "FAIL"
obj *= { v3 = "OK" }
if (v3 != "OK") return "times: $v3"
var v4 = "FAIL"
obj /= { v4 = "OK" }
if (v4 != "OK") return "div: $v4"
var v5 = "FAIL"
obj %= { v5 = "OK" }
if (v5 != "OK") return "mod: $v5"
return "OK"
}

View File

@@ -0,0 +1,31 @@
class JavaClass {
JavaClass plus(Runnable i) {
i.run();
return this;
}
JavaClass minus(Runnable i) {
i.run();
return this;
}
JavaClass times(Runnable i) {
i.run();
return this;
}
JavaClass div(Runnable i) {
i.run();
return this;
}
JavaClass mod(Runnable i) {
i.run();
return this;
}
JavaClass rangeTo(Runnable i) {
i.run();
return this;
}
}

View File

@@ -0,0 +1,29 @@
fun box(): String {
val obj = JavaClass()
var v1 = "FAIL"
obj + { v1 = "OK" }
if (v1 != "OK") return "plus: $v1"
var v2 = "FAIL"
obj - { v2 = "OK" }
if (v2 != "OK") return "minus: $v2"
var v3 = "FAIL"
obj * { v3 = "OK" }
if (v3 != "OK") return "times: $v3"
var v4 = "FAIL"
obj / { v4 = "OK" }
if (v4 != "OK") return "div: $v4"
var v5 = "FAIL"
obj % { v5 = "OK" }
if (v5 != "OK") return "mod: $v5"
var v6 = "FAIL"
obj .. { v6 = "OK" }
if (v6 != "OK") return "rangeTo: $v6"
return "OK"
}

View File

@@ -0,0 +1,6 @@
class JavaClass {
int compareTo(Runnable i) {
i.run();
return 239;
}
}

View File

@@ -0,0 +1,21 @@
fun box(): String {
val obj = JavaClass()
var v1 = "FAIL"
obj < { v1 = "OK" }
if (v1 != "OK") return "<: $v1"
var v2 = "FAIL"
obj > { v2 = "OK" }
if (v2 != "OK") return ">: $v2"
var v3 = "FAIL"
obj <= { v3 = "OK" }
if (v3 != "OK") return "<=: $v3"
var v4 = "FAIL"
obj >= { v4 = "OK" }
if (v4 != "OK") return ">=: $v4"
return "OK"
}

View File

@@ -0,0 +1,6 @@
class JavaClass {
boolean contains(Runnable i) {
i.run();
return true;
}
}

View File

@@ -0,0 +1,8 @@
fun box(): String {
val obj = JavaClass()
var v = "FAIL"
{ v = "O" } in obj
{ v += "K" } !in obj
return v
}

View File

@@ -0,0 +1,6 @@
class JavaClass {
int get(Runnable i) {
i.run();
return 239;
}
}

View File

@@ -0,0 +1,7 @@
fun box(): String {
val obj = JavaClass()
var v = "FAIL"
obj[{ v = "OK" }]
return v
}

View File

@@ -0,0 +1,5 @@
class JavaClass {
void doSomething(Runnable i) {
i.run();
}
}

View File

@@ -0,0 +1,7 @@
fun box(): String {
val obj = JavaClass()
var v = "FAIL"
obj doSomething { v = "OK" }
return v
}

View File

@@ -0,0 +1,5 @@
class JavaClass {
void invoke(Runnable i) {
i.run();
}
}

View File

@@ -0,0 +1,8 @@
fun box(): String {
val obj = JavaClass()
var v = "FAIL"
obj({ v = "O" })
obj { v += "K" }
return v
}

View File

@@ -0,0 +1,13 @@
class JavaClass {
int get(Runnable i1, Runnable i2) {
i1.run();
i2.run();
return 239;
}
void set(Runnable i1, Runnable i2, Runnable value) {
i1.run();
i2.run();
value.run();
}
}

View File

@@ -0,0 +1,13 @@
fun box(): String {
val obj = JavaClass()
var v1 = "FAIL"
obj[{ v1 = "O" }, { v1 += "K" }]
if (v1 != "OK") return "get: $v1"
var v2 = "FAIL"
obj[{ v2 = "" }, { v2 += "O" }] = { v2 += "K" }
if (v2 != "OK") return "set: $v2"
return "OK"
}

View File

@@ -0,0 +1,6 @@
class JavaClass {
void invoke(Runnable p1, Runnable p2) {
p1.run();
p2.run();
}
}

View File

@@ -0,0 +1,7 @@
fun box(): String {
val obj = JavaClass()
var v = "FAIL"
obj({ v = "O" }, { v += "K" })
return v
}

View File

@@ -0,0 +1,6 @@
class JavaClass {
void set(Runnable i, Runnable value) {
i.run();
value.run();
}
}

View File

@@ -0,0 +1,7 @@
fun box(): String {
val obj = JavaClass()
var v = "FAIL"
obj[{ v = "O" }] = { v += "K" }
return v
}

View File

@@ -0,0 +1,9 @@
import java.util.*;
class JavaClass {
public static String findMaxAndInvokeCallback(Comparator<String> comparator, String a, String b, Runnable afterRunnable) {
int compare = comparator.compare(a, b);
afterRunnable.run();
return compare > 0 ? a : b;
}
}

View File

@@ -0,0 +1,6 @@
fun box(): String {
var v = "FAIL"
val max = JavaClass.findMaxAndInvokeCallback({ a, b -> a.length - b.length }, "foo", "kotlin", { v = "OK" })
if (max != "kotlin") return "Wrong max: $max"
return v
}

View File

@@ -0,0 +1,5 @@
class JavaClass {
public static void run(Runnable r) {
r.run();
}
}

View File

@@ -0,0 +1,5 @@
fun box(): String {
var v = "FAIL"
JavaClass.run { v = "OK" }
return v
}

View File

@@ -0,0 +1,5 @@
class JavaClass {
JavaClass(Runnable r) {
if (r != null) r.run();
}
}

View File

@@ -0,0 +1,7 @@
class KotlinClass(): JavaClass(null) {
}
fun box(): String {
KotlinClass()
return "OK"
}

View File

@@ -0,0 +1,7 @@
import java.util.*;
class WeirdComparator<T> {
public T max(Comparator<T> comparator, T value1, T value2) {
return comparator.compare(value1, value2) > 0 ? value1 : value2;
}
}

View File

@@ -0,0 +1,6 @@
fun box(): String {
val wc = WeirdComparator<String>()
val result = wc.max({ a, b -> a.length - b.length }, "java", "kotlin")
if (result != "kotlin") return "Wrong: $result"
return "OK"
}

View File

@@ -0,0 +1,11 @@
import java.util.*;
class WeirdComparator {
public static <T> T max(Comparator<T> comparator, T value1, T value2) {
return comparator.compare(value1, value2) > 0 ? value1 : value2;
}
public static <T extends CharSequence> T max2(Comparator<T> comparator, T value1, T value2) {
return comparator.compare(value1, value2) > 0 ? value1 : value2;
}
}

View File

@@ -0,0 +1,9 @@
fun box(): String {
val result = WeirdComparator.max<String>({ a, b -> a.length - b.length }, "java", "kotlin")
if (result != "kotlin") return "Wrong: $result"
val result2 = WeirdComparator.max2<String>({ a, b -> a.length - b.length }, "java", "kotlin")
if (result2 != "kotlin") return "Wrong: $result"
return "OK"
}

View File

@@ -0,0 +1,13 @@
import java.util.*;
class WeirdComparator<T> {
public Inner createInner() {
return new Inner();
}
public class Inner {
public T max(Comparator<T> comparator, T value1, T value2) {
return comparator.compare(value1, value2) > 0 ? value1 : value2;
}
}
}

View File

@@ -0,0 +1,6 @@
fun box(): String {
val wc = WeirdComparator<String>().createInner()!!
val result = wc.max({ a, b -> a.length - b.length }, "java", "kotlin")
if (result != "kotlin") return "Wrong: $result"
return "OK"
}

View File

@@ -0,0 +1,5 @@
class Custom {
public interface Runnable {
void run2();
}
}

View File

@@ -0,0 +1,7 @@
fun box(): String {
val f = { }
val class1 = Runnable(f).getClass()
val class2 = Custom.Runnable(f).getClass()
return if (class1 != class2) "OK" else "Same class: $class1"
}