tests: Update external tests (1.1.2-dev-393)
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
val Int.test: String get() = "test"
|
||||
|
||||
fun box(): String {
|
||||
val x = "a ${1.test}"
|
||||
return if (x == "a test") "OK" else "Fail $x"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(): Int {
|
||||
var sum = 0
|
||||
for (c in "239")
|
||||
sum += (c.toInt() - '0'.toInt())
|
||||
return sum
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val f = foo()
|
||||
return if (f == 14) "OK" else "Fail $f"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fun test(p: String?): String {
|
||||
return "${p ?: "Default"} test"
|
||||
}
|
||||
fun box(): String {
|
||||
if (test(null) != "Default test") return "fail 1: ${test(null)}"
|
||||
if (test("Good") != "Good test") return "fail 1: ${test("OK")}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
fun box(): String {
|
||||
String()
|
||||
return String() + "OK" + String()
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
class Thing(delegate: CharSequence) : CharSequence by delegate
|
||||
|
||||
fun box(): String {
|
||||
val l = Thing("hello there").length
|
||||
return if (l == 11) "OK" else "Fail $l"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fun box(): String {
|
||||
var a = 'a'
|
||||
|
||||
if ("${a++}x" != "ax") return "fail1"
|
||||
|
||||
if ("${a++}" != "b") return "fail2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
fun box(): String {
|
||||
val sb = StringBuilder("OK")
|
||||
return "${sb.get(0)}${sb[1]}"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// KT-5956 java.lang.AbstractMethodError: test.Thing.subSequence(II)Ljava/lang/CharSequence
|
||||
|
||||
class Thing(val delegate: CharSequence) : CharSequence {
|
||||
override fun get(index: Int): Char {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
override val length: Int get() = 0
|
||||
override fun subSequence(start: Int, end: Int) = delegate.subSequence(start, end)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val txt = Thing("hello there")
|
||||
val s = txt.subSequence(0, 1)
|
||||
return if ("$s" == "h") "OK" else "Fail: $s"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
fun box() : String {
|
||||
val b = 1+1
|
||||
if ("$b" != "2") return "fail"
|
||||
if ("${1+1}" != "2") return "fail"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
operator fun Int.plus(s: String) : String {
|
||||
System.out?.println("Int.plus(s: String) called")
|
||||
return s
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val s = "${1 + "a"}"
|
||||
return if(s == "a") "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
fun stringConcat(n : Int) : String? {
|
||||
var string : String? = ""
|
||||
for (i in 0..(n - 1))
|
||||
string += "LOL "
|
||||
return string
|
||||
}
|
||||
|
||||
fun box() = if(stringConcat(3) == "LOL LOL LOL ") "OK" else "fail"
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
fun box() : String {
|
||||
val s = "abc"
|
||||
val test1 = """$s"""
|
||||
if (test1 != "abc") return "Fail 1: $test1"
|
||||
|
||||
val test2 = """${s}"""
|
||||
if (test2 != "abc") return "Fail 2: $test2"
|
||||
|
||||
val test3 = """ "$s" """
|
||||
if (test3 != " \"abc\" ") return "Fail 3: $test3"
|
||||
|
||||
val test4 = """ "${s}" """
|
||||
if (test4 != " \"abc\" ") return "Fail 4: $test4"
|
||||
|
||||
val test5 =
|
||||
"""
|
||||
${s.length}
|
||||
"""
|
||||
if (test5 != "\n 3\n") return "Fail 5: $test5"
|
||||
|
||||
val test6 = """\n"""
|
||||
if (test6 != "\\n") return "Fail 6: $test6"
|
||||
|
||||
val test7 = """\${'$'}foo"""
|
||||
if (test7 != "\\\$foo") return "Fail 7: $test7"
|
||||
|
||||
val test8 = """$ foo"""
|
||||
if (test8 != "$ foo") return "Fail 8: $test8"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
fun box() : String {
|
||||
val s = """ foo \n bar """
|
||||
if (s != " foo \\n bar ") return "Fail: '$s'"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
class P(val actual: String, val expected: String)
|
||||
fun array(vararg s: P) = s
|
||||
|
||||
fun box() : String {
|
||||
val data = array(
|
||||
P("""""", ""),
|
||||
P(""""""", "\""),
|
||||
P("""""""", "\"\""),
|
||||
P(""""""""", "\"\"\""),
|
||||
P("""""""""", "\"\"\"\""),
|
||||
P("""" """, "\" "),
|
||||
P(""""" """, "\"\" "),
|
||||
P(""" """", " \""),
|
||||
P(""" """"", " \"\""),
|
||||
P(""" """""", " \"\"\""),
|
||||
P(""" """"""", " \"\"\"\""),
|
||||
P(""" """""""", " \"\"\"\"\""),
|
||||
P("""" """", "\" \""),
|
||||
P(""""" """"", "\"\" \"\"")
|
||||
)
|
||||
|
||||
for (i in 0..data.size-1) {
|
||||
val p = data[i]
|
||||
if (p.actual != p.expected) return "Fail at #$i. actual='${p.actual}', expected='${p.expected}'"
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
class A() {
|
||||
|
||||
override fun toString(): String {
|
||||
return "A"
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
|
||||
val s = "1" + "2" + 3 + 4L + 5.0 + 6F + '7' + A()
|
||||
|
||||
if (s != "12345.06.07A") return "fail $s"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun box(): String {
|
||||
var x: MutableCollection<Int> = ArrayList()
|
||||
x + ArrayList()
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user