Migrate boxWithJava tests to multi-file framework
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
// FILE: Simple.java
|
||||
|
||||
public interface Simple {
|
||||
default String test(String s) {
|
||||
return s + "K";
|
||||
}
|
||||
|
||||
static String testStatic(String s) {
|
||||
return s + "K";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
interface KInterface : Simple {
|
||||
fun bar(): String {
|
||||
return test("O") + Simple.testStatic("O")
|
||||
}
|
||||
}
|
||||
|
||||
class Test : KInterface {}
|
||||
|
||||
fun box(): String {
|
||||
val test = Test().bar()
|
||||
if (test != "OKOK") return "fail $test"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// FILE: Simple.java
|
||||
|
||||
interface Simple {
|
||||
default String test(String s) {
|
||||
return s + "K";
|
||||
}
|
||||
|
||||
static String testStatic(String s) {
|
||||
return s + "K";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
class Test : Simple {}
|
||||
|
||||
fun box(): String {
|
||||
val test = Test().test("O")
|
||||
if (test != "OK") return "fail $test"
|
||||
|
||||
return Simple.testStatic("O")
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// FILE: Simple.java
|
||||
|
||||
public interface Simple {
|
||||
default String test(String s) {
|
||||
return s + "K";
|
||||
}
|
||||
|
||||
static String testStatic(String s) {
|
||||
return s + "K";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
interface TestInterface : Simple {}
|
||||
class Test : TestInterface {}
|
||||
|
||||
fun box(): String {
|
||||
val test = Test().test("O")
|
||||
if (test != "OK") return "fail $test"
|
||||
|
||||
return Simple.testStatic("O")
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// FILE: Simple.java
|
||||
|
||||
public interface Simple {
|
||||
default String test(String s) {
|
||||
return s + "Fail";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
interface KInterface: Simple {
|
||||
override fun test(s: String): String {
|
||||
return s + "K"
|
||||
}
|
||||
}
|
||||
|
||||
class Test : KInterface {
|
||||
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return Test().test("O")
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// FILE: Test.java
|
||||
|
||||
interface Test<T> {
|
||||
|
||||
T call();
|
||||
|
||||
default T testDefault(T p) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
class Child : Test<String> {
|
||||
override fun call() : String {
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
fun box(): String {
|
||||
val res = Child().call()
|
||||
if (res != "OK") return "fail $res"
|
||||
|
||||
return Child().testDefault("OK")
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// FILE: Simple.java
|
||||
|
||||
interface Simple extends KInterface {
|
||||
default String test() {
|
||||
return "simple";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
interface KInterface {
|
||||
fun test(): String {
|
||||
return "base";
|
||||
}
|
||||
}
|
||||
|
||||
class Test : Simple {
|
||||
fun bar(): String {
|
||||
return super.test()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val test = Test().test()
|
||||
if (test != "simple") return "fail $test"
|
||||
|
||||
val bar = Test().bar()
|
||||
if (bar != "simple") return "fail 2 $bar"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// FILE: Test.java
|
||||
|
||||
public interface Test {
|
||||
default String test() {
|
||||
return "OK";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
interface KInterface : Test {
|
||||
|
||||
}
|
||||
|
||||
class KClass : Test {
|
||||
fun ktest(): String {
|
||||
return super.test() + test()
|
||||
}
|
||||
}
|
||||
|
||||
class KTClass : KInterface {
|
||||
fun ktest(): String {
|
||||
return super.test() + test()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val p = object : KInterface {
|
||||
fun ktest(): String {
|
||||
return super.test() + test()
|
||||
}
|
||||
}.ktest()
|
||||
|
||||
if (p != "OKOK") return "fail1: $p"
|
||||
|
||||
if (KClass().ktest() != "OKOK") return "fail 2: ${KClass().ktest()}"
|
||||
|
||||
if (KTClass().ktest() != "OKOK") return "fail 3: ${KTClass().ktest()}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// FILE: Base.java
|
||||
|
||||
public interface Base {
|
||||
default String foo() {
|
||||
return "OK";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: derived.kt
|
||||
|
||||
interface K1 : Base
|
||||
|
||||
interface K2 : K1
|
||||
|
||||
interface K3 : K2
|
||||
|
||||
class C : K3 {
|
||||
override fun foo() = super.foo()
|
||||
}
|
||||
|
||||
fun box(): String = C().foo()
|
||||
@@ -0,0 +1,24 @@
|
||||
// FILE: J.java
|
||||
|
||||
public class J {
|
||||
public J(String constructorParam) {}
|
||||
|
||||
public static void foo(int methodParam) {}
|
||||
}
|
||||
|
||||
// FILE: K.kt
|
||||
// JAVAC_OPTIONS: -parameters
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun box(): String {
|
||||
val methodParam = J::foo.parameters.single()
|
||||
if (methodParam.name == null) return "Fail: method parameter has no name"
|
||||
assertEquals("methodParam", methodParam.name)
|
||||
|
||||
val constructorParam = J::class.constructors.single().parameters.single()
|
||||
if (constructorParam.name == null) return "Fail: constructor parameter has no name"
|
||||
assertEquals("constructorParam", constructorParam.name)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// FILE: J.java
|
||||
|
||||
public class J {
|
||||
public J(String constructorParam) {}
|
||||
|
||||
public static void foo(int methodParam) {}
|
||||
}
|
||||
|
||||
// FILE: K.kt
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun box(): String {
|
||||
val methodParam = J::foo.parameters.single()
|
||||
if (methodParam.name == null) return "Fail: method parameter has no name"
|
||||
assertEquals("arg0", methodParam.name)
|
||||
|
||||
val constructorParam = J::class.constructors.single().parameters.single()
|
||||
if (constructorParam.name == null) return "Fail: constructor parameter has no name"
|
||||
assertEquals("arg0", constructorParam.name)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// FILE: JavaCall.java
|
||||
|
||||
class JavaCall {
|
||||
String call(Test test) {
|
||||
return test.call();
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: Test.java
|
||||
|
||||
interface Test {
|
||||
|
||||
String call();
|
||||
|
||||
default String test() {
|
||||
return "K";
|
||||
}
|
||||
|
||||
static String testStatic() {
|
||||
return "K";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: sam.kt
|
||||
|
||||
fun box(): String {
|
||||
return JavaCall().call {"OK"}
|
||||
}
|
||||
Reference in New Issue
Block a user