Stdlib: run all stdlib tests with JS backend(as possible).

This commit is contained in:
Zalim Bashorov
2014-10-10 17:10:17 +04:00
parent f20ee6df4b
commit f202ad9f98
18 changed files with 252 additions and 208 deletions
@@ -2,12 +2,11 @@ package test.properties
import kotlin.*
import kotlin.properties.*
import kotlin.util.*
import kotlin.test.*
import java.util.*
import junit.framework.TestCase
import org.junit.Test as test
class Customer() : ChangeSupport() {
class Customer : ChangeSupport() {
// TODO the setter code should be generated
// via KT-1299
var name: String? = null
@@ -25,7 +24,7 @@ class Customer() : ChangeSupport() {
override fun toString() = "Customer($name, $city)"
}
class MyChangeListener() : ChangeListener {
class MyChangeListener : ChangeListener {
val events = ArrayList<ChangeEvent>()
override fun onPropertyChange(event: ChangeEvent): Unit {
@@ -34,9 +33,9 @@ class MyChangeListener() : ChangeListener {
}
}
class PropertiesTest() : TestCase() {
class PropertiesTest {
fun testModel() {
test fun testModel() {
val c = Customer()
c.name = "James"
c.city = "Mells"
@@ -1,6 +1,6 @@
package test.properties.delegation
import junit.framework.TestCase
import org.junit.Test as test
import kotlin.test.*
import kotlin.properties.*
@@ -8,26 +8,26 @@ trait WithBox {
fun box(): String
}
abstract class DelegationTestBase: TestCase() {
abstract class DelegationTestBase {
fun doTest(klass: WithBox) {
assertEquals("OK", klass.box())
}
}
class DelegationTest(): DelegationTestBase() {
fun testNotNullVar() {
test fun testNotNullVar() {
doTest(TestNotNullVar("a", "b"))
}
fun testObservablePropertyInChangeSupport() {
test fun testObservablePropertyInChangeSupport() {
doTest(TestObservablePropertyInChangeSupport())
}
fun testObservableProperty() {
test fun testObservableProperty() {
doTest(TestObservableProperty())
}
fun testVetoableProperty() {
test fun testVetoableProperty() {
doTest(TestVetoableProperty())
}
}
@@ -82,6 +82,8 @@ class TestObservableProperty: WithBox {
}
}
class A(val p: Boolean)
class TestVetoableProperty: WithBox {
var result = false
var b by Delegates.vetoable(A(true), {(pd, o, n) -> result = n.p == true; result})
@@ -96,6 +98,4 @@ class TestVetoableProperty: WithBox {
if (result) return "fail4: result should be false"
return "OK"
}
class A(val p: Boolean)
}
@@ -1,53 +1,56 @@
package test.properties.delegation
import org.junit.Test as test
import java.util.HashMap
import kotlin.properties.*
class MapDelegationTest(): DelegationTestBase() {
fun testMapPropertyString() {
test fun testMapPropertyString() {
doTest(TestMapPropertyString())
}
fun testMapValWithDifferentTypes() {
test fun testMapValWithDifferentTypes() {
doTest(TestMapValWithDifferentTypes())
}
fun testMapVarWithDifferentTypes() {
test fun testMapVarWithDifferentTypes() {
doTest(TestMapVarWithDifferentTypes())
}
fun testNullableKey() {
test fun testNullableKey() {
doTest(TestNullableKey())
}
fun testMapPropertyKey() {
test fun testMapPropertyKey() {
doTest(TestMapPropertyKey())
}
fun testMapPropertyFunction() {
test fun testMapPropertyFunction() {
doTest(TestMapPropertyFunction())
}
fun testMapPropertyCustom() {
test fun testMapPropertyCustom() {
doTest(TestMapPropertyCustom())
}
fun testMapValWithDefault() {
test fun testMapValWithDefault() {
doTest(TestMapValWithDefault())
}
fun testMapVarWithDefault() {
test fun testMapVarWithDefault() {
doTest(TestMapVarWithDefault())
}
fun testMapPropertyCustomWithDefault() {
test fun testMapPropertyCustomWithDefault() {
doTest(TestMapPropertyCustomWithDefault())
}
}
data class B(val a: Int)
class TestMapValWithDifferentTypes(): WithBox {
val map = hashMapOf("a" to "a", "b" to 1, "c" to A(1), "d" to null)
val map = hashMapOf("a" to "a", "b" to 1, "c" to B(1), "d" to null)
val a by Delegates.mapVal<String>(map)
val b by Delegates.mapVal<Int>(map)
val c by Delegates.mapVal<Any>(map)
@@ -56,16 +59,14 @@ class TestMapValWithDifferentTypes(): WithBox {
override fun box(): String {
if (a != "a") return "fail at 'a'"
if (b != 1) return "fail at 'b'"
if (c != A(1)) return "fail at 'c'"
if (c != B(1)) return "fail at 'c'"
if (d != null) return "fail at 'd'"
return "OK"
}
data class A(val a: Int)
}
class TestMapVarWithDifferentTypes(): WithBox {
val map: HashMap<String, Any?> = hashMapOf("a" to "a", "b" to 1, "c" to A(1), "d" to "d")
val map: HashMap<String, Any?> = hashMapOf("a" to "a", "b" to 1, "c" to B(1), "d" to "d")
var a: String by Delegates.mapVar(map)
var b: Int by Delegates.mapVar(map)
var c by Delegates.mapVar<Any>(map)
@@ -74,16 +75,14 @@ class TestMapVarWithDifferentTypes(): WithBox {
override fun box(): String {
a = "aa"
b = 11
c = A(11)
c = B(11)
d = null
if (a != "aa") return "fail at 'a'"
if (b != 11) return "fail at 'b'"
if (c != A(11)) return "fail at 'c'"
if (c != B(11)) return "fail at 'c'"
if (d != null) return "fail at 'd'"
return "OK"
}
data class A(val a: Int)
}
class TestNullableKey: WithBox {
@@ -2,31 +2,32 @@ package test.properties.delegation.lazy
import test.properties.delegation.WithBox
import test.properties.delegation.DelegationTestBase
import org.junit.Test as test
import kotlin.properties.*
class LazyValuesTest(): DelegationTestBase() {
fun testLazyVal() {
test fun testLazyVal() {
doTest(TestLazyVal())
}
fun testNullableLazyVal() {
test fun testNullableLazyVal() {
doTest(TestNullableLazyVal())
}
fun testAtomicNullableLazyVal() {
test fun testAtomicNullableLazyVal() {
doTest(TestAtomicNullableLazyVal())
}
fun testAtomicLazyVal() {
test fun testAtomicLazyVal() {
doTest(TestAtomicLazyVal())
}
fun testVolatileNullableLazyVal() {
test fun testVolatileNullableLazyVal() {
doTest(TestVolatileNullableLazyVal())
}
fun testVolatileLazyVal() {
test fun testVolatileLazyVal() {
doTest(TestVolatileLazyVal())
}
}