mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-08 08:31:26 +00:00
tests added
This commit is contained in:
committed by
Alexander Udalov
parent
e53e4fe257
commit
0f5e29df9b
@@ -0,0 +1,22 @@
|
||||
|
||||
inline fun <R, T> foo(x : R?, block : (R?) -> T) : T {
|
||||
return block(x)
|
||||
}
|
||||
|
||||
fun bar() {
|
||||
foo(1) { x -> x!!.toLong() }
|
||||
foo(1) { x -> x!!.toShort() }
|
||||
foo(1L) { x -> x!!.toByte() }
|
||||
foo(1L) { x -> x!!.toShort() }
|
||||
foo('a') { x -> x!!.toDouble() }
|
||||
foo(1.0) { x -> x!!.toByte() }
|
||||
}
|
||||
|
||||
// 0 valueOf
|
||||
// 0 Value\s\(\)
|
||||
// 1 I2L
|
||||
// 2 L2I
|
||||
// 2 I2S
|
||||
// 2 I2B
|
||||
// 1 I2D
|
||||
// 1 D2I
|
||||
@@ -0,0 +1,23 @@
|
||||
|
||||
inline fun <R, T> foo(x : R, y : R, block : (R) -> T) : T {
|
||||
val a = x is Number
|
||||
val b = x is Object
|
||||
|
||||
val a1 = x as Number
|
||||
val b1 = x as Object
|
||||
|
||||
if (a && b) {
|
||||
return block(x)
|
||||
} else {
|
||||
return block(y)
|
||||
}
|
||||
}
|
||||
|
||||
fun bar() {
|
||||
foo(1, 2) { x -> x is Int }
|
||||
}
|
||||
|
||||
// 0 valueOf
|
||||
// 0 Value\s\(\)
|
||||
// 2 INSTANCEOF
|
||||
// 2 CHECKCAST
|
||||
@@ -0,0 +1,13 @@
|
||||
|
||||
fun foo() : Long {
|
||||
val x = LongArray(5)
|
||||
|
||||
for (i in 0..4) {
|
||||
x[i] = (i + 1).toLong()
|
||||
}
|
||||
|
||||
return x.fold(0L) { x, y -> x + y }
|
||||
}
|
||||
|
||||
// 0 valueOf
|
||||
// 0 Value\s\(\)
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
inline fun <R, T> foo(x : R?, y : R?, block : (R?) -> T) : T {
|
||||
if (x == null) {
|
||||
return block(x)
|
||||
} else {
|
||||
return block(y)
|
||||
}
|
||||
}
|
||||
|
||||
fun bar() {
|
||||
foo(1, 2) { x -> if (x != null) 1 else 2 }
|
||||
}
|
||||
|
||||
// 0 valueOf
|
||||
// 0 Value\s\(\)
|
||||
// 1 IFNULL
|
||||
// 0 IFNONNULL
|
||||
@@ -0,0 +1,37 @@
|
||||
|
||||
inline fun <R, T : Iterable<R>> foo(x : T, block : (R) -> R) : R {
|
||||
val y = x.iterator()
|
||||
if (y.hasNext()) {
|
||||
return block(y.next())
|
||||
} else {
|
||||
throw RuntimeException()
|
||||
}
|
||||
}
|
||||
|
||||
fun bar() {
|
||||
foo((1..100)) { x -> x + 1 }
|
||||
foo((1L..100L)) { x -> x + 1 }
|
||||
foo((1.0.toDouble()..2.0.toDouble())) { x -> x + 1 }
|
||||
foo((1.0f..2.0f)) { x -> x + 1 }
|
||||
foo((1.toByte()..100.toByte())) { x -> x }
|
||||
foo((1.toShort()..100.toShort())) { x -> x }
|
||||
foo(('a'..'z')) { x -> x }
|
||||
|
||||
foo(IntRange(1, 100)) { x -> x + 1 }
|
||||
foo(LongRange(1L, 100L)) { x -> x + 1 }
|
||||
foo(DoubleRange(1.0, 2.0)) { x -> x + 1 }
|
||||
foo(FloatRange(1.0f, 2.0f)) { x -> x + 1 }
|
||||
foo(ByteRange(1.toByte(), 100.toByte())) { x -> x }
|
||||
foo(ShortRange(1.toShort(), 100.toShort())) { x -> x }
|
||||
foo(CharRange('a', 'z')) { x -> x }
|
||||
}
|
||||
|
||||
// 1 next\s\(
|
||||
// 2 nextInt
|
||||
// 2 nextLong
|
||||
// 2 nextDouble
|
||||
// 2 nextFloat
|
||||
// 2 nextByte
|
||||
// 2 nextShort
|
||||
// 2 nextChar
|
||||
// 0 Value\s\(\)
|
||||
@@ -0,0 +1,9 @@
|
||||
class A(val x : Int, val y : A?)
|
||||
|
||||
fun check(a : A?) : Int {
|
||||
return a?.y?.x ?: (a?.x ?: 3)
|
||||
}
|
||||
|
||||
// 0 valueOf
|
||||
// 0 Value\s\(\)
|
||||
// 0 ACONST_NULL
|
||||
@@ -0,0 +1,34 @@
|
||||
|
||||
inline fun <R, T> foo(x : R, y : R, block : (R, R) -> T) : T {
|
||||
return block(x, y)
|
||||
}
|
||||
|
||||
fun bar() {
|
||||
foo(1, 2) { x, y -> x + y }
|
||||
foo(1L, 2L) { x, y -> x + y }
|
||||
foo(1f, 2f) { x, y -> x + y }
|
||||
foo(1.toDouble(), 2.toDouble()) { x, y -> x + y }
|
||||
foo(1.toByte(), 2.toByte()) { x, y -> x + y }
|
||||
foo(1.toShort(), 2.toShort()) { x, y -> x + y }
|
||||
foo('a', 'b') { x, y -> x == y }
|
||||
foo(true, false) { x, y -> x || y }
|
||||
}
|
||||
|
||||
// 0 valueOf
|
||||
// 0 Value\s\(\)
|
||||
// 1 LOCALVARIABLE x I L6 L11 5
|
||||
// 1 LOCALVARIABLE y I L6 L11 4
|
||||
// 1 LOCALVARIABLE x J L19 L24 6
|
||||
// 1 LOCALVARIABLE y J L19 L24 4
|
||||
// 1 LOCALVARIABLE x F L32 L37 5
|
||||
// 1 LOCALVARIABLE y F L32 L37 4
|
||||
// 1 LOCALVARIABLE x D L45 L50 6
|
||||
// 1 LOCALVARIABLE y D L45 L50 4
|
||||
// 1 LOCALVARIABLE x B L58 L63 5
|
||||
// 1 LOCALVARIABLE y B L58 L63 4
|
||||
// 1 LOCALVARIABLE x S L71 L76 5
|
||||
// 1 LOCALVARIABLE y S L71 L76 4
|
||||
// 1 LOCALVARIABLE x C L84 L91 5
|
||||
// 1 LOCALVARIABLE y C L84 L91 4
|
||||
// 1 LOCALVARIABLE x Z L99 L106 5
|
||||
// 1 LOCALVARIABLE y Z L99 L106 4
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
inline fun foo(x : Int, block : (Int) -> Int) : Int {
|
||||
return block(x)
|
||||
}
|
||||
|
||||
fun bar() {
|
||||
foo(1) { x -> x + 1 }
|
||||
}
|
||||
|
||||
// 1 java/lang/Integer.valueOf
|
||||
// 1 intValue
|
||||
@@ -0,0 +1,28 @@
|
||||
fun returningBoxed() : Int? = 1
|
||||
fun acceptingBoxed(x : Int?) : Int ? = x
|
||||
|
||||
class A(var x : Int? = null)
|
||||
|
||||
fun foo() {
|
||||
val rb = returningBoxed()
|
||||
acceptingBoxed(2)
|
||||
|
||||
val a = A()
|
||||
a.x = 3
|
||||
|
||||
val b = Array<Int?>(4, { null })
|
||||
b[100] = 5
|
||||
|
||||
val x = 6 : Int?
|
||||
val hc = x!!.hashCode()
|
||||
|
||||
val y = 7 : Int?
|
||||
val z = 8 : Int?
|
||||
val res = y.identityEquals(z)
|
||||
|
||||
val c1: Any = if (1 == 1) 0 else "abc"
|
||||
val c2: Any = if (1 != 1) 0 else "abc"
|
||||
}
|
||||
|
||||
// 10 java/lang/Integer.valueOf
|
||||
// 1 intValue
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
fun bar() {
|
||||
var x : Object? = java.lang.Integer.valueOf(1) as Object?
|
||||
|
||||
val y1 : Int = (x as Int?)!!
|
||||
|
||||
x = java.lang.Long.valueOf(1) as Object?
|
||||
|
||||
val y2 : Long = (x as Long?)!!
|
||||
}
|
||||
|
||||
// 2 valueOf
|
||||
// 1 intValue
|
||||
// 1 longValue
|
||||
@@ -0,0 +1,21 @@
|
||||
|
||||
inline fun <R, T> foo(x : R, block : (R) -> T) : T {
|
||||
var y = x
|
||||
var z = y
|
||||
z = x
|
||||
return block(z)
|
||||
}
|
||||
|
||||
fun bar() {
|
||||
foo(1) { x -> x }
|
||||
foo(1f) { x -> x }
|
||||
foo(1L) { x -> x }
|
||||
foo(1.toDouble()) { x -> x }
|
||||
foo(1.toShort()) { x -> x }
|
||||
foo(1.toByte()) { x -> x }
|
||||
foo('a') { x -> x }
|
||||
foo(true) { x -> x }
|
||||
}
|
||||
|
||||
// 0 valueOf
|
||||
// 0 Value\s\(\)
|
||||
Reference in New Issue
Block a user