JS backend: tests for KT-2468

This commit is contained in:
Michael Nedzelsky
2014-10-10 14:53:47 +04:00
parent cff0c35987
commit edac2dd3bd
5 changed files with 132 additions and 12 deletions
@@ -0,0 +1,97 @@
// KT-2468 ArrayList<String> is List<String> or HashSet<String> is Set<String> fails in generated JS code
package foo
import java.util.*
data class A
fun checkAbstractList(obj: Any) {
assertTrue(obj is AbstractList<*>, "checkAbstractList: is AbstractList")
assertTrue(obj is MutableList<*>, "checkAbstractList: is MutableList")
assertTrue(obj is List<*>, "checkAbstractList: is List")
assertTrue(obj is AbstractCollection<*>, "checkAbstractList: is AbstractCollection")
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 AbstractCollection<*>, "checkHashSet: is AbstractCollection")
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<*, *>).keySet() is Set, "checkHashMap: keySet() 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,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(): Any) is List<*>, "stdlib_emptyListClass() is List<*> #2")
assertTrue((stdlib_emptyListClass(): 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"
}