JS: move more test to box tests
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
// KT-2468 ArrayList<String> is List<String> or HashSet<String> is Set<String> fails in generated JS code
|
||||
package foo
|
||||
|
||||
class A
|
||||
|
||||
fun checkAbstractList(obj: Any) {
|
||||
assertTrue(obj is AbstractMutableList<*>, "checkAbstractList: is AbstractMutableList")
|
||||
assertTrue(obj is MutableList<*>, "checkAbstractList: is MutableList")
|
||||
assertTrue(obj is List<*>, "checkAbstractList: is List")
|
||||
assertTrue(obj is AbstractMutableCollection<*>, "checkAbstractList: is AbstractMutableCollection")
|
||||
assertTrue(obj is MutableCollection<*>, "checkAbstractList: is MutableCollection")
|
||||
assertTrue(obj is Collection<*>, "checkAbstractList: is Collection")
|
||||
assertTrue(obj is MutableIterable<*>, "checkAbstractList: is MutableIterable")
|
||||
assertTrue(obj is Iterable<*>, "checkAbstractList: is Iterable")
|
||||
assertTrue((obj as Iterable<*>).iterator() is Iterator, "checkAbstractList: iterator() is Iterator")
|
||||
}
|
||||
|
||||
fun checkArrayList(obj: Any) {
|
||||
assertTrue(obj is ArrayList<*>, "checkArrayList: is ArrayList")
|
||||
assertTrue((obj as Iterable<*>).iterator() is MutableIterator, "checkAbstractList: iterator() is MutableIterator")
|
||||
checkAbstractList(obj)
|
||||
}
|
||||
|
||||
fun checkHashSet(obj: Any) {
|
||||
assertTrue(obj is HashSet<*>, "checkHashSet: is HashSet")
|
||||
assertTrue(obj is AbstractMutableSet<*>, "checkHashSet: is AbstractMutableSet")
|
||||
assertTrue(obj is AbstractMutableCollection<*>, "checkHashSet: is AbstractMutableCollection")
|
||||
assertTrue(obj is MutableCollection<*>, "checkHashSet: is MutableCollection")
|
||||
assertTrue(obj is Collection<*>, "checkHashSet: is Collection")
|
||||
assertTrue(obj is MutableIterable<*>, "checkHashSet: is MutableIterable")
|
||||
assertTrue(obj is Iterable<*>, "checkHashSet: is Iterable")
|
||||
assertTrue(obj is MutableSet<*>, "checkHashSet: is MutableSet")
|
||||
assertTrue(obj is Set<*>, "checkHashSet: is Set")
|
||||
assertTrue((obj as Set<*>).iterator() is Iterator, "checkHashSet: iterator() is Iterator")
|
||||
assertTrue((obj as Set<*>).iterator() is MutableIterator, "checkHashSet: iterator() is MutableIterator")
|
||||
}
|
||||
|
||||
fun checkLinkedHashSet(obj: Any) {
|
||||
assertTrue(obj is LinkedHashSet<*>, "checkLinkedHashSet: is LinkedHashSet")
|
||||
checkHashSet(obj)
|
||||
}
|
||||
|
||||
fun checkHashMap(obj: Any) {
|
||||
assertTrue(obj is HashMap<*, *>, "checkHashMap: is HashMap")
|
||||
assertTrue(obj is MutableMap<*, *>, "checkHashMap: is MutableMap")
|
||||
assertTrue(obj is Map<*, *>, "checkHashMap: is Map")
|
||||
assertTrue((obj as Map<*, *>).values is Collection, "checkHashMap: values is Collection")
|
||||
assertTrue((obj as Map<*, *>).keys is Set, "checkHashMap: keys is Set")
|
||||
}
|
||||
|
||||
fun checkLinkedHashMap(obj: Any) {
|
||||
assertTrue(obj is LinkedHashMap<*, *>, "checkLinkedHashMap: is LinkedHashMap")
|
||||
checkHashMap(obj)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
checkArrayList(ArrayList<Int>())
|
||||
checkArrayList(arrayListOf(1, 2, 3))
|
||||
|
||||
checkArrayList(ArrayList<String>())
|
||||
checkArrayList(arrayListOf("first", "second"))
|
||||
|
||||
checkArrayList(ArrayList<A>())
|
||||
checkArrayList(arrayListOf(A()))
|
||||
|
||||
checkHashSet(HashSet<Int>())
|
||||
checkHashSet(hashSetOf(1))
|
||||
checkLinkedHashSet(LinkedHashSet<Int>(0))
|
||||
|
||||
checkHashSet(HashSet<Double>())
|
||||
checkHashSet(hashSetOf(1.0))
|
||||
checkLinkedHashSet(LinkedHashSet<Double>(0))
|
||||
|
||||
checkHashSet(HashSet<String>())
|
||||
checkHashSet(hashSetOf("test"))
|
||||
checkLinkedHashSet(LinkedHashSet<String>(0))
|
||||
|
||||
checkHashSet(HashSet<A>())
|
||||
checkHashSet(hashSetOf(A()))
|
||||
checkLinkedHashSet(LinkedHashSet<A>(0))
|
||||
|
||||
checkHashMap(HashMap<Int, String>())
|
||||
checkHashMap(hashMapOf(1 to "test"))
|
||||
checkLinkedHashMap(LinkedHashMap<Int, String>())
|
||||
|
||||
checkHashMap(HashMap<Double, String>())
|
||||
checkHashMap(hashMapOf(1.0 to "test"))
|
||||
checkLinkedHashMap(LinkedHashMap<Double, String>())
|
||||
|
||||
checkHashMap(HashMap<String, String>())
|
||||
checkHashMap(HashMap<A, String>())
|
||||
checkLinkedHashMap(LinkedHashMap<A, String>())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package foo
|
||||
|
||||
class A : Comparable<A> {
|
||||
override fun compareTo(other: A): Int = 0
|
||||
}
|
||||
|
||||
class B
|
||||
|
||||
fun test(x: Any?): Boolean = x is Comparable<*>
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(true, test(A()), "A()")
|
||||
assertEquals(true, test("abc"), "\"abc\"")
|
||||
assertEquals(true, test('a'), "\'a\'")
|
||||
assertEquals(true, test(0), "0")
|
||||
assertEquals(true, test(0.toChar()), "0.toChar()")
|
||||
assertEquals(true, test(0.toByte()), "0.toByte()")
|
||||
assertEquals(true, test(0.toShort()), "0.toShort()")
|
||||
assertEquals(true, test(0.toLong()), "0.toLong()")
|
||||
assertEquals(true, test(0.toDouble()), "0.toDouble()")
|
||||
assertEquals(true, test(0.toFloat()), "0.toFloat()")
|
||||
assertEquals(false, test(B()), "B()")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package foo
|
||||
|
||||
enum class Type {
|
||||
NUMBER,
|
||||
STRING,
|
||||
BOOLEAN,
|
||||
OBJECT
|
||||
}
|
||||
|
||||
fun test(a: Any, actualType: Type) {
|
||||
assertEquals(actualType == Type.NUMBER, a is Int, "$a is Int")
|
||||
assertEquals(actualType == Type.NUMBER, a is Number, "$a is Number")
|
||||
assertEquals(actualType == Type.NUMBER, a is Double, "$a is Double")
|
||||
assertEquals(actualType == Type.BOOLEAN, a is Boolean, "$a is Boolean")
|
||||
assertEquals(actualType == Type.STRING, a is String, "$a is String")
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
test(1, Type.NUMBER)
|
||||
|
||||
test(12.3, Type.NUMBER)
|
||||
test(12.3f, Type.NUMBER)
|
||||
|
||||
test("text", Type.STRING)
|
||||
|
||||
test(true, Type.BOOLEAN)
|
||||
test(false, Type.BOOLEAN)
|
||||
|
||||
test(object {}, Type.OBJECT)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package foo
|
||||
|
||||
object Obj
|
||||
|
||||
fun box(): String {
|
||||
val r: Any = Obj
|
||||
|
||||
if (r !is Obj) return "r !is Obj"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package foo
|
||||
|
||||
class A() {
|
||||
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(true, A() is A)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package foo
|
||||
|
||||
open class A() {
|
||||
|
||||
}
|
||||
|
||||
class B() : A() {
|
||||
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(true, A() !is B)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package foo
|
||||
|
||||
interface A
|
||||
interface B
|
||||
open class C
|
||||
open class D
|
||||
|
||||
fun box(): String {
|
||||
|
||||
if ((object {} as Any) is A) return "object {} is A"
|
||||
if ((object {} as Any) is C) return "object {} is C"
|
||||
|
||||
if ((object : A {} as Any) !is A) return "object : A {} !is A"
|
||||
if ((object : A {} as Any) is B) return "object : A {} is B"
|
||||
if ((object : A {} as Any) is C) return "object : A {} is C"
|
||||
|
||||
if ((object : C() {} as Any) is A) return "object : C() {} is A"
|
||||
if ((object : C() {} as Any) !is C) return "object : C() {} !is C"
|
||||
if ((object : C() {} as Any) is D) return "object : C() {} is D"
|
||||
|
||||
if ((object : B, D() {} as Any) is A) return "object : B, D() {} is A"
|
||||
if ((object : B, D() {} as Any) !is B) return "object : B, D() {} !is B"
|
||||
if ((object : B, D() {} as Any) is C) return "object : B, D() {} is C"
|
||||
if ((object : B, D() {} as Any) !is D) return "object : B, D() {} !is D"
|
||||
|
||||
if ((object : D(), B {} as Any) is A) return "object : D(), B {} is A"
|
||||
if ((object : D(), B {} as Any) !is B) return "object : D(), B {} !is B"
|
||||
if ((object : D(), B {} as Any) is C) return "object : D(), B {} is C"
|
||||
if ((object : D(), B {} as Any) !is D) return "object : D(), B {} !is D"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package foo
|
||||
|
||||
class C
|
||||
interface I
|
||||
|
||||
fun box(): String {
|
||||
val obj: Any = js("({})")
|
||||
|
||||
if (obj is C) return "obj is C"
|
||||
if (obj is I) return "obj is I"
|
||||
|
||||
val obj2: Any = js("Object.create(null)")
|
||||
|
||||
if (obj2 is C) return "obj2 is C"
|
||||
if (obj2 is I) return "obj2 is I"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package foo
|
||||
|
||||
class D
|
||||
|
||||
open class A
|
||||
|
||||
open class B : A()
|
||||
|
||||
open class C : B()
|
||||
|
||||
fun box(): String {
|
||||
val a: Any = A()
|
||||
val b: Any = B()
|
||||
val c: Any = C()
|
||||
if (a !is A) return "a !is A"
|
||||
|
||||
val t = a is A
|
||||
if (!t) return "t = a is A; t != true"
|
||||
|
||||
if (b !is A) return "b !is A"
|
||||
if (b !is B) return "b !is B"
|
||||
|
||||
if (c !is A) return "c !is A"
|
||||
if (c !is B) return "c !is B"
|
||||
if (c !is C) return "c !is C"
|
||||
|
||||
if (a is D) return "a is D"
|
||||
if (b is D) return "b is D"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package foo
|
||||
|
||||
|
||||
open class A
|
||||
|
||||
interface B
|
||||
|
||||
class C : A(), B
|
||||
|
||||
fun box(): String {
|
||||
|
||||
val a = A()
|
||||
val b = object : B {
|
||||
}
|
||||
val c = C()
|
||||
|
||||
if (a is B) return "a is B"
|
||||
if (b !is B) return "b !is B"
|
||||
if (c !is B) return "c !is B"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package foo
|
||||
|
||||
interface A
|
||||
interface B : A
|
||||
interface C : A
|
||||
interface D : B, C
|
||||
interface E : C
|
||||
|
||||
open class CB : B
|
||||
class CB2 : CB()
|
||||
|
||||
class CD : D
|
||||
|
||||
fun testPhrase(o: Any): String {
|
||||
var s = ""
|
||||
s += if (o is A) "Y" else "N"
|
||||
s += if (o is B) "Y" else "N"
|
||||
s += if (o is C) "Y" else "N"
|
||||
s += if (o is D) "Y" else "N"
|
||||
s += if (o is E) "Y" else "N"
|
||||
return s
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val b = CB()
|
||||
val b2 = CB2()
|
||||
val d = CD()
|
||||
val e = object : E {
|
||||
}
|
||||
|
||||
if (testPhrase(b) != "YYNNN") return "bad b, it: ${testPhrase(b)}"
|
||||
if (testPhrase(b2) != "YYNNN") return "bad b2, it: ${testPhrase(b2)}"
|
||||
if (testPhrase(d) != "YYYYN") return "bad d, it: ${testPhrase(d)}"
|
||||
if (testPhrase(e) != "YNYNY") return "bad e, it: ${testPhrase(e)}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package foo
|
||||
|
||||
var counter = 0
|
||||
|
||||
class A {
|
||||
fun getCounter(): Any? =
|
||||
when (counter++) {
|
||||
0 -> "0"
|
||||
1 -> null
|
||||
else -> counter
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(false, A().getCounter() is Int?, "(1)")
|
||||
assertEquals(true, A().getCounter() is Int?, "(2)")
|
||||
assertEquals(true, A().getCounter() is Int?, "(3)")
|
||||
assertEquals(3, counter)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package foo
|
||||
|
||||
var counter = 0
|
||||
|
||||
class A {
|
||||
val x: Any?
|
||||
get() =
|
||||
when (counter++) {
|
||||
0 -> "0"
|
||||
1 -> null
|
||||
else -> counter
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(false, A().x is Int?, "(1)")
|
||||
assertEquals(true, A().x is Int?, "(2)")
|
||||
assertEquals(true, A().x is Int?, "(3)")
|
||||
assertEquals(3, counter)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// KT-5192 JS compiler fails to generate correct code for List implementation
|
||||
package foo
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
class stdlib_emptyListClass : List<Any> by ArrayList<Any>() {}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
assertTrue(stdlib_emptyListClass() is List<*>, "stdlib_emptyListClass() is List<*> #1")
|
||||
assertTrue((stdlib_emptyListClass() as Any) is List<*>, "stdlib_emptyListClass() is List<*> #2")
|
||||
assertTrue((stdlib_emptyListClass() as Any) !is ArrayList<*>, "stdlib_emptyListClass() !is ArrayList<*>")
|
||||
|
||||
assertTrue(stdlib_emptyListClass().isEmpty(), "stdlib_emptyListClass().isEmpty()")
|
||||
assertTrue(stdlib_emptyListClass().size == 0, "stdlib_emptyListClass().size == 0")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user