Rework tests on Number.toChar with custom Number subclass
Simplify them, move to a subfolder, add a couple of new tests.
This commit is contained in:
committed by
Space Team
parent
a64d8e8a31
commit
a962ec4553
@@ -1,38 +0,0 @@
|
||||
// DONT_TARGET_EXACT_BACKEND: JVM
|
||||
// DONT_TARGET_EXACT_BACKEND: JS
|
||||
// IGNORE_BACKEND: JVM_IR, JS_IR
|
||||
// KT-46465
|
||||
// WITH_STDLIB
|
||||
|
||||
class MyNumber(val b: Boolean) : Number() {
|
||||
override fun toByte(): Byte {
|
||||
return toInt().toByte()
|
||||
}
|
||||
|
||||
override fun toDouble(): Double {
|
||||
return toInt().toDouble()
|
||||
}
|
||||
|
||||
override fun toFloat(): Float {
|
||||
return toInt().toFloat()
|
||||
}
|
||||
|
||||
override fun toInt(): Int {
|
||||
return if (b) { 'O'.code } else { 'K'.code }
|
||||
}
|
||||
|
||||
override fun toLong(): Long {
|
||||
return toInt().toLong()
|
||||
}
|
||||
|
||||
override fun toShort(): Short {
|
||||
return toInt().toShort()
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
fun box(): String {
|
||||
val o = MyNumber(true)
|
||||
val k = MyNumber(false)
|
||||
return "${o.toChar()}${k.toChar()}"
|
||||
}
|
||||
-42
@@ -1,42 +0,0 @@
|
||||
// DONT_TARGET_EXACT_BACKEND: JVM
|
||||
// DONT_TARGET_EXACT_BACKEND: JS
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// KT-46465
|
||||
// WITH_STDLIB
|
||||
|
||||
class MyNumber(val b: Boolean) : Number() {
|
||||
override fun toByte(): Byte {
|
||||
return toInt().toByte()
|
||||
}
|
||||
|
||||
override fun toDouble(): Double {
|
||||
return toInt().toDouble()
|
||||
}
|
||||
|
||||
override fun toFloat(): Float {
|
||||
return toInt().toFloat()
|
||||
}
|
||||
|
||||
override fun toChar(): Char {
|
||||
return super.toChar()
|
||||
}
|
||||
|
||||
override fun toInt(): Int {
|
||||
return if (b) { 'O'.code } else { 'K'.code }
|
||||
}
|
||||
|
||||
override fun toLong(): Long {
|
||||
return toInt().toLong()
|
||||
}
|
||||
|
||||
override fun toShort(): Short {
|
||||
return toInt().toShort()
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
fun box(): String {
|
||||
val o = MyNumber(true)
|
||||
val k = MyNumber(false)
|
||||
return "${o.toChar()}${k.toChar()}"
|
||||
}
|
||||
-41
@@ -1,41 +0,0 @@
|
||||
// DONT_TARGET_EXACT_BACKEND: JVM
|
||||
// DONT_TARGET_EXACT_BACKEND: JS
|
||||
// KT-46465
|
||||
// WITH_STDLIB
|
||||
|
||||
interface Some {
|
||||
fun toChar(): Char
|
||||
}
|
||||
|
||||
class MyNumber(val b: Boolean) : Number() {
|
||||
override fun toByte(): Byte {
|
||||
return toInt().toByte()
|
||||
}
|
||||
|
||||
override fun toDouble(): Double {
|
||||
return toInt().toDouble()
|
||||
}
|
||||
|
||||
override fun toFloat(): Float {
|
||||
return toInt().toFloat()
|
||||
}
|
||||
|
||||
override fun toInt(): Int {
|
||||
return if (b) { 'O'.code } else { 'K'.code }
|
||||
}
|
||||
|
||||
override fun toLong(): Long {
|
||||
return toInt().toLong()
|
||||
}
|
||||
|
||||
override fun toShort(): Short {
|
||||
return toInt().toShort()
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
fun box(): String {
|
||||
val o = MyNumber(true)
|
||||
val k = MyNumber(false)
|
||||
return "${o.toChar()}${k.toChar()}"
|
||||
}
|
||||
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
// DONT_TARGET_EXACT_BACKEND: JVM
|
||||
// DONT_TARGET_EXACT_BACKEND: JS
|
||||
// IGNORE_BACKEND: JS_IR, JS_IR_ES6
|
||||
// ISSUE: KT-46465
|
||||
// WITH_STDLIB
|
||||
|
||||
interface Some {
|
||||
fun toChar(): Char
|
||||
}
|
||||
|
||||
class MyNumber(val value: Int) : Number(), Some {
|
||||
override fun toInt(): Int = value
|
||||
|
||||
override fun toByte(): Byte = toInt().toByte()
|
||||
override fun toDouble(): Double = toInt().toDouble()
|
||||
override fun toFloat(): Float = toInt().toFloat()
|
||||
override fun toLong(): Long = toInt().toLong()
|
||||
override fun toShort(): Short = toInt().toShort()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val x = MyNumber('*'.code).toChar()
|
||||
return if (x == '*') "OK" else "Fail: $x"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// DONT_TARGET_EXACT_BACKEND: JVM
|
||||
// DONT_TARGET_EXACT_BACKEND: JS
|
||||
// ISSUE: KT-46465
|
||||
// WITH_STDLIB
|
||||
|
||||
open class MyNumber(val value: Int) : Number() {
|
||||
override fun toChar(): Char = '+'
|
||||
override fun toInt(): Int = value
|
||||
|
||||
override fun toByte(): Byte = toInt().toByte()
|
||||
override fun toDouble(): Double = toInt().toDouble()
|
||||
override fun toFloat(): Float = toInt().toFloat()
|
||||
override fun toLong(): Long = toInt().toLong()
|
||||
override fun toShort(): Short = toInt().toShort()
|
||||
}
|
||||
|
||||
class MyNumberImpl(value: Int) : MyNumber(value)
|
||||
|
||||
fun box(): String {
|
||||
val x = MyNumberImpl('*'.code).toChar()
|
||||
return if (x == '+') "OK" else "Fail: $x"
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// ISSUE: KT-23447
|
||||
// WITH_STDLIB
|
||||
|
||||
// FILE: MyNumber.java
|
||||
|
||||
public class MyNumber extends Number {
|
||||
private final int value;
|
||||
|
||||
public MyNumber(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int intValue() { return value; }
|
||||
|
||||
@Override
|
||||
public long longValue() { return 0; }
|
||||
|
||||
@Override
|
||||
public float floatValue() { return 0; }
|
||||
|
||||
@Override
|
||||
public double doubleValue() { return 0; }
|
||||
}
|
||||
|
||||
// FILE: box.kt
|
||||
|
||||
fun box(): String {
|
||||
val x = MyNumber('*'.code).toChar()
|
||||
if (x != '*') return "Fail 1: $x"
|
||||
|
||||
val y = java.lang.Integer('+'.code).toChar()
|
||||
if (y != '+') return "Fail 2: $y"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// DONT_TARGET_EXACT_BACKEND: JVM
|
||||
// DONT_TARGET_EXACT_BACKEND: JS
|
||||
// IGNORE_BACKEND: JS_IR, JS_IR_ES6
|
||||
// ISSUE: KT-46465
|
||||
// WITH_STDLIB
|
||||
|
||||
class MyNumber(val value: Int) : Number() {
|
||||
override fun toInt(): Int = value
|
||||
|
||||
override fun toByte(): Byte = toInt().toByte()
|
||||
override fun toDouble(): Double = toInt().toDouble()
|
||||
override fun toFloat(): Float = toInt().toFloat()
|
||||
override fun toLong(): Long = toInt().toLong()
|
||||
override fun toShort(): Short = toInt().toShort()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val x = MyNumber('*'.code).toChar()
|
||||
return if (x == '*') "OK" else "Fail: $x"
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// DONT_TARGET_EXACT_BACKEND: JVM
|
||||
// DONT_TARGET_EXACT_BACKEND: JS
|
||||
// ISSUE: KT-46465
|
||||
// WITH_STDLIB
|
||||
|
||||
open class MyNumber(val value: Int) : Number() {
|
||||
override fun toChar(): Char = '+'
|
||||
override fun toInt(): Int = value
|
||||
|
||||
override fun toByte(): Byte = toInt().toByte()
|
||||
override fun toDouble(): Double = toInt().toDouble()
|
||||
override fun toFloat(): Float = toInt().toFloat()
|
||||
override fun toLong(): Long = toInt().toLong()
|
||||
override fun toShort(): Short = toInt().toShort()
|
||||
}
|
||||
|
||||
class MyNumberImpl(value: Int) : MyNumber(value) {
|
||||
override fun toChar(): Char = super.toChar()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val x = MyNumberImpl('*'.code).toChar()
|
||||
return if (x == '+') "OK" else "Fail: $x"
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// DONT_TARGET_EXACT_BACKEND: JVM
|
||||
// DONT_TARGET_EXACT_BACKEND: JS
|
||||
// ISSUE: KT-46465
|
||||
// WITH_STDLIB
|
||||
|
||||
interface Some {
|
||||
fun toChar(): Char = '+'
|
||||
}
|
||||
|
||||
class MyNumber(val value: Int) : Number(), Some {
|
||||
override fun toChar(): Char = super<Some>.toChar()
|
||||
override fun toInt(): Int = value
|
||||
|
||||
override fun toByte(): Byte = toInt().toByte()
|
||||
override fun toDouble(): Double = toInt().toDouble()
|
||||
override fun toFloat(): Float = toInt().toFloat()
|
||||
override fun toLong(): Long = toInt().toLong()
|
||||
override fun toShort(): Short = toInt().toShort()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val x = MyNumber('*'.code).toChar()
|
||||
return if (x == '+') "OK" else "Fail: $x"
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// DONT_TARGET_EXACT_BACKEND: JVM
|
||||
// DONT_TARGET_EXACT_BACKEND: JS
|
||||
// IGNORE_BACKEND: JS_IR, JS_IR_ES6
|
||||
// ISSUE: KT-46465
|
||||
// WITH_STDLIB
|
||||
|
||||
class MyNumber(val value: Int) : Number() {
|
||||
override fun toChar(): Char = super.toChar()
|
||||
override fun toInt(): Int = value
|
||||
|
||||
override fun toByte(): Byte = toInt().toByte()
|
||||
override fun toDouble(): Double = toInt().toDouble()
|
||||
override fun toFloat(): Float = toInt().toFloat()
|
||||
override fun toLong(): Long = toInt().toLong()
|
||||
override fun toShort(): Short = toInt().toShort()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val x = MyNumber('*'.code).toChar()
|
||||
return if (x == '*') "OK" else "Fail: $x"
|
||||
}
|
||||
Reference in New Issue
Block a user