JS: move expressions test to box tests
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
val a = arrayOf(1, 2, 3)
|
||||
val b = arrayOf(1, 2, 3)
|
||||
val c = a
|
||||
|
||||
if (a == b) return "fail1"
|
||||
if (a != c) return "fail2"
|
||||
if (c == b) return "fail3"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// KT-3518 Null pointer during null comparison in JS Backend
|
||||
package foo
|
||||
|
||||
class MyClazz(val nullableL : List<String>?)
|
||||
|
||||
fun box(): String {
|
||||
val a = MyClazz(null)
|
||||
if(a.nullableL != null) return "a.nullableL != null"
|
||||
|
||||
val b = MyClazz(listOf("somthing"))
|
||||
if(b.nullableL == null) return "b.nullableL == null"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package foo
|
||||
|
||||
class A {
|
||||
override fun equals(other: Any?) = this === other
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a: A? = null
|
||||
val b: A? = null
|
||||
val c: A? = A()
|
||||
val d: A? = A()
|
||||
val e: A = A()
|
||||
|
||||
// compare nullable vals with null
|
||||
testTrue { a == b }
|
||||
testTrue { a == a }
|
||||
testFalse { a != b }
|
||||
testFalse { a != a }
|
||||
|
||||
// compare null and non-null inside nullable vals
|
||||
testFalse { a == c }
|
||||
testTrue { a != c }
|
||||
testFalse { c == a }
|
||||
testTrue { c != a }
|
||||
|
||||
// compare nullables vals with non-null
|
||||
testFalse { c == d }
|
||||
testTrue { c == c }
|
||||
testTrue { c != d }
|
||||
testFalse { d == c }
|
||||
testTrue { d != c }
|
||||
testFalse { d != d }
|
||||
|
||||
// compare nullable val with null with non-nullable
|
||||
testFalse { a == e }
|
||||
testTrue { a != e }
|
||||
testFalse { e == a }
|
||||
testTrue { e != a }
|
||||
|
||||
// compare nullable val with non-null with non-nullable
|
||||
testFalse { c == e }
|
||||
testTrue { c != e }
|
||||
testFalse { e == c }
|
||||
testTrue { e != c }
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package foo
|
||||
|
||||
class A {
|
||||
override fun equals(other: Any?) = super.equals(other)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a: A? = null
|
||||
|
||||
testTrue { a == null }
|
||||
testFalse { a != null }
|
||||
testTrue { null == a }
|
||||
testFalse { null != a }
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package foo
|
||||
|
||||
class Foo(val name: String) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is Foo) {
|
||||
return false
|
||||
}
|
||||
return this.name == other.name
|
||||
}
|
||||
}
|
||||
|
||||
fun callEqualsMethod(v1: Foo?, v2: Foo?): Boolean {
|
||||
return v1 == v2
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = Foo("abc")
|
||||
val b = Foo("abc")
|
||||
val c = Foo("def")
|
||||
|
||||
if (!callEqualsMethod(a, b)) return "fail1"
|
||||
if (callEqualsMethod(a, c)) return "fail2"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package foo
|
||||
|
||||
class Foo(val name: String) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is Foo) {
|
||||
return false
|
||||
}
|
||||
return this.name == other.name
|
||||
}
|
||||
}
|
||||
|
||||
fun callEqualsMethod(v1: Any?, v2: Any?): Boolean {
|
||||
return v1 == v2
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = Foo("abc")
|
||||
val b = Foo("abc")
|
||||
val c = Foo("def")
|
||||
|
||||
if (!callEqualsMethod(a, b)) return "fail1"
|
||||
if (callEqualsMethod(a, c)) return "fail2"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package foo
|
||||
|
||||
var log = ""
|
||||
|
||||
class A {
|
||||
override fun equals(o: Any?): Boolean {
|
||||
log += "$o;"
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
|
||||
assertTrue(a.equals("aaa"))
|
||||
assertEquals("aaa;", log)
|
||||
assertFalse(a == null)
|
||||
assertEquals("aaa;", log)
|
||||
assertTrue(a.equals(null))
|
||||
assertEquals("aaa;null;", log)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
val a: Int? = null
|
||||
val r = a == null
|
||||
if (!r || a != null)
|
||||
return "wrong result on simple nullable check"
|
||||
|
||||
//force using Kotlin.equals
|
||||
val t = null
|
||||
if (t != undefined)
|
||||
return "wrong result when compare null and undefined using Kotlin.equals"
|
||||
|
||||
var i = 0;
|
||||
fun foo(): Int? = ++i;
|
||||
if (foo() == null)
|
||||
return "wrong result on nullable check with side effects"
|
||||
|
||||
if (i != 1)
|
||||
return "wrong affects when using nullable check with side effects"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package foo
|
||||
|
||||
class Foo(val name: String) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is Foo) {
|
||||
return false
|
||||
}
|
||||
return this.name == other.name
|
||||
}
|
||||
}
|
||||
|
||||
class Bar() {
|
||||
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = Foo("abc")
|
||||
val b = Foo("abc")
|
||||
val c = Foo("def")
|
||||
|
||||
if (!(a.equals(b))) return "fail1"
|
||||
if (a.equals(c)) return "fail2"
|
||||
if (Bar().equals(Bar())) return "fail3"
|
||||
val g = Bar()
|
||||
if (!(g.equals(g))) return "fail4"
|
||||
if (g.equals(Bar())) return "fail5"
|
||||
return "OK"
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
val a = 2
|
||||
if (!(a.equals(a))) return "fail1"
|
||||
if (!(a.equals(2))) return "fail2"
|
||||
if (!(a.equals(2.0))) return "fail3"
|
||||
val c = "a"
|
||||
if (!("a".equals(c))) return "fail4"
|
||||
if (!((null as Any?)?.equals(null) ?: true)) return "fail5"
|
||||
val d = 5.6
|
||||
if (!(d.toShort().equals(5.toShort()))) return "fail6"
|
||||
if (!(d.toByte().equals(5.toByte()))) return "fail7"
|
||||
if (!(d.toFloat().equals(5.6.toFloat()))) return "fail8"
|
||||
if (!(d.toInt().equals(5))) return "fail9"
|
||||
if (true.equals(false)) return "fail10"
|
||||
|
||||
val n: Number = 3
|
||||
if (!(n.equals(3.3.toInt()))) return "fail11"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package foo
|
||||
|
||||
import java.util.*
|
||||
|
||||
fun box(): String {
|
||||
val data = ArrayList<String>()
|
||||
data.add("foo")
|
||||
data.add("bar")
|
||||
data.add("whatnot")
|
||||
val data2 = ArrayList<String>()
|
||||
data2.addAll(data)
|
||||
return if (data.equals(data2)) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
val a = "abc"
|
||||
val b = "abc"
|
||||
val c = "def"
|
||||
|
||||
if (a != b) return "fail1"
|
||||
if (a == c) return "fail2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package foo
|
||||
|
||||
open class A {
|
||||
var log = ""
|
||||
|
||||
var called = false
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (called) fail("recursion detected")
|
||||
|
||||
log += "A.equals;"
|
||||
|
||||
called = true
|
||||
val result = super.equals(other)
|
||||
called = false
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
class B : A() {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
log += "B.equals;"
|
||||
if (other == null) return false
|
||||
return super.equals(other)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
testFalse { a == A() }
|
||||
assertEquals("A.equals;", a.log)
|
||||
|
||||
val b1 = B()
|
||||
testTrue { b1 == b1 }
|
||||
assertEquals("B.equals;A.equals;", b1.log)
|
||||
|
||||
val b2 = B()
|
||||
testFalse { b2 == B() }
|
||||
assertEquals("B.equals;A.equals;", b2.log)
|
||||
|
||||
val b3 = B()
|
||||
testFalse { b3 == null }
|
||||
assertEquals("", b3.log)
|
||||
|
||||
val b4 = B()
|
||||
testFalse { b4.equals(null) }
|
||||
assertEquals("B.equals;", b4.log)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user