JS backend: tests for KT-2468
This commit is contained in:
@@ -43,4 +43,12 @@ public class RTTITest extends SingleFileTranslationTest {
|
||||
public void testNotIsOtherClass() throws Exception {
|
||||
fooBoxTest();
|
||||
}
|
||||
|
||||
public void testCollectionClassesIsCheck() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testStdlibEmptyListClass() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
@@ -30,10 +30,9 @@ class CollectionTest {
|
||||
assertEquals(2, foo.size)
|
||||
assertEquals(arrayListOf("foo", "bar"), foo)
|
||||
|
||||
// TODO uncomment this when KT-2468 will be fixed
|
||||
// assertTrue {
|
||||
// foo is List<String>
|
||||
// }
|
||||
assertTrue {
|
||||
foo is List<String>
|
||||
}
|
||||
}
|
||||
|
||||
test fun mapNotNull() {
|
||||
@@ -42,10 +41,9 @@ class CollectionTest {
|
||||
assertEquals(2, foo.size)
|
||||
assertEquals(arrayListOf(3, 3), foo)
|
||||
|
||||
// TODO uncomment this when KT-2468 will be fixed
|
||||
// assertTrue {
|
||||
// foo is List<Int>
|
||||
// }
|
||||
assertTrue {
|
||||
foo is List<Int>
|
||||
}
|
||||
}
|
||||
|
||||
test fun filterIntoSet() {
|
||||
|
||||
@@ -105,8 +105,7 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
|
||||
|
||||
Test fun filter() {
|
||||
val foo = data.filter { it.startsWith("f") }
|
||||
// TODO uncomment this when KT-2468 will be fixed
|
||||
//expect(true) { foo is List<String> }
|
||||
expect(true) { foo is List<String> }
|
||||
expect(true) { foo.all { it.startsWith("f") } }
|
||||
expect(1) { foo.size }
|
||||
assertEquals(listOf("foo"), foo)
|
||||
@@ -114,8 +113,7 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
|
||||
|
||||
Test fun filterNot() {
|
||||
val notFoo = data.filterNot { it.startsWith("f") }
|
||||
// TODO uncomment this when KT-2468 will be fixed
|
||||
//expect(true) { notFoo is List<String> }
|
||||
expect(true) { notFoo is List<String> }
|
||||
expect(true) { notFoo.none { it.startsWith("f") } }
|
||||
expect(1) { notFoo.size }
|
||||
assertEquals(listOf("bar"), notFoo)
|
||||
|
||||
Reference in New Issue
Block a user