Merge pull request #185 from JetBrains/blackbox-testing
Blackbox testing
This commit is contained in:
@@ -21,6 +21,7 @@ kotstd/kotstd.iml
|
|||||||
*.kt.S
|
*.kt.S
|
||||||
*.kt.exe
|
*.kt.exe
|
||||||
*.log
|
*.log
|
||||||
|
**/test-result.md
|
||||||
|
|
||||||
# Ignore Gradle GUI config
|
# Ignore Gradle GUI config
|
||||||
gradle-app.setting
|
gradle-app.setting
|
||||||
|
|||||||
@@ -1,3 +1,10 @@
|
|||||||
|
import com.google.common.collect.Lists
|
||||||
|
import groovy.io.FileType
|
||||||
|
import org.jetbrains.kotlin.*
|
||||||
|
|
||||||
|
import java.nio.file.*
|
||||||
|
import java.util.regex.Matcher
|
||||||
|
|
||||||
configurations {
|
configurations {
|
||||||
cli_bc
|
cli_bc
|
||||||
}
|
}
|
||||||
@@ -6,109 +13,79 @@ dependencies {
|
|||||||
cli_bc project(path: ':backend.native', configuration: 'cli_bc')
|
cli_bc project(path: ':backend.native', configuration: 'cli_bc')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def logFileName = "test-result.md"
|
||||||
|
|
||||||
|
task regenerate_external_tests() {
|
||||||
|
doLast {
|
||||||
|
def externalTestsProject = childProjects["external"]
|
||||||
|
def gradleGenerated = externalTestsProject.file("build.gradle")
|
||||||
|
def externalTestsDir = externalTestsProject.file("codegen/blackbox")
|
||||||
|
gradleGenerated.write("import org.jetbrains.kotlin.*\n")
|
||||||
|
gradleGenerated.append(
|
||||||
|
"""
|
||||||
|
configurations {
|
||||||
|
cli_bc
|
||||||
|
}
|
||||||
|
|
||||||
abstract class KonanTest extends DefaultTask {
|
dependencies {
|
||||||
protected String source
|
cli_bc project(path: ':backend.native', configuration: 'cli_bc')
|
||||||
def backendNative = project.project(":backend.native")
|
}
|
||||||
def runtimeProject = project.project(":runtime")
|
"""
|
||||||
def dist = project.parent.parent.file("dist")
|
)
|
||||||
def llvmLlc = llvmTool("llc")
|
gradleGenerated.append(
|
||||||
def runtimeBc = new File("${dist.canonicalPath}/lib/runtime.bc").absolutePath
|
"""
|
||||||
def launcherBc = new File("${dist.canonicalPath}/lib/launcher.bc").absolutePath
|
task createLogFile() {
|
||||||
def startKtBc = new File("${dist.canonicalPath}/lib/start.kt.bc").absolutePath
|
doLast {
|
||||||
def stdlibKtBc = new File("${dist.canonicalPath}/lib/stdlib.kt.bc").absolutePath
|
project.file("$logFileName").write("")
|
||||||
def mainC = 'main.c'
|
|
||||||
String goldValue = null
|
|
||||||
String testData = null
|
|
||||||
List<String> arguments = null
|
|
||||||
|
|
||||||
boolean enabled = true
|
|
||||||
|
|
||||||
public void setDisabled(boolean value) {
|
|
||||||
this.enabled = !value
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
externalTestsDir.eachDirRecurse {
|
||||||
|
// Skip build directory and directories without *.kt files.
|
||||||
|
if (it.name == "build" || it.listFiles().count {it.name.endsWith(".kt")} == 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
public KonanTest(){
|
def taskDirectory = externalTestsProject.relativePath(it)
|
||||||
// TODO: that's a long reach up the project tree.
|
def taskName = taskDirectory.replaceAll("[-/]", '_')
|
||||||
// May be we should reorganize a little.
|
|
||||||
dependsOn(project.parent.parent.tasks['dist'])
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract void compileTest(String source, String exe)
|
gradleGenerated.append(
|
||||||
|
"task $taskName (type: RunExternalTestGroup) {\n" +
|
||||||
protected void runCompiler(String source, String output, List<String> moreArgs) {
|
" dependsOn(createLogFile)\n" +
|
||||||
project.javaexec {
|
" groupDirectory = \"$taskDirectory\"\n" +
|
||||||
main = 'org.jetbrains.kotlin.cli.bc.K2NativeKt'
|
" logFileName = \"$logFileName\"\n" +
|
||||||
classpath = project.configurations.cli_bc
|
"}\n\n")
|
||||||
jvmArgs "-ea",
|
|
||||||
"-Dkonan.home=${dist.canonicalPath}",
|
|
||||||
"-Djava.library.path=${dist.canonicalPath}/konan/nativelib"
|
|
||||||
args("-output", output,
|
|
||||||
source,
|
|
||||||
*moreArgs,
|
|
||||||
*project.globalArgs)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TaskAction
|
|
||||||
void executeTest() {
|
|
||||||
def sourceKt = project.file(source).absolutePath
|
|
||||||
def exe = sourceKt.replace(".kt", ".kt.exe")
|
|
||||||
|
|
||||||
compileTest(sourceKt, exe)
|
|
||||||
println "execution :$exe"
|
|
||||||
|
|
||||||
def out = null
|
|
||||||
project.exec {
|
|
||||||
commandLine exe
|
|
||||||
if (arguments != null) {
|
|
||||||
args arguments
|
|
||||||
}
|
|
||||||
if (testData != null) {
|
|
||||||
standardInput = new ByteArrayInputStream(testData.bytes)
|
|
||||||
}
|
|
||||||
if (goldValue != null) {
|
|
||||||
out = new ByteArrayOutputStream()
|
|
||||||
standardOutput = out
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (goldValue != null && goldValue != out.toString())
|
|
||||||
throw new RuntimeException("test failed")
|
|
||||||
}
|
|
||||||
|
|
||||||
private String llvmTool(String tool) {
|
|
||||||
return "${project.llvmDir}/bin/${tool}"
|
|
||||||
}
|
|
||||||
|
|
||||||
protected List<String> clangLinkArgs() {
|
|
||||||
return project.clangLinkArgs
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class RunKonanTest extends KonanTest {
|
|
||||||
void compileTest(String source, String exe) {
|
|
||||||
runCompiler(source, exe, [])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class LinkKonanTest extends KonanTest {
|
|
||||||
protected String lib
|
|
||||||
|
|
||||||
void compileTest(String source, String exe) {
|
|
||||||
def libDir = project.file(lib).absolutePath
|
|
||||||
def libBc = "${libDir}.bc"
|
|
||||||
|
|
||||||
runCompiler(lib, libBc, ['-nolink', '-nostdlib'])
|
|
||||||
runCompiler(source, exe, ['-library', libBc])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
task run() {
|
task run() {
|
||||||
dependsOn(tasks.withType(KonanTest).matching { it.enabled })
|
dependsOn(tasks.withType(KonanTest).matching { it.enabled })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
task run_external () {
|
||||||
|
project.subprojects {
|
||||||
|
dependsOn(it.tasks.withType(RunExternalTestGroup).matching { it.enabled })
|
||||||
|
}
|
||||||
|
doLast {
|
||||||
|
def logFile = childProjects["external"].file(logFileName)
|
||||||
|
def logText = logFile.text
|
||||||
|
|
||||||
|
def passed = logText.count("|PASSED|")
|
||||||
|
def failed = logText.count("|FAILED|")
|
||||||
|
def skipped = logText.count("|SKIPPED|")
|
||||||
|
|
||||||
|
def report = "\nDONE.\n\n" +
|
||||||
|
"PASSED: $passed\n" +
|
||||||
|
"FAILED: $failed\n" +
|
||||||
|
"TOTAL (FAILED + PASSED): ${passed + failed}\n" +
|
||||||
|
"SKIPPED : $skipped"
|
||||||
|
logFile.append(report)
|
||||||
|
println(report)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
task sum (type:RunKonanTest) {
|
task sum (type:RunKonanTest) {
|
||||||
source = "codegen/function/sum.kt"
|
source = "codegen/function/sum.kt"
|
||||||
}
|
}
|
||||||
|
|||||||
+1215
File diff suppressed because it is too large
Load Diff
+35
@@ -0,0 +1,35 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
// WITH_RUNTIME
|
||||||
|
// KT-5665
|
||||||
|
|
||||||
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
annotation class First
|
||||||
|
|
||||||
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
annotation class Second(val value: String)
|
||||||
|
|
||||||
|
enum class E {
|
||||||
|
@First
|
||||||
|
E1 {
|
||||||
|
fun foo() = "something"
|
||||||
|
},
|
||||||
|
|
||||||
|
@Second("OK")
|
||||||
|
E2
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val e = E::class.java
|
||||||
|
|
||||||
|
val e1 = e.getDeclaredField(E.E1.toString()).getAnnotations()
|
||||||
|
if (e1.size != 1) return "Fail E1 size: ${e1.toList()}"
|
||||||
|
if (e1[0].annotationClass.java != First::class.java) return "Fail E1: ${e1.toList()}"
|
||||||
|
|
||||||
|
val e2 = e.getDeclaredField(E.E2.toString()).getAnnotations()
|
||||||
|
if (e2.size != 1) return "Fail E2 size: ${e2.toList()}"
|
||||||
|
if (e2[0].annotationClass.java != Second::class.java) return "Fail E2: ${e2.toList()}"
|
||||||
|
|
||||||
|
return (e2[0] as Second).value
|
||||||
|
}
|
||||||
Vendored
+33
@@ -0,0 +1,33 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
import java.lang.reflect.Method
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
annotation class Ann(val x: String)
|
||||||
|
|
||||||
|
fun foo0(block: () -> Unit) = block.javaClass
|
||||||
|
fun foo1(block: (String) -> Unit) = block.javaClass
|
||||||
|
|
||||||
|
fun testMethod(method: Method, name: String) {
|
||||||
|
assertEquals("OK", method.getAnnotation(Ann::class.java).x, "On method of test named `$name`")
|
||||||
|
|
||||||
|
for ((index, annotations) in method.getParameterAnnotations().withIndex()) {
|
||||||
|
val ann = annotations.filterIsInstance<Ann>().single()
|
||||||
|
assertEquals("OK$index", ann.x, "On parameter $index of test named `$name`")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testClass(clazz: Class<*>, name: String) {
|
||||||
|
val invokes = clazz.getDeclaredMethods().single() { !it.isBridge() }
|
||||||
|
testMethod(invokes, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
testClass(foo0( @Ann("OK") fun() {} ), "1")
|
||||||
|
testClass(foo1( @Ann("OK") fun(@Ann("OK0") x: String) {} ), "2")
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
import java.lang.reflect.Method
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
@Target(AnnotationTarget.FUNCTION)
|
||||||
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
annotation class Ann(val x: String)
|
||||||
|
|
||||||
|
fun foo0(block: () -> Unit) = block.javaClass
|
||||||
|
|
||||||
|
fun testMethod(method: Method, name: String) {
|
||||||
|
assertEquals("OK", method.getAnnotation(Ann::class.java).x, "On method of test named `$name`")
|
||||||
|
|
||||||
|
for ((index, annotations) in method.getParameterAnnotations().withIndex()) {
|
||||||
|
val ann = annotations.filterIsInstance<Ann>().single()
|
||||||
|
assertEquals("OK$index", ann.x, "On parameter $index of test named `$name`")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testClass(clazz: Class<*>, name: String) {
|
||||||
|
val invokes = clazz.getDeclaredMethods().single() { !it.isBridge() }
|
||||||
|
testMethod(invokes, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
testClass(foo0(@Ann("OK") { }), "1")
|
||||||
|
testClass(foo0( @Ann("OK") { }), "2")
|
||||||
|
|
||||||
|
testClass(foo0() @Ann("OK") { }, "3")
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
Vendored
+49
@@ -0,0 +1,49 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
// WITH_RUNTIME
|
||||||
|
// FILE: Test.java
|
||||||
|
|
||||||
|
class Test {
|
||||||
|
public static Class<?> apply(Runnable x) {
|
||||||
|
return x.getClass();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static interface ABC {
|
||||||
|
void apply(String x1, String x2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Class<?> applyABC(ABC x) {
|
||||||
|
return x.getClass();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: test.kt
|
||||||
|
|
||||||
|
import java.lang.reflect.Method
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
annotation class Ann(val x: String)
|
||||||
|
|
||||||
|
fun testMethod(method: Method, name: String) {
|
||||||
|
assertEquals("OK", method.getAnnotation(Ann::class.java).x, "On method of test named `$name`")
|
||||||
|
|
||||||
|
for ((index, annotations) in method.getParameterAnnotations().withIndex()) {
|
||||||
|
val ann = annotations.filterIsInstance<Ann>().single()
|
||||||
|
assertEquals("OK$index", ann.x, "On parameter $index of test named `$name`")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testClass(clazz: Class<*>, name: String) {
|
||||||
|
val invokes = clazz.getDeclaredMethods().single() { !it.isBridge() }
|
||||||
|
testMethod(invokes, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
testClass(Test.apply(@Ann("OK") fun(){}), "1")
|
||||||
|
|
||||||
|
testClass(Test.applyABC(@Ann("OK") fun(@Ann("OK0") x: String, @Ann("OK1") y: String){}), "2")
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
// WITH_RUNTIME
|
||||||
|
// FILE: Test.java
|
||||||
|
|
||||||
|
class Test {
|
||||||
|
public static Class<?> apply(Runnable x) {
|
||||||
|
return x.getClass();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: test.kt
|
||||||
|
|
||||||
|
import java.lang.reflect.Method
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
@Target(AnnotationTarget.FUNCTION)
|
||||||
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
annotation class Ann(val x: String)
|
||||||
|
|
||||||
|
fun testMethod(method: Method, name: String) {
|
||||||
|
assertEquals("OK", method.getAnnotation(Ann::class.java).x, "On method of test named `$name`")
|
||||||
|
|
||||||
|
for ((index, annotations) in method.getParameterAnnotations().withIndex()) {
|
||||||
|
val ann = annotations.filterIsInstance<Ann>().single()
|
||||||
|
assertEquals("OK$index", ann.x, "On parameter $index of test named `$name`")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testClass(clazz: Class<*>, name: String) {
|
||||||
|
val invokes = clazz.getDeclaredMethods().single() { !it.isBridge() }
|
||||||
|
testMethod(invokes, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
testClass(Test.apply(@Ann("OK") {}), "1")
|
||||||
|
testClass(Test.apply @Ann("OK") {}, "2")
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
annotation class Ann(val v: String = "???")
|
||||||
|
@Ann open class My
|
||||||
|
fun box(): String {
|
||||||
|
val v = @Ann("OK") object: My() {}
|
||||||
|
val klass = v.javaClass
|
||||||
|
|
||||||
|
val annotations = klass.annotations.toList()
|
||||||
|
// Ann, kotlin.Metadata
|
||||||
|
if (annotations.size != 2) return "Fail annotations size is ${annotations.size}: $annotations"
|
||||||
|
val annotation = annotations.filterIsInstance<Ann>().firstOrNull()
|
||||||
|
?: return "Fail no @Ann: $annotations"
|
||||||
|
|
||||||
|
return annotation.v
|
||||||
|
}
|
||||||
+36
@@ -0,0 +1,36 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
// WITH_RUNTIME
|
||||||
|
// FILE: JavaClass.java
|
||||||
|
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
||||||
|
public class JavaClass {
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@interface Foo {
|
||||||
|
int value();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Foo(KotlinClass.FOO_INT)
|
||||||
|
public String test() throws NoSuchMethodException {
|
||||||
|
return KotlinClass.FOO_STRING +
|
||||||
|
JavaClass.class.getMethod("test").getAnnotation(Foo.class).value();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: kotlinClass.kt
|
||||||
|
|
||||||
|
class KotlinClass {
|
||||||
|
companion object {
|
||||||
|
const val FOO_INT: Int = 10
|
||||||
|
@JvmField val FOO_STRING: String = "OK"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val test = JavaClass().test()
|
||||||
|
return if (test == "OK10") "OK" else "fail : $test"
|
||||||
|
}
|
||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
// FILE: JavaClass.java
|
||||||
|
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
||||||
|
public class JavaClass {
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@interface Foo {
|
||||||
|
int value();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Foo(KotlinInterface.FOO_INT)
|
||||||
|
public String test() throws NoSuchMethodException {
|
||||||
|
return KotlinInterface.FOO_STRING +
|
||||||
|
JavaClass.class.getMethod("test").getAnnotation(Foo.class).value();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: KotlinInterface.kt
|
||||||
|
|
||||||
|
interface KotlinInterface {
|
||||||
|
companion object {
|
||||||
|
const val FOO_INT: Int = 10
|
||||||
|
const val FOO_STRING: String = "OK"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val test = JavaClass().test()
|
||||||
|
return if (test == "OK10") "OK" else "fail : $test"
|
||||||
|
}
|
||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
annotation class Ann(val x: Int)
|
||||||
|
class A {
|
||||||
|
@Ann(1) fun foo(x: Int, y: Int = 2, z: Int) {}
|
||||||
|
|
||||||
|
@Ann(1) constructor(x: Int, y: Int = 2, z: Int)
|
||||||
|
}
|
||||||
|
|
||||||
|
class B @Ann(1) constructor(x: Int, y: Int = 2, z: Int) {}
|
||||||
|
|
||||||
|
fun test(name: String, annotations: Array<out Annotation>) {
|
||||||
|
assertEquals(1, annotations.filterIsInstance<Ann>().single().x, "$name[0]")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val foo = A::class.java.getDeclaredMethods().first { it.getName() == "foo" }
|
||||||
|
test("foo", foo.getDeclaredAnnotations())
|
||||||
|
|
||||||
|
val fooDefault = A::class.java.getDeclaredMethods().first { it.getName() == "foo\$default" }
|
||||||
|
test("foo", foo.getDeclaredAnnotations())
|
||||||
|
|
||||||
|
val (secondary, secondaryDefault) = A::class.java.getDeclaredConstructors().partition { it.getParameterTypes().size == 3 }
|
||||||
|
|
||||||
|
test("secondary", secondary[0].getDeclaredAnnotations())
|
||||||
|
test("secondary\$default", secondaryDefault[0].getDeclaredAnnotations())
|
||||||
|
|
||||||
|
val (primary, primaryDefault) = B::class.java.getConstructors().partition { it.getParameterTypes().size == 3 }
|
||||||
|
|
||||||
|
test("primary", primary[0].getDeclaredAnnotations())
|
||||||
|
test("primary\$default", primaryDefault[0].getDeclaredAnnotations())
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
// WITH_RUNTIME
|
||||||
|
// FULL_JDK
|
||||||
|
|
||||||
|
import kotlin.annotation.AnnotationTarget.*
|
||||||
|
import kotlin.annotation.AnnotationRetention.*
|
||||||
|
import java.lang.Class
|
||||||
|
|
||||||
|
@Target(TYPEALIAS)
|
||||||
|
@Retention(RUNTIME)
|
||||||
|
annotation class Ann(val x: Int)
|
||||||
|
|
||||||
|
@Ann(2)
|
||||||
|
typealias TA = Any
|
||||||
|
|
||||||
|
fun Class<*>.assertHasDeclaredMethodWithAnn() {
|
||||||
|
if (!declaredMethods.any { it.isSynthetic && it.getAnnotation(Ann::class.java) != null }) {
|
||||||
|
throw java.lang.AssertionError("Class ${this.simpleName} has no declared method with annotation @Ann")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
Class.forName("AnnotationsOnTypeAliasesKt").assertHasDeclaredMethodWithAnn()
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+41
@@ -0,0 +1,41 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
annotation class Ann(
|
||||||
|
val i: Int = 1,
|
||||||
|
val s: String = "a",
|
||||||
|
val a: Ann2 = Ann2(),
|
||||||
|
val e: MyEnum = MyEnum.A,
|
||||||
|
val c: KClass<*> = A::class,
|
||||||
|
val ia: IntArray = intArrayOf(1, 2),
|
||||||
|
val sa: Array<String> = arrayOf("a", "b")
|
||||||
|
)
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val ann = MyClass::class.java.getAnnotation(Ann::class.java)
|
||||||
|
if (ann == null) return "fail: cannot find Ann on MyClass}"
|
||||||
|
if (ann.i != 1) return "fail: annotation parameter i should be 1, but was ${ann.i}"
|
||||||
|
if (ann.s != "a") return "fail: annotation parameter s should be \"a\", but was ${ann.s}"
|
||||||
|
val annSimpleName = ann.a.annotationClass.java.getSimpleName()
|
||||||
|
if (annSimpleName != "Ann2") return "fail: annotation parameter a should be of class Ann2, but was $annSimpleName"
|
||||||
|
if (ann.e != MyEnum.A) return "fail: annotation parameter e should be MyEnum.A, but was ${ann.e}"
|
||||||
|
if (ann.c.java != A::class.java) return "fail: annotation parameter c should be of class A, but was ${ann.c}"
|
||||||
|
if (ann.ia[0] != 1 || ann.ia[1] != 2) return "fail: annotation parameter ia should be [1, 2], but was ${ann.ia}"
|
||||||
|
if (ann.sa[0] != "a" || ann.sa[1] != "b") return "fail: annotation parameter ia should be [\"a\", \"b\"], but was ${ann.sa}"
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
annotation class Ann2
|
||||||
|
|
||||||
|
enum class MyEnum {
|
||||||
|
A
|
||||||
|
}
|
||||||
|
|
||||||
|
class A
|
||||||
|
|
||||||
|
@Ann class MyClass
|
||||||
+32
@@ -0,0 +1,32 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
annotation class First
|
||||||
|
|
||||||
|
class MyClass() {
|
||||||
|
public var x: String by Delegate()
|
||||||
|
@First set
|
||||||
|
}
|
||||||
|
|
||||||
|
class Delegate {
|
||||||
|
operator fun getValue(t: Any?, p: KProperty<*>): String {
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
operator fun setValue(t: Any?, p: KProperty<*>, i: String) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val e = MyClass::class.java
|
||||||
|
|
||||||
|
val e1 = e.getDeclaredMethod("setX", String::class.java).getAnnotations()
|
||||||
|
if (e1.size != 1) return "Fail E1 size: ${e1.toList()}"
|
||||||
|
if (e1[0].annotationClass.java != First::class.java) return "Fail: ${e1.toList()}"
|
||||||
|
|
||||||
|
return MyClass().x
|
||||||
|
}
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
@file:StringHolder("OK")
|
||||||
|
@file:JvmName("FileClass")
|
||||||
|
|
||||||
|
@Target(AnnotationTarget.FILE)
|
||||||
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
public annotation class StringHolder(val value: String)
|
||||||
|
|
||||||
|
fun box(): String =
|
||||||
|
Class.forName("FileClass").getAnnotation(StringHolder::class.java)?.value ?: "null"
|
||||||
+34
@@ -0,0 +1,34 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
// WITH_RUNTIME
|
||||||
|
// FULL_JDK
|
||||||
|
|
||||||
|
import java.lang.reflect.Modifier
|
||||||
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
|
class CustomDelegate {
|
||||||
|
operator fun getValue(thisRef: Any?, prop: KProperty<*>): String = prop.name
|
||||||
|
}
|
||||||
|
|
||||||
|
class C {
|
||||||
|
@Volatile var vol = 1
|
||||||
|
@Transient val tra = 1
|
||||||
|
@delegate:Transient val del: String by CustomDelegate()
|
||||||
|
|
||||||
|
@Strictfp fun str() {}
|
||||||
|
@Synchronized fun sync() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val c = C::class.java
|
||||||
|
|
||||||
|
if (c.getDeclaredField("vol").getModifiers() and Modifier.VOLATILE == 0) return "Fail: volatile"
|
||||||
|
if (c.getDeclaredField("tra").getModifiers() and Modifier.TRANSIENT == 0) return "Fail: transient"
|
||||||
|
if (c.getDeclaredField("del\$delegate").getModifiers() and Modifier.TRANSIENT == 0) return "Fail: delegate transient"
|
||||||
|
|
||||||
|
if (c.getDeclaredMethod("str").getModifiers() and Modifier.STRICT == 0) return "Fail: strict"
|
||||||
|
if (c.getDeclaredMethod("sync").getModifiers() and Modifier.SYNCHRONIZED == 0) return "Fail: synchronized"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+48
@@ -0,0 +1,48 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
@Ann(Foo.i, Foo.s, Foo.f, Foo.d, Foo.l, Foo.b, Foo.bool, Foo.c, Foo.str) class MyClass
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val ann = MyClass::class.java.getAnnotation(Ann::class.java)
|
||||||
|
if (ann == null) return "fail: cannot find Ann on MyClass}"
|
||||||
|
if (ann.i != 2) return "fail: annotation parameter i should be 2, but was ${ann.i}"
|
||||||
|
if (ann.s != 2.toShort()) return "fail: annotation parameter i should be 2, but was ${ann.i}"
|
||||||
|
if (ann.f != 2.toFloat()) return "fail: annotation parameter i should be 2, but was ${ann.i}"
|
||||||
|
if (ann.d != 2.toDouble()) return "fail: annotation parameter i should be 2, but was ${ann.i}"
|
||||||
|
if (ann.l != 2.toLong()) return "fail: annotation parameter i should be 2, but was ${ann.i}"
|
||||||
|
if (ann.b != 2.toByte()) return "fail: annotation parameter i should be 2, but was ${ann.i}"
|
||||||
|
if (!ann.bool) return "fail: annotation parameter i should be true, but was ${ann.i}"
|
||||||
|
if (ann.c != 'c') return "fail: annotation parameter i should be c, but was ${ann.i}"
|
||||||
|
if (ann.str != "str") return "fail: annotation parameter i should be str, but was ${ann.i}"
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
annotation class Ann(
|
||||||
|
val i: Int,
|
||||||
|
val s: Short,
|
||||||
|
val f: Float,
|
||||||
|
val d: Double,
|
||||||
|
val l: Long,
|
||||||
|
val b: Byte,
|
||||||
|
val bool: Boolean,
|
||||||
|
val c: Char,
|
||||||
|
val str: String
|
||||||
|
)
|
||||||
|
|
||||||
|
class Foo {
|
||||||
|
companion object {
|
||||||
|
const val i: Int = 2
|
||||||
|
const val s: Short = 2
|
||||||
|
const val f: Float = 2.0.toFloat()
|
||||||
|
const val d: Double = 2.0
|
||||||
|
const val l: Long = 2
|
||||||
|
const val b: Byte = 2
|
||||||
|
const val bool: Boolean = true
|
||||||
|
const val c: Char = 'c'
|
||||||
|
const val str: String = "str"
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+44
@@ -0,0 +1,44 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
@Ann(i, s, f, d, l, b, bool, c, str) class MyClass
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val ann = MyClass::class.java.getAnnotation(Ann::class.java)
|
||||||
|
if (ann == null) return "fail: cannot find Ann on MyClass}"
|
||||||
|
if (ann.i != 2) return "fail: annotation parameter i should be 2, but was ${ann.i}"
|
||||||
|
if (ann.s != 2.toShort()) return "fail: annotation parameter i should be 2, but was ${ann.i}"
|
||||||
|
if (ann.f != 2.toFloat()) return "fail: annotation parameter i should be 2, but was ${ann.i}"
|
||||||
|
if (ann.d != 2.toDouble()) return "fail: annotation parameter i should be 2, but was ${ann.i}"
|
||||||
|
if (ann.l != 2.toLong()) return "fail: annotation parameter i should be 2, but was ${ann.i}"
|
||||||
|
if (ann.b != 2.toByte()) return "fail: annotation parameter i should be 2, but was ${ann.i}"
|
||||||
|
if (!ann.bool) return "fail: annotation parameter i should be true, but was ${ann.i}"
|
||||||
|
if (ann.c != 'c') return "fail: annotation parameter i should be c, but was ${ann.i}"
|
||||||
|
if (ann.str != "str") return "fail: annotation parameter i should be str, but was ${ann.i}"
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
annotation class Ann(
|
||||||
|
val i: Int,
|
||||||
|
val s: Short,
|
||||||
|
val f: Float,
|
||||||
|
val d: Double,
|
||||||
|
val l: Long,
|
||||||
|
val b: Byte,
|
||||||
|
val bool: Boolean,
|
||||||
|
val c: Char,
|
||||||
|
val str: String
|
||||||
|
)
|
||||||
|
|
||||||
|
const val i: Int = 2
|
||||||
|
const val s: Short = 2
|
||||||
|
const val f: Float = 2.0.toFloat()
|
||||||
|
const val d: Double = 2.0
|
||||||
|
const val l: Long = 2
|
||||||
|
const val b: Byte = 2
|
||||||
|
const val bool: Boolean = true
|
||||||
|
const val c: Char = 'c'
|
||||||
|
const val str: String = "str"
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
annotation class A
|
||||||
|
|
||||||
|
@Target(AnnotationTarget.CLASS)
|
||||||
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
annotation class B(val items: Array<A> = arrayOf(A()))
|
||||||
|
|
||||||
|
@B
|
||||||
|
class C
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val bClass = B::class.java
|
||||||
|
val cClass = C::class.java
|
||||||
|
|
||||||
|
val items = cClass.getAnnotation(bClass).items
|
||||||
|
assert(items.size == 1) { "Expected: [A()], got ${items.asList()}" }
|
||||||
|
assert(items[0] is A) { "Expected: [A()], got ${items.asList()}" }
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
Vendored
+24
@@ -0,0 +1,24 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
@Ann(A.B.i) class MyClass
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val ann = MyClass::class.java.getAnnotation(Ann::class.java)
|
||||||
|
if (ann == null) return "fail: cannot find Ann on MyClass}"
|
||||||
|
if (ann.i != 1) return "fail: annotation parameter i should be 1, but was ${ann.i}"
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
annotation class Ann(val i: Int)
|
||||||
|
|
||||||
|
class A {
|
||||||
|
class B {
|
||||||
|
companion object {
|
||||||
|
const val i = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+32
@@ -0,0 +1,32 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
annotation class Ann(
|
||||||
|
val b: Byte,
|
||||||
|
val s: Short,
|
||||||
|
val i: Int,
|
||||||
|
val f: Float,
|
||||||
|
val d: Double,
|
||||||
|
val l: Long,
|
||||||
|
val c: Char,
|
||||||
|
val bool: Boolean
|
||||||
|
)
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val ann = MyClass::class.java.getAnnotation(Ann::class.java)
|
||||||
|
if (ann == null) return "fail: cannot find Ann on MyClass}"
|
||||||
|
if (ann.b != 1.toByte()) return "fail: annotation parameter b should be 1, but was ${ann.b}"
|
||||||
|
if (ann.s != 1.toShort()) return "fail: annotation parameter s should be 1, but was ${ann.s}"
|
||||||
|
if (ann.i != 1) return "fail: annotation parameter i should be 1, but was ${ann.i}"
|
||||||
|
if (ann.f != 1.toFloat()) return "fail: annotation parameter f should be 1, but was ${ann.f}"
|
||||||
|
if (ann.d != 1.0) return "fail: annotation parameter d should be 1, but was ${ann.d}"
|
||||||
|
if (ann.l != 1.toLong()) return "fail: annotation parameter l should be 1, but was ${ann.l}"
|
||||||
|
if (ann.c != 'c') return "fail: annotation parameter c should be 1, but was ${ann.c}"
|
||||||
|
if (!ann.bool) return "fail: annotation parameter bool should be 1, but was ${ann.bool}"
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
@Ann(1, 1, 1, 1.0.toFloat(), 1.0, 1, 'c', true) class MyClass
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
@Ann(i) class MyClass
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val ann = MyClass::class.java.getAnnotation(Ann::class.java)
|
||||||
|
if (ann == null) return "fail: cannot find Ann on MyClass}"
|
||||||
|
if (ann.i != 1) return "fail: annotation parameter i should be 1, but was ${ann.i}"
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
annotation class Ann(val i: Int)
|
||||||
|
|
||||||
|
const val i2: Int = 1
|
||||||
|
const val i: Int = i2
|
||||||
Vendored
+19
@@ -0,0 +1,19 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||||
|
@kotlin.internal.LowPriorityInOverloadResolution
|
||||||
|
fun foo(i: Int) = 1
|
||||||
|
|
||||||
|
fun foo(a: Any) = 2
|
||||||
|
|
||||||
|
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||||
|
@kotlin.internal.LowPriorityInOverloadResolution
|
||||||
|
fun bar(a: String?) = 3
|
||||||
|
|
||||||
|
fun bar(a: Any) = 4
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
if (foo(1) != 2) return "fail1"
|
||||||
|
if (bar(null) != 3) return "fail2"
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+53
@@ -0,0 +1,53 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
annotation class Ann(vararg val p: Int)
|
||||||
|
|
||||||
|
@Ann() class MyClass1
|
||||||
|
@Ann(1) class MyClass2
|
||||||
|
@Ann(1, 2) class MyClass3
|
||||||
|
|
||||||
|
@Ann(*intArrayOf()) class MyClass4
|
||||||
|
@Ann(*intArrayOf(1)) class MyClass5
|
||||||
|
@Ann(*intArrayOf(1, 2)) class MyClass6
|
||||||
|
|
||||||
|
@Ann(p = 1) class MyClass7
|
||||||
|
|
||||||
|
@Ann(p = *intArrayOf()) class MyClass8
|
||||||
|
@Ann(p = *intArrayOf(1)) class MyClass9
|
||||||
|
@Ann(p = *intArrayOf(1, 2)) class MyClass10
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
test(MyClass1::class.java, "")
|
||||||
|
test(MyClass2::class.java, "1")
|
||||||
|
test(MyClass3::class.java, "12")
|
||||||
|
|
||||||
|
test(MyClass4::class.java, "")
|
||||||
|
test(MyClass5::class.java, "1")
|
||||||
|
test(MyClass6::class.java, "12")
|
||||||
|
|
||||||
|
test(MyClass7::class.java, "1")
|
||||||
|
|
||||||
|
test(MyClass8::class.java, "")
|
||||||
|
test(MyClass9::class.java, "1")
|
||||||
|
test(MyClass10::class.java, "12")
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test(klass: Class<*>, expected: String) {
|
||||||
|
val ann = klass.getAnnotation(Ann::class.java)
|
||||||
|
if (ann == null) throw AssertionError("fail: cannot find Ann on ${klass}")
|
||||||
|
|
||||||
|
var result = ""
|
||||||
|
for (i in ann.p) {
|
||||||
|
result += i
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result != expected) {
|
||||||
|
throw AssertionError("fail: expected = ${expected}, actual = ${result}")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
|
||||||
|
fun test(a: String, b: String): String {
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
var res = "";
|
||||||
|
val call = test(b = {res += "K"; "K"}(), a = {res+="O"; "O"}())
|
||||||
|
|
||||||
|
if (res != "KO" || call != "OK") return "fail: $res != KO or $call != OK"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
var invokeOrder = "";
|
||||||
|
val expectedResult = "0_1_9"
|
||||||
|
val expectedInvokeOrder = "1_0_9"
|
||||||
|
var l = 1L
|
||||||
|
var i = 0
|
||||||
|
val captured = 9L
|
||||||
|
|
||||||
|
var result = test(b = {invokeOrder += "1_"; l}(), a = {invokeOrder+="0_"; i}(), c = {invokeOrder += "$captured"; "$captured"})
|
||||||
|
if (invokeOrder != expectedInvokeOrder || result != expectedResult) return "fail 1: $invokeOrder != $expectedInvokeOrder or $result != $expectedResult"
|
||||||
|
|
||||||
|
invokeOrder = "";
|
||||||
|
result = test(b = {invokeOrder += "1_"; l}(), c = {invokeOrder += "$captured"; "$captured"}, a = {invokeOrder+="0_"; i}())
|
||||||
|
if (invokeOrder != expectedInvokeOrder || result != expectedResult) return "fail 2: $invokeOrder != $expectedInvokeOrder or $result != $expectedResult"
|
||||||
|
|
||||||
|
|
||||||
|
invokeOrder = "";
|
||||||
|
result = test(c = {invokeOrder += "$captured"; "$captured"}, b = {invokeOrder += "1_"; l}(), a = {invokeOrder+="0_"; i}())
|
||||||
|
if (invokeOrder != expectedInvokeOrder || result != expectedResult) return "fail 3: $invokeOrder != $expectedInvokeOrder or $result != $expectedResult"
|
||||||
|
|
||||||
|
|
||||||
|
invokeOrder = "";
|
||||||
|
result = test(a = {invokeOrder+="0_"; i}(), c = {invokeOrder += "$captured"; "$captured"}, b = {invokeOrder += "1_"; l}())
|
||||||
|
if (invokeOrder != "0_1_9" || result != expectedResult) return "fail 4: $invokeOrder != 0_1_9 or $result != $expectedResult"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test(a: Int, b: Long, c: () -> String): String {
|
||||||
|
return { "${a}_${b}_${c()}"} ()
|
||||||
|
}
|
||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
var invokeOrder = "";
|
||||||
|
val expectedResult = "1.0_0_1_9"
|
||||||
|
val expectedInvokeOrder = "1_0_9"
|
||||||
|
var l = 1L
|
||||||
|
var i = 0
|
||||||
|
val captured = 9L
|
||||||
|
|
||||||
|
var result = 1.0.test(b = {invokeOrder += "1_"; l}(), a = {invokeOrder+="0_"; i}(), c = {invokeOrder += "$captured"; "$captured"})
|
||||||
|
if (invokeOrder != expectedInvokeOrder || result != expectedResult) return "fail 1: $invokeOrder != $expectedInvokeOrder or $result != $expectedResult"
|
||||||
|
|
||||||
|
invokeOrder = "";
|
||||||
|
result = 1.0.test(b = {invokeOrder += "1_"; l}(), c = {invokeOrder += "${captured}"; "${captured}"}, a = {invokeOrder+="0_"; i}())
|
||||||
|
if (invokeOrder != expectedInvokeOrder || result != expectedResult) return "fail 2: $invokeOrder != $expectedInvokeOrder or $result != $expectedResult"
|
||||||
|
|
||||||
|
|
||||||
|
invokeOrder = "";
|
||||||
|
result = 1.0.test(c = {invokeOrder += "${captured}"; "${captured}"}, b = {invokeOrder += "1_"; l}(), a = {invokeOrder+="0_"; i}())
|
||||||
|
if (invokeOrder != expectedInvokeOrder || result != expectedResult) return "fail 3: $invokeOrder != $expectedInvokeOrder or $result != $expectedResult"
|
||||||
|
|
||||||
|
invokeOrder = "";
|
||||||
|
result = 1.0.test(a = {invokeOrder+="0_"; i}(), c = {invokeOrder += "${captured}"; "${captured}"}, b = {invokeOrder += "1_"; l}())
|
||||||
|
if (invokeOrder != "0_1_9" || result != expectedResult) return "fail 4: $invokeOrder != 0_1_9 or $result != $expectedResult"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Double.test(a: Int, b: Long, c: () -> String): String {
|
||||||
|
return { "${this}_${a}_${b}_${c()}"} ()
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
var invokeOrder: String = ""
|
||||||
|
|
||||||
|
fun test(x: Double = { invokeOrder += "x"; 1.0 }(), a: String, y: Long = { invokeOrder += "y"; 1 }(), b: String): String {
|
||||||
|
return "" + x + a + b + y;
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val funResult = test(b = { invokeOrder += "K"; "K" }(), a = { invokeOrder += "O"; "O" }())
|
||||||
|
|
||||||
|
if (invokeOrder != "KOxy" || funResult != "1.0OK1") return "fail: $invokeOrder != KOxy or $funResult != 1.0OK1"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
var invokeOrder = "";
|
||||||
|
val expectedResult = "1.0_0_1_L"
|
||||||
|
val expectedInvokeOrder = "1_0_L"
|
||||||
|
var l = 1L
|
||||||
|
var i = 0
|
||||||
|
|
||||||
|
var result = 1.0.test(b = {invokeOrder += "1_"; l}(), a = {invokeOrder+="0_"; i}(), c = {invokeOrder += "L"; "L"})
|
||||||
|
if (invokeOrder != expectedInvokeOrder || result != expectedResult) return "fail 1: $invokeOrder != $expectedInvokeOrder or $result != $expectedResult"
|
||||||
|
|
||||||
|
invokeOrder = "";
|
||||||
|
result = 1.0.test(b = {invokeOrder += "1_"; l}(), c = {invokeOrder += "L"; "L"}, a = {invokeOrder+="0_"; i}())
|
||||||
|
if (invokeOrder != expectedInvokeOrder || result != expectedResult) return "fail 2: $invokeOrder != $expectedInvokeOrder or $result != $expectedResult"
|
||||||
|
|
||||||
|
|
||||||
|
invokeOrder = "";
|
||||||
|
result = 1.0.test(c = {invokeOrder += "L"; "L"}, b = {invokeOrder += "1_"; l}(), a = {invokeOrder+="0_"; i}())
|
||||||
|
if (invokeOrder != expectedInvokeOrder || result != expectedResult) return "fail 3: $invokeOrder != $expectedInvokeOrder or $result != $expectedResult"
|
||||||
|
|
||||||
|
|
||||||
|
invokeOrder = "";
|
||||||
|
result = 1.0.test(a = {invokeOrder+="0_"; i}(), c = {invokeOrder += "L"; "L"}, b = {invokeOrder += "1_"; l}())
|
||||||
|
if (invokeOrder != "0_1_L" || result != expectedResult) return "fail 4: $invokeOrder != 0_1_L or $result != $expectedResult"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Double.test(a: Int, b: Long, c: () -> String): String {
|
||||||
|
return "${this}_${a}_${b}_${c()}"
|
||||||
|
}
|
||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
return Z().test()
|
||||||
|
}
|
||||||
|
|
||||||
|
class Z {
|
||||||
|
fun Double.test(a: Int, b: Long, c: () -> String): String {
|
||||||
|
return "${this}_${a}_${b}_${c()}"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun test(): String {
|
||||||
|
var invokeOrder = "";
|
||||||
|
val expectedResult = "1.0_0_1_L"
|
||||||
|
val expectedInvokeOrder = "1_0_L"
|
||||||
|
var l = 1L
|
||||||
|
var i = 0
|
||||||
|
|
||||||
|
var result = 1.0.test(b = { invokeOrder += "1_"; l }(), a = { invokeOrder += "0_"; i }(), c = { invokeOrder += "L"; "L" })
|
||||||
|
if (invokeOrder != expectedInvokeOrder || result != expectedResult) return "fail 1: $invokeOrder != $expectedInvokeOrder or $result != $expectedResult"
|
||||||
|
|
||||||
|
invokeOrder = "";
|
||||||
|
result = 1.0.test(b = { invokeOrder += "1_"; l }(), c = { invokeOrder += "L"; "L" }, a = { invokeOrder += "0_"; i }())
|
||||||
|
if (invokeOrder != expectedInvokeOrder || result != expectedResult) return "fail 2: $invokeOrder != $expectedInvokeOrder or $result != $expectedResult"
|
||||||
|
|
||||||
|
|
||||||
|
invokeOrder = "";
|
||||||
|
result = 1.0.test(c = { invokeOrder += "L"; "L" }, b = { invokeOrder += "1_"; l }(), a = { invokeOrder += "0_"; i }())
|
||||||
|
if (invokeOrder != expectedInvokeOrder || result != expectedResult) return "fail 3: $invokeOrder != $expectedInvokeOrder or $result != $expectedResult"
|
||||||
|
|
||||||
|
|
||||||
|
invokeOrder = "";
|
||||||
|
result = 1.0.test(a = { invokeOrder += "0_"; i }(), c = { invokeOrder += "L"; "L" }, b = { invokeOrder += "1_"; l }())
|
||||||
|
if (invokeOrder != "0_1_L" || result != expectedResult) return "fail 4: $invokeOrder != 0_1_L or $result != $expectedResult"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
// KT-9277 Unexpected NullPointerException in an invocaton with named arguments
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
foo(null)
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo(x : Int?){
|
||||||
|
bar(z = x ?: return, y = x)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bar(y : Int, z : Int) {}
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
fun box(): String {
|
||||||
|
var res = "";
|
||||||
|
var call = test(a = {res += "K"; "K"}(), b = {res+="O"; "O"}(), c = {res += "L"; "L"})
|
||||||
|
if (res != "KOL" || call != "KOL") return "fail 1: $res != KOL or $call != KOL"
|
||||||
|
|
||||||
|
res = "";
|
||||||
|
call = test(a = {res += "K"; "K"}(), c = {res += "L"; "L"}, b = {res+="O"; "O"}())
|
||||||
|
if (res != "KOL" || call != "KOL") return "fail 2: $res != KOL or $call != KOL"
|
||||||
|
|
||||||
|
|
||||||
|
res = "";
|
||||||
|
call = test(c = {res += "L"; "L"}, a = {res += "K"; "K"}(), b = {res+="O"; "O"}())
|
||||||
|
if (res != "KOL" || call != "KOL") return "fail 3: $res != KOL or $call != KOL"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test(a: String, b: String, c: () -> String): String {
|
||||||
|
return a + b + c();
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
fun box(): String {
|
||||||
|
var res = "";
|
||||||
|
var call = Z("Z").test(a = {res += "K"; "K"}(), b = {res+="O"; "O"}(), c = {res += "L"; "L"})
|
||||||
|
if (res != "KOL" || call != "KOLZ") return "fail 1: $res != KOL or $call != KOLZ"
|
||||||
|
|
||||||
|
res = "";
|
||||||
|
call = Z("Z").test(a = {res += "K"; "K"}(), c = {res += "L"; "L"}, b = {res+="O"; "O"}())
|
||||||
|
if (res != "KOL" || call != "KOLZ") return "fail 2: $res != KOL or $call != KOLZ"
|
||||||
|
|
||||||
|
|
||||||
|
res = "";
|
||||||
|
call = Z("Z").test(c = {res += "L"; "L"}, a = {res += "K"; "K"}(), b = {res+="O"; "O"}())
|
||||||
|
if (res != "KOL" || call != "KOLZ") return "fail 3: $res != KOL or $call != KOLZ"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class Z(val p: String) {
|
||||||
|
|
||||||
|
fun test(a: String, b: String, c: () -> String): String {
|
||||||
|
return a + b + c() + p;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
var res = "";
|
||||||
|
var call = test(b = {res += "K"; "K"}(), a = {res+="O"; "O"}(), c = {res += "L"; "L"})
|
||||||
|
if (res != "KOL" || call != "OKL") return "fail 1: $res != KOL or $call != OKL"
|
||||||
|
|
||||||
|
res = "";
|
||||||
|
call = test(b = {res += "K"; "K"}(), c = {res += "L"; "L"}, a = {res+="O"; "O"}())
|
||||||
|
if (res != "KOL" || call != "OKL") return "fail 2: $res != KOL or $call != OKL"
|
||||||
|
|
||||||
|
|
||||||
|
res = "";
|
||||||
|
call = test(c = {res += "L"; "L"}, b = {res += "K"; "K"}(), a = {res+="O"; "O"}())
|
||||||
|
if (res != "KOL" || call != "OKL") return "fail 3: $res != KOL or $call != OKL"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test(a: String, b: String, c: () -> String): String {
|
||||||
|
return a + b + c();
|
||||||
|
}
|
||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
var res = "";
|
||||||
|
var call = Z("Z").test(b = {res += "K"; "K"}(), a = {res+="O"; "O"}(), c = {res += "L"; "L"})
|
||||||
|
if (res != "KOL" || call != "OKLZ") return "fail 1: $res != KOL or $call != OKLZ"
|
||||||
|
|
||||||
|
res = "";
|
||||||
|
call = Z("Z").test(b = {res += "K"; "K"}(), c = {res += "L"; "L"}, a = {res+="O"; "O"}())
|
||||||
|
if (res != "KOL" || call != "OKLZ") return "fail 2: $res != KOL or $call != OKLZ"
|
||||||
|
|
||||||
|
|
||||||
|
res = "";
|
||||||
|
call = Z("Z").test(c = {res += "L"; "L"}, b = {res += "K"; "K"}(), a = {res+="O"; "O"}())
|
||||||
|
if (res != "KOL" || call != "OKLZ") return "fail 3: $res != KOL or $call != OKLZ"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class Z(val p: String) {
|
||||||
|
fun test(a: String, b: String, c: () -> String): String {
|
||||||
|
return a + b + c() + p;
|
||||||
|
}
|
||||||
|
}
|
||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
fun simpleIntArray(): Array<Int> = Array(3) { it }
|
||||||
|
fun simpleDoubleArray(): Array<Double> = Array(3) { it.toDouble() + 0.1 }
|
||||||
|
fun simpleStringArray(): Array<String> = Array(3) { it.toString() }
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val ia = simpleIntArray()
|
||||||
|
assertEquals(0, ia[0])
|
||||||
|
assertEquals(1, ia[1])
|
||||||
|
assertEquals(2, ia[2])
|
||||||
|
|
||||||
|
val da = simpleDoubleArray()
|
||||||
|
assertEquals(0.1, da[0])
|
||||||
|
assertEquals(1.1, da[1])
|
||||||
|
assertEquals(2.1, da[2])
|
||||||
|
|
||||||
|
val sa = simpleStringArray()
|
||||||
|
assertEquals("0", sa[0])
|
||||||
|
assertEquals("1", sa[1])
|
||||||
|
assertEquals("2", sa[2])
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
operator fun Array<String>.get(index1: Int, index2: Int) = this[index1 + index2]
|
||||||
|
operator fun Array<String>.set(index1: Int, index2: Int, elem: String) {
|
||||||
|
this[index1 + index2] = elem
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val s = Array<String>(1, { "" })
|
||||||
|
s[1, -1] = "O"
|
||||||
|
s[2, -2] += "K"
|
||||||
|
return s[-3, 3]
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
operator fun Array<String>.get(index1: Int, index2: Int) = this[index1 + index2]
|
||||||
|
operator fun Array<String>.set(index1: Int, index2: Int, elem: String) {
|
||||||
|
this[index1 + index2] = elem
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val s = Array<String>(1, { "" })
|
||||||
|
s[1, -1] = "OK"
|
||||||
|
return s[-2, 2]
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
//test [], get and iterator calls
|
||||||
|
fun test(createIntNotLong: Boolean): String {
|
||||||
|
val a = if (createIntNotLong) IntArray(5) else LongArray(5)
|
||||||
|
if (a is IntArray) {
|
||||||
|
val x = a.iterator()
|
||||||
|
var i = 0
|
||||||
|
while (x.hasNext()) {
|
||||||
|
if (a[i] != x.next()) return "Fail $i"
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
return "O"
|
||||||
|
} else if (a is LongArray) {
|
||||||
|
val x = a.iterator()
|
||||||
|
var i = 0
|
||||||
|
while (x.hasNext()) {
|
||||||
|
if (a.get(i) != x.next()) return "Fail $i"
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
return "K"
|
||||||
|
}
|
||||||
|
return "fail"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
return test(true) + test(false)
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
fun box(): String {
|
||||||
|
val s = IntArray(1)
|
||||||
|
s[0] = 5
|
||||||
|
s[0] += 7
|
||||||
|
return if (s[0] == 12) "OK" else "Fail ${s[0]}"
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
fun foo(x: Cloneable) = x
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
foo(arrayOf(""))
|
||||||
|
foo(intArrayOf())
|
||||||
|
foo(longArrayOf())
|
||||||
|
foo(shortArrayOf())
|
||||||
|
foo(byteArrayOf())
|
||||||
|
foo(charArrayOf())
|
||||||
|
foo(doubleArrayOf())
|
||||||
|
foo(floatArrayOf())
|
||||||
|
foo(booleanArrayOf())
|
||||||
|
|
||||||
|
arrayOf("").clone()
|
||||||
|
intArrayOf().clone()
|
||||||
|
longArrayOf().clone()
|
||||||
|
shortArrayOf().clone()
|
||||||
|
byteArrayOf().clone()
|
||||||
|
charArrayOf().clone()
|
||||||
|
doubleArrayOf().clone()
|
||||||
|
floatArrayOf().clone()
|
||||||
|
booleanArrayOf().clone()
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val s = arrayOf("live", "long")
|
||||||
|
val t: Array<String> = s.clone()
|
||||||
|
if (!(s contentEquals t)) return "Fail string"
|
||||||
|
if (s === t) return "Fail string identity"
|
||||||
|
|
||||||
|
val ss = arrayOf(s, s)
|
||||||
|
val tt: Array<Array<String>> = ss.clone()
|
||||||
|
if (!(ss contentEquals tt)) return "Fail string[]"
|
||||||
|
if (ss === tt) return "Fail string[] identity"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val i = intArrayOf(1, 2)
|
||||||
|
if (!(i contentEquals i.clone())) return "Fail int"
|
||||||
|
if (i.clone() === i) return "Fail int identity"
|
||||||
|
|
||||||
|
val j = longArrayOf(1L, 2L)
|
||||||
|
if (!(j contentEquals j.clone())) return "Fail long"
|
||||||
|
if (j.clone() === j) return "Fail long identity"
|
||||||
|
|
||||||
|
val s = shortArrayOf(1.toShort(), 2.toShort())
|
||||||
|
if (!(s contentEquals s.clone())) return "Fail short"
|
||||||
|
if (s.clone() === s) return "Fail short identity"
|
||||||
|
|
||||||
|
val b = byteArrayOf(1.toByte(), 2.toByte())
|
||||||
|
if (!(b contentEquals b.clone())) return "Fail byte"
|
||||||
|
if (b.clone() === b) return "Fail byte identity"
|
||||||
|
|
||||||
|
val c = charArrayOf('a', 'b')
|
||||||
|
if (!(c contentEquals c.clone())) return "Fail char"
|
||||||
|
if (c.clone() === c) return "Fail char identity"
|
||||||
|
|
||||||
|
val d = doubleArrayOf(1.0, -1.0)
|
||||||
|
if (!(d contentEquals d.clone())) return "Fail double"
|
||||||
|
if (d.clone() === d) return "Fail double identity"
|
||||||
|
|
||||||
|
val f = floatArrayOf(1f, -1f)
|
||||||
|
if (!(f contentEquals f.clone())) return "Fail float"
|
||||||
|
if (f.clone() === f) return "Fail float identity"
|
||||||
|
|
||||||
|
val z = booleanArrayOf(true, false)
|
||||||
|
if (!(z contentEquals z.clone())) return "Fail boolean"
|
||||||
|
if (z.clone() === z) return "Fail boolean identity"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
operator fun ArrayList<String>.get(index1: Int, index2: Int) = this[index1 + index2]
|
||||||
|
operator fun ArrayList<String>.set(index1: Int, index2: Int, elem: String) {
|
||||||
|
this[index1 + index2] = elem
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val s = ArrayList<String>(1)
|
||||||
|
s.add("")
|
||||||
|
s[1, -1] = "O"
|
||||||
|
s[2, -2] += "K"
|
||||||
|
return s[2, -2]
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
operator fun ArrayList<String>.get(index1: Int, index2: Int) = this[index1 + index2]
|
||||||
|
operator fun ArrayList<String>.set(index1: Int, index2: Int, elem: String) {
|
||||||
|
this[index1 + index2] = elem
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val s = ArrayList<String>(1)
|
||||||
|
s.add("")
|
||||||
|
s[1, -1] = "OK"
|
||||||
|
return s[2, -2]
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
fun box(): String {
|
||||||
|
for (x in BooleanArray(5)) {
|
||||||
|
if (x != false) return "Fail $x"
|
||||||
|
}
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
fun box(): String {
|
||||||
|
for (x in ByteArray(5)) {
|
||||||
|
if (x != 0.toByte()) return "Fail $x"
|
||||||
|
}
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
fun box(): String {
|
||||||
|
for (x in CharArray(5)) {
|
||||||
|
if (x != 0.toChar()) return "Fail $x"
|
||||||
|
}
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
fun box(): String {
|
||||||
|
for (x in DoubleArray(5)) {
|
||||||
|
if (x != 0.toDouble()) return "Fail $x"
|
||||||
|
}
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
fun box(): String {
|
||||||
|
for (x in FloatArray(5)) {
|
||||||
|
if (x != 0.toFloat()) return "Fail $x"
|
||||||
|
}
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
fun box(): String {
|
||||||
|
for (x in IntArray(5)) {
|
||||||
|
if (x != 0) return "Fail $x"
|
||||||
|
}
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
fun box(): String {
|
||||||
|
for (x in LongArray(5)) {
|
||||||
|
if (x != 0.toLong()) return "Fail $x"
|
||||||
|
}
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
fun box(): String {
|
||||||
|
for (x in ShortArray(5)) {
|
||||||
|
if (x != 0.toShort()) return "Fail $x"
|
||||||
|
}
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
operator fun HashMap<String, Int?>.set(index: String, elem: Int?) {
|
||||||
|
this.put(index, elem)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val s = HashMap<String, Int?>()
|
||||||
|
s["239"] = 239
|
||||||
|
return if (s["239"] == 239) "OK" else "Fail"
|
||||||
|
}
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
fun test(y: Array<in Array<String>>) {
|
||||||
|
y[0] = kotlin.arrayOf("OK")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box() : String {
|
||||||
|
val x : Array<Array<*>> = kotlin.arrayOf(kotlin.arrayOf(1))
|
||||||
|
test(x)
|
||||||
|
return x[0][0] as String
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
fun box(): String {
|
||||||
|
val x : Array<Array<*>> = arrayOf(arrayOf(1))
|
||||||
|
val y : Array<in Array<String>> = x
|
||||||
|
|
||||||
|
if (y.size != 1) return "fail 1"
|
||||||
|
|
||||||
|
y[0] = arrayOf("OK")
|
||||||
|
|
||||||
|
return x[0][0] as String
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val x: Array<List<*>> = arrayOf(listOf(1))
|
||||||
|
val y : Array<in List<String>> = x
|
||||||
|
|
||||||
|
if (y.size != 1) return "fail 1"
|
||||||
|
|
||||||
|
y[0] = listOf("OK")
|
||||||
|
|
||||||
|
return x[0][0] as String
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val a = Array<Int>(5, {it})
|
||||||
|
val x = a.indices.iterator()
|
||||||
|
while (x.hasNext()) {
|
||||||
|
val i = x.next()
|
||||||
|
if (a[i] != i) return "Fail $i ${a[i]}"
|
||||||
|
}
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val a = CharArray(5)
|
||||||
|
val x = a.indices.iterator()
|
||||||
|
while (x.hasNext()) {
|
||||||
|
val i = x.next()
|
||||||
|
if (a[i] != 0.toChar()) return "Fail $i ${a[i]}"
|
||||||
|
}
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
fun box(): String {
|
||||||
|
val x = Array<Int>(5, { it } ).iterator()
|
||||||
|
var i = 0
|
||||||
|
while (x.hasNext()) {
|
||||||
|
if (x.next() != i) return "Fail $i"
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
fun box(): String {
|
||||||
|
val a = BooleanArray(5)
|
||||||
|
val x = a.iterator()
|
||||||
|
var i = 0
|
||||||
|
while (x.hasNext()) {
|
||||||
|
if (a[i] != x.next()) return "Fail $i"
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
fun box(): String {
|
||||||
|
val a = ByteArray(5)
|
||||||
|
val x = a.iterator()
|
||||||
|
var i = 0
|
||||||
|
while (x.hasNext()) {
|
||||||
|
if (a[i] != x.next()) return "Fail $i"
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val a = ByteArray(5)
|
||||||
|
val x = a.iterator()
|
||||||
|
var i = 0
|
||||||
|
while (x.hasNext()) {
|
||||||
|
if (a[i] != x.nextByte()) return "Fail $i"
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
fun box(): String {
|
||||||
|
val a = CharArray(5)
|
||||||
|
val x = a.iterator()
|
||||||
|
var i = 0
|
||||||
|
while (x.hasNext()) {
|
||||||
|
if (a[i] != x.next()) return "Fail $i"
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
fun box(): String {
|
||||||
|
val a = DoubleArray(5)
|
||||||
|
val x = a.iterator()
|
||||||
|
var i = 0
|
||||||
|
while (x.hasNext()) {
|
||||||
|
if (a[i] != x.next()) return "Fail $i"
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
fun box(): String {
|
||||||
|
val a = FloatArray(5)
|
||||||
|
val x = a.iterator()
|
||||||
|
var i = 0
|
||||||
|
while (x.hasNext()) {
|
||||||
|
if (a[i] != x.next()) return "Fail $i"
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
fun box(): String {
|
||||||
|
val a = IntArray(5)
|
||||||
|
val x = a.iterator()
|
||||||
|
var i = 0
|
||||||
|
while (x.hasNext()) {
|
||||||
|
if (a[i] != x.next()) return "Fail $i"
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
fun box(): String {
|
||||||
|
val a = LongArray(5)
|
||||||
|
val x = a.iterator()
|
||||||
|
var i = 0
|
||||||
|
while (x.hasNext()) {
|
||||||
|
if (a[i] != x.next()) return "Fail $i"
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val a = LongArray(5)
|
||||||
|
val x = a.iterator()
|
||||||
|
var i = 0
|
||||||
|
while (x.hasNext()) {
|
||||||
|
if (a[i] != x.nextLong()) return "Fail $i"
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
fun box(): String {
|
||||||
|
val a = ShortArray(5)
|
||||||
|
val x = a.iterator()
|
||||||
|
var i = 0
|
||||||
|
while (x.hasNext()) {
|
||||||
|
if (a[i] != x.next()) return "Fail $i"
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
var result = 0
|
||||||
|
|
||||||
|
fun <T> Iterator<T>.foreach(action: (T) -> Unit) {
|
||||||
|
while (this.hasNext()) {
|
||||||
|
(action)(this.next())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <In, Out> Iterator<In>.select(f: (In) -> Out) : Iterator<Out> {
|
||||||
|
return Selector(this, f);
|
||||||
|
}
|
||||||
|
|
||||||
|
class Selector<In, Out>(val source: Iterator<In>, val f: (In) -> Out) : Iterator<Out> {
|
||||||
|
override fun hasNext(): Boolean = source.hasNext()
|
||||||
|
|
||||||
|
override fun next(): Out {
|
||||||
|
return (f)(source.next())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
Array(4, { it + 1 }).iterator()
|
||||||
|
.select({i -> i * 10})
|
||||||
|
.foreach({k -> result += k})
|
||||||
|
if (result != 10+20+30+40) return "Fail: $result"
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
fun t1 () {
|
||||||
|
val a1 = arrayOfNulls<String>(1)
|
||||||
|
a1[0] = "0" //ok
|
||||||
|
val s = a1[0] //ok
|
||||||
|
}
|
||||||
|
|
||||||
|
fun t2 () {
|
||||||
|
val a2 = arrayOfNulls<Int>(1) as Array<Int>
|
||||||
|
a2[0] = 0 //ok
|
||||||
|
var i = a2[0] //ok
|
||||||
|
}
|
||||||
|
|
||||||
|
fun t3 () {
|
||||||
|
val a3 = arrayOfNulls<Int>(1)
|
||||||
|
a3[0] = 0 //verify error
|
||||||
|
var j = a3[0] //ok
|
||||||
|
var k : Int = a3[0] ?: 5 //ok
|
||||||
|
}
|
||||||
|
|
||||||
|
fun t4 () {
|
||||||
|
val b1 = StrangeIntArray(10)
|
||||||
|
b1[4] = 5 //ok
|
||||||
|
var i = b1[1] //ok
|
||||||
|
}
|
||||||
|
|
||||||
|
fun t5 () {
|
||||||
|
val b2 = StrangeArray<Int>(10, 0)
|
||||||
|
b2.set(4, 5) //ok
|
||||||
|
b2[4] = 5 //verify error
|
||||||
|
var i = b2.get(2) //ok
|
||||||
|
i = b2[1] //verify error
|
||||||
|
}
|
||||||
|
|
||||||
|
fun t6() {
|
||||||
|
val b3 = StrangeArray<Int?>(10, 0)
|
||||||
|
b3.set(5, 6) //ok
|
||||||
|
b3[4] = 5 //verify error
|
||||||
|
val v = b3[1] //ok
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box() : String {
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
class StrangeArray<T>(size: Int, private var defaultValue: T) {
|
||||||
|
operator fun get(index: Int): T = defaultValue
|
||||||
|
operator fun set(index: Int, v: T) {
|
||||||
|
defaultValue = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class StrangeIntArray(size: Int) {
|
||||||
|
private var defaultValue = 0
|
||||||
|
operator fun get(index: Int): Int = defaultValue
|
||||||
|
operator fun set(index: Int, v: Int) {
|
||||||
|
defaultValue = v
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
//KT-2997 Automatically cast error (Array)
|
||||||
|
|
||||||
|
fun foo(a: Any): Int {
|
||||||
|
if (a is IntArray) {
|
||||||
|
a.get(0)
|
||||||
|
a.set(0, 1)
|
||||||
|
a.iterator()
|
||||||
|
return a.size
|
||||||
|
}
|
||||||
|
if (a is ShortArray) {
|
||||||
|
a.get(0)
|
||||||
|
a.set(0, 1)
|
||||||
|
a.iterator()
|
||||||
|
return a.size
|
||||||
|
}
|
||||||
|
if (a is ByteArray) {
|
||||||
|
a.get(0)
|
||||||
|
a.set(0, 1)
|
||||||
|
a.iterator()
|
||||||
|
return a.size
|
||||||
|
}
|
||||||
|
if (a is FloatArray) {
|
||||||
|
a.get(0)
|
||||||
|
a.set(0, 1.toFloat())
|
||||||
|
a.iterator()
|
||||||
|
return a.size
|
||||||
|
}
|
||||||
|
if (a is DoubleArray) {
|
||||||
|
a.get(0)
|
||||||
|
a.set(0, 1.0)
|
||||||
|
a.iterator()
|
||||||
|
return a.size
|
||||||
|
}
|
||||||
|
if (a is BooleanArray) {
|
||||||
|
a.get(0)
|
||||||
|
a.set(0, false)
|
||||||
|
a.iterator()
|
||||||
|
return a.size
|
||||||
|
}
|
||||||
|
if (a is CharArray) {
|
||||||
|
a.get(0)
|
||||||
|
a.set(0, 'a')
|
||||||
|
a.iterator()
|
||||||
|
return a.size
|
||||||
|
}
|
||||||
|
if (a is Array<*>) {
|
||||||
|
if (a.size > 0) a.get(0)
|
||||||
|
a.iterator()
|
||||||
|
return a.size
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val iA = IntArray(1)
|
||||||
|
if (foo(iA) != 1) return "fail int[]"
|
||||||
|
val sA = ShortArray(1)
|
||||||
|
if (foo(sA) != 1) return "fail short[]"
|
||||||
|
val bA = ByteArray(1)
|
||||||
|
if (foo(bA) != 1) return "fail byte[]"
|
||||||
|
val fA = FloatArray(1)
|
||||||
|
if (foo(fA) != 1) return "fail float[]"
|
||||||
|
val dA = DoubleArray(1)
|
||||||
|
if (foo(dA) != 1) return "fail double[]"
|
||||||
|
val boolA = BooleanArray(1)
|
||||||
|
if (foo(boolA) != 1) return "fail boolean[]"
|
||||||
|
val cA = CharArray(1)
|
||||||
|
if (foo(cA) != 1) return "fail char[]"
|
||||||
|
val oA = arrayOfNulls<Int>(1)
|
||||||
|
if (foo(oA) != 1) return "fail Any[]"
|
||||||
|
|
||||||
|
val sArray = arrayOfNulls<String>(0)
|
||||||
|
if (foo(sArray) != 0) return "fail String[]"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
fun box () : String {
|
||||||
|
val s = ArrayList<String>()
|
||||||
|
s.add("foo")
|
||||||
|
s[0] += "bar"
|
||||||
|
return if(s[0] == "foobar") "OK" else "fail"
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
fun fill(dest : Array<in String>, v : String) {
|
||||||
|
dest[0] = v
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box() : String {
|
||||||
|
//fun main(args : Array<String>) {
|
||||||
|
val s : String = "bar"
|
||||||
|
val any : Array<Any> = arrayOf(1, "foo", 1.234)
|
||||||
|
fill(any, s)
|
||||||
|
/* shouldn't throw
|
||||||
|
ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;
|
||||||
|
*/
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
fun Array<String>.test1(): Array<String> {
|
||||||
|
val func = { i:Int -> this}
|
||||||
|
return func(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Array<String>.test1Nested(): Array<String> {
|
||||||
|
val func = { i: Int -> { this }()}
|
||||||
|
return func(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun Array<String>.test2() : Array<String> {
|
||||||
|
class Z2() {
|
||||||
|
fun run(): Array<String> {
|
||||||
|
return this@test2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Z2().run()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Array<String>.test2Nested() : Array<String> {
|
||||||
|
class Z2() {
|
||||||
|
fun run(): Array<String> {
|
||||||
|
class Z3 {
|
||||||
|
fun run(): Array<String> {
|
||||||
|
return this@test2Nested;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Z3().run()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Z2().run()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Array<String>.test3(): Array<String> {
|
||||||
|
fun local(): Array<String> {
|
||||||
|
return this@test3
|
||||||
|
}
|
||||||
|
return local()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Array<String>.test3Nested(): Array<String> {
|
||||||
|
fun local(): Array<String> {
|
||||||
|
fun local2(): Array<String> {
|
||||||
|
return this@test3Nested
|
||||||
|
}
|
||||||
|
return local2()
|
||||||
|
}
|
||||||
|
return local()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun Array<String>.test4() : Array<String> {
|
||||||
|
return object {
|
||||||
|
fun run() : Array<String> {
|
||||||
|
return this@test4
|
||||||
|
}
|
||||||
|
}.run()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Array<String>.test4Nested() : Array<String> {
|
||||||
|
return object {
|
||||||
|
fun run() : Array<String> {
|
||||||
|
return object {
|
||||||
|
fun run() : Array<String> {
|
||||||
|
return this@test4Nested
|
||||||
|
}
|
||||||
|
}.run()
|
||||||
|
}
|
||||||
|
}.run()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Array<DoubleArray>.test1(): Array<DoubleArray> {
|
||||||
|
val func = { i: Int -> this}
|
||||||
|
return func(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun box() : String {
|
||||||
|
val array = Array<String>(2, { i -> "${i}" })
|
||||||
|
if (array != array.test1()) return "fail 1"
|
||||||
|
if (array != array.test2()) return "fail 2"
|
||||||
|
if (array != array.test3()) return "fail 3"
|
||||||
|
if (array != array.test4()) return "fail 4"
|
||||||
|
|
||||||
|
if (array != array.test1Nested()) return "fail 1Nested"
|
||||||
|
if (array != array.test2Nested()) return "fail 2Nested"
|
||||||
|
if (array != array.test3Nested()) return "fail 3Nested"
|
||||||
|
if (array != array.test4Nested()) return "fail 4Nested"
|
||||||
|
|
||||||
|
val array2 = Array<DoubleArray>(2, { i -> DoubleArray(i) })
|
||||||
|
if (array2 != array2.test1()) return "fail on array of double []"
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
operator fun String.get(vararg value: Any) : String {
|
||||||
|
return if (value[0] == 44 && value[1] == "example") "OK" else "fail"
|
||||||
|
}
|
||||||
|
|
||||||
|
operator fun Int.get(vararg value: Any) : Int {
|
||||||
|
return if (value[0] == 44 && value[1] == "example") 1 else 0
|
||||||
|
}
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
12 [44, "example"]
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
if ("foo" [44, "example"] != "OK") return "fail1"
|
||||||
|
if (11 [44, "example"] != 1) return "fail2"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fun box(): String {
|
||||||
|
val array = intArrayOf(11, 12, 13)
|
||||||
|
val p = array.get(0)
|
||||||
|
if (p != 11) return "fail 1: $p"
|
||||||
|
|
||||||
|
val stringArray = arrayOf("OK", "FAIL")
|
||||||
|
return stringArray.get(0)
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
fun iarr(vararg a : Int) = a
|
||||||
|
fun <T> array(vararg a : T) = a
|
||||||
|
|
||||||
|
fun box() : String {
|
||||||
|
val tests = array<IntArray>(
|
||||||
|
iarr(6, 5, 4, 3, 2, 1),
|
||||||
|
iarr(1, 2),
|
||||||
|
iarr(1, 2, 3),
|
||||||
|
iarr(1, 2, 3, 4),
|
||||||
|
iarr(1)
|
||||||
|
)
|
||||||
|
|
||||||
|
var n = 0
|
||||||
|
|
||||||
|
try {
|
||||||
|
var i = 0
|
||||||
|
while (true) {
|
||||||
|
if (thirdElementIsThree(tests[i++]))
|
||||||
|
n++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e : ArrayIndexOutOfBoundsException) {
|
||||||
|
// No more tests to process
|
||||||
|
}
|
||||||
|
return if(n == 2) "OK" else "fail"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun thirdElementIsThree(a : IntArray) =
|
||||||
|
a.size >= 3 && a[2] == 3
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package array_test
|
||||||
|
|
||||||
|
fun box() : String {
|
||||||
|
var array : IntArray? = IntArray(10)
|
||||||
|
array?.set(0, 3)
|
||||||
|
if(array?.get(0) != 3) return "fail"
|
||||||
|
|
||||||
|
var a = arrayOfNulls<Array<String?>>(5)
|
||||||
|
var b = arrayOfNulls<String>(1)
|
||||||
|
b.set(0, "239")
|
||||||
|
a?.set(0, b)
|
||||||
|
|
||||||
|
if(a?.get(0)?.get(0) != "239") return "fail"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun box() = if(arrayOfNulls<Int>(10).isArrayOf<java.lang.Integer>()) "OK" else "fail"
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun box() : String {
|
||||||
|
val value = (1 to doubleArrayOf(1.0)).second[0]
|
||||||
|
return if (value == 1.0) "OK" else "fail"
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
fun test(b: Boolean): String {
|
||||||
|
val a = if (b) IntArray(5) else LongArray(5)
|
||||||
|
if (a is IntArray) {
|
||||||
|
val x = a.iterator()
|
||||||
|
var i = 0
|
||||||
|
while (x.hasNext()) {
|
||||||
|
if (a[i] != x.next()) return "Fail $i"
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
return "OK"
|
||||||
|
} else if (a is LongArray) {
|
||||||
|
val x = a.iterator()
|
||||||
|
var i = 0
|
||||||
|
while (x.hasNext()) {
|
||||||
|
if (a[i] != x.next()) return "Fail $i"
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
return "fail"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
if (test(true) != "OK") return "fail 1: ${test(true)}"
|
||||||
|
|
||||||
|
if (test(false) != "OK") return "fail 1: ${test(false)}"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun foo(x : Any): String {
|
||||||
|
return if(x is Array<*> && x.isArrayOf<String>()) (x as Array<String>)[0] else "fail"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
return foo(arrayOf("OK"))
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
val <T> Array<T>.length : Int get() = this.size
|
||||||
|
|
||||||
|
fun box() = if(arrayOfNulls<Int>(10).length == 10) "OK" else "fail"
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
fun box() : String {
|
||||||
|
val data = Array<Array<Boolean>>(3) { Array<Boolean>(4, {false}) }
|
||||||
|
for(d in data) {
|
||||||
|
if(d.size != 4) return "fail"
|
||||||
|
for(b in d) if (b) return "fail"
|
||||||
|
}
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
operator fun <K, V> MutableMap<K, V>.set(k : K, v : V) = put(k, v)
|
||||||
|
|
||||||
|
fun box() : String {
|
||||||
|
val map = HashMap<String,String>()
|
||||||
|
map["239"] = "932"
|
||||||
|
return if(map["239"] == "932") "OK" else "fail"
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
operator fun IntArray.set(index: Long, elem: Int) { this[index.toInt()] = elem }
|
||||||
|
operator fun IntArray.get(index: Long) = this[index.toInt()]
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
var l = IntArray(1)
|
||||||
|
l[0.toLong()] = 4
|
||||||
|
l[0.toLong()] += 6
|
||||||
|
return if (l[0.toLong()] == 10) "OK" else "Fail"
|
||||||
|
}
|
||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
fun stringMultiArray(): Array<Array<String>> = Array(3) {
|
||||||
|
i -> Array(3) { j -> "$i-$j" }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun stringNullableMultiArray(): Array<Array<String?>> = Array(3) {
|
||||||
|
i -> if (i == 1) Array(3) { j -> "$i-$j" } as Array<String?> else arrayOfNulls<String>(3)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val matrix = stringMultiArray()
|
||||||
|
|
||||||
|
for (i in 0..2) {
|
||||||
|
for (j in 0..2) {
|
||||||
|
assertEquals("$i-$j", matrix[i][j], "matrix")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val matrixNullable = stringNullableMultiArray()
|
||||||
|
|
||||||
|
for (j in 0..2) {
|
||||||
|
assertEquals(null, matrixNullable[0][j], "nullable")
|
||||||
|
assertEquals("1-$j", matrixNullable[1][j], "nullable")
|
||||||
|
assertEquals(null, matrixNullable[2][j], "nullable")
|
||||||
|
}
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
class C(val i: Int) {
|
||||||
|
operator fun component1() = i + 1
|
||||||
|
operator fun component2() = i + 2
|
||||||
|
}
|
||||||
|
|
||||||
|
fun doTest(l : Array<C>): String {
|
||||||
|
var s = ""
|
||||||
|
for ((a, b) in l) {
|
||||||
|
s += "$a:$b;"
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val l = Array<C>(3, {x -> C(x)})
|
||||||
|
val s = doTest(l)
|
||||||
|
return if (s == "1:2;2:3;3:4;") "OK" else "fail: $s"
|
||||||
|
}
|
||||||
Vendored
+19
@@ -0,0 +1,19 @@
|
|||||||
|
class C(val i: Int) {
|
||||||
|
}
|
||||||
|
|
||||||
|
operator fun C.component1() = i + 1
|
||||||
|
operator fun C.component2() = i + 2
|
||||||
|
|
||||||
|
fun doTest(l : Array<C>): String {
|
||||||
|
var s = ""
|
||||||
|
for ((a, b) in l) {
|
||||||
|
s += "$a:$b;"
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val l = Array<C>(3, {x -> C(x)})
|
||||||
|
val s = doTest(l)
|
||||||
|
return if (s == "1:2;2:3;3:4;") "OK" else "fail: $s"
|
||||||
|
}
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
class C(val i: Int) {
|
||||||
|
}
|
||||||
|
|
||||||
|
class M {
|
||||||
|
operator fun C.component1() = i + 1
|
||||||
|
operator fun C.component2() = i + 2
|
||||||
|
|
||||||
|
fun doTest(l : Array<C>): String {
|
||||||
|
var s = ""
|
||||||
|
for ((a, b) in l) {
|
||||||
|
s += "$a:$b;"
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val l = Array<C>(3, {x -> C(x)})
|
||||||
|
val s = M().doTest(l)
|
||||||
|
return if (s == "1:2;2:3;3:4;") "OK" else "fail: $s"
|
||||||
|
}
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
class C(val i: Int) {
|
||||||
|
}
|
||||||
|
|
||||||
|
class M {
|
||||||
|
operator fun C.component1() = i + 1
|
||||||
|
operator fun C.component2() = i + 2
|
||||||
|
}
|
||||||
|
|
||||||
|
fun M.doTest(l : Array<C>): String {
|
||||||
|
var s = ""
|
||||||
|
for ((a, b) in l) {
|
||||||
|
s += "$a:$b;"
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val l = Array<C>(3, {x -> C(x)})
|
||||||
|
val s = M().doTest(l)
|
||||||
|
return if (s == "1:2;2:3;3:4;") "OK" else "fail: $s"
|
||||||
|
}
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
class C(val i: Int) {
|
||||||
|
operator fun component1() = i + 1
|
||||||
|
operator fun component2() = i + 2
|
||||||
|
}
|
||||||
|
|
||||||
|
fun doTest(l : Array<C>): String {
|
||||||
|
var s = ""
|
||||||
|
for ((a, b) in l) {
|
||||||
|
s += {"$a:$b;"}()
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val l = Array<C>(3, {x -> C(x)})
|
||||||
|
val s = doTest(l)
|
||||||
|
return if (s == "1:2;2:3;3:4;") "OK" else "fail: $s"
|
||||||
|
}
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
operator fun Int.component1() = this + 1
|
||||||
|
operator fun Int.component2() = this + 2
|
||||||
|
|
||||||
|
fun doTest(l : Array<Int>): String {
|
||||||
|
var s = ""
|
||||||
|
for ((a, b) in l) {
|
||||||
|
s += "$a:$b;"
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val l = Array<Int>(3, {x -> x})
|
||||||
|
val s = doTest(l)
|
||||||
|
return if (s == "1:2;2:3;3:4;") "OK" else "fail: $s"
|
||||||
|
}
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
operator fun Int.component1() = this + 1
|
||||||
|
operator fun Int.component2() = this + 2
|
||||||
|
|
||||||
|
fun doTest(l : Array<Int>): String {
|
||||||
|
var s = ""
|
||||||
|
for ((a, b) in l) {
|
||||||
|
s += {"$a:$b;"}()
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val l = Array<Int>(3, {x -> x})
|
||||||
|
val s = doTest(l)
|
||||||
|
return if (s == "1:2;2:3;3:4;") "OK" else "fail: $s"
|
||||||
|
}
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
class M {
|
||||||
|
operator fun Int.component1() = this + 1
|
||||||
|
operator fun Int.component2() = this + 2
|
||||||
|
|
||||||
|
fun doTest(l : Array<Int>): String {
|
||||||
|
var s = ""
|
||||||
|
for ((a, b) in l) {
|
||||||
|
s += "$a:$b;"
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val l = Array<Int>(3, {x -> x})
|
||||||
|
val s = M().doTest(l)
|
||||||
|
return if (s == "1:2;2:3;3:4;") "OK" else "fail: $s"
|
||||||
|
}
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
class M {
|
||||||
|
operator fun Int.component1() = this + 1
|
||||||
|
operator fun Int.component2() = this + 2
|
||||||
|
}
|
||||||
|
|
||||||
|
fun M.doTest(l : Array<Int>): String {
|
||||||
|
var s = ""
|
||||||
|
for ((a, b) in l) {
|
||||||
|
s += "$a:$b;"
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val l = Array<Int>(3, {x -> x})
|
||||||
|
val s = M().doTest(l)
|
||||||
|
return if (s == "1:2;2:3;3:4;") "OK" else "fail: $s"
|
||||||
|
}
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
operator fun Long.component1() = this + 1
|
||||||
|
operator fun Long.component2() = this + 2
|
||||||
|
|
||||||
|
fun doTest(l : Array<Long>): String {
|
||||||
|
var s = ""
|
||||||
|
for ((a, b) in l) {
|
||||||
|
s += "$a:$b;"
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val l = Array<Long>(3, {x -> x.toLong()})
|
||||||
|
val s = doTest(l)
|
||||||
|
return if (s == "1:2;2:3;3:4;") "OK" else "fail: $s"
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user