Stdlib: run all stdlib tests with JS backend(as possible).
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package test.compare
|
||||
|
||||
import java.util.Comparator
|
||||
import kotlin.test.*
|
||||
import org.junit.Test
|
||||
|
||||
@@ -35,34 +34,4 @@ class CompareTest {
|
||||
val diff = compareBy(v1, v1, { rating }, { name })
|
||||
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")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,10 +5,10 @@ import java.math.BigInteger
|
||||
import java.math.BigDecimal
|
||||
|
||||
import kotlin.test.*
|
||||
import junit.framework.TestCase
|
||||
import org.junit.Test as test
|
||||
|
||||
class MathTest : TestCase() {
|
||||
fun testBigInteger() {
|
||||
class MathTest {
|
||||
test fun testBigInteger() {
|
||||
val a = BigInteger("2")
|
||||
val b = BigInteger("3")
|
||||
|
||||
@@ -21,7 +21,7 @@ class MathTest : TestCase() {
|
||||
assertEquals(BigInteger("-2"), -a remainder b)
|
||||
}
|
||||
|
||||
fun testBigDecimal() {
|
||||
test fun testBigDecimal() {
|
||||
val a = BigDecimal("2")
|
||||
val b = BigDecimal("3")
|
||||
|
||||
|
||||
@@ -2,26 +2,25 @@ package test.collections
|
||||
|
||||
import kotlin.*
|
||||
import kotlin.io.*
|
||||
import kotlin.util.*
|
||||
import kotlin.test.*
|
||||
import java.util.*
|
||||
import java.io.*
|
||||
import junit.framework.TestCase
|
||||
import org.junit.Test as test
|
||||
|
||||
class OldStdlibTest() : TestCase() {
|
||||
fun testCollectionEmpty() {
|
||||
class OldStdlibTest() {
|
||||
test fun testCollectionEmpty() {
|
||||
assertNot {
|
||||
Arrays.asList(0, 1, 2).empty
|
||||
listOf(0, 1, 2).empty
|
||||
}
|
||||
}
|
||||
|
||||
fun testCollectionSize() {
|
||||
test fun testCollectionSize() {
|
||||
assertTrue {
|
||||
Arrays.asList(0, 1, 2).size == 3
|
||||
listOf(0, 1, 2).size == 3
|
||||
}
|
||||
}
|
||||
|
||||
fun testInputStreamIterator() {
|
||||
test fun testInputStreamIterator() {
|
||||
val x = ByteArray (10)
|
||||
|
||||
for(index in 0..9) {
|
||||
@@ -29,7 +28,7 @@ class OldStdlibTest() : TestCase() {
|
||||
}
|
||||
|
||||
for(b in x.inputStream) {
|
||||
System.out.println(b)
|
||||
println(b)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
package test.stdlib.issues
|
||||
|
||||
import kotlin.util.*
|
||||
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> {
|
||||
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 filterValues = arrayList("bar", "something", "blah")
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package test.tuples
|
||||
|
||||
import kotlin.test.assertTrue
|
||||
import org.junit.Test as test
|
||||
import kotlin.test.assertTrue
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNotEquals
|
||||
|
||||
class PairTest {
|
||||
val p = Pair(1, "a")
|
||||
@@ -23,69 +24,69 @@ class PairTest {
|
||||
}
|
||||
|
||||
test fun pairEquals() {
|
||||
assertTrue(p == Pair(1, "a"))
|
||||
assertTrue(p != Pair(2, "a"))
|
||||
assertTrue(p != Pair(1, "b"))
|
||||
assertEquals(Pair(1, "a"), p)
|
||||
assertNotEquals(Pair(2, "a"), p)
|
||||
assertNotEquals(Pair(1, "b"), p)
|
||||
assertTrue(!p.equals(null))
|
||||
assertTrue((p : Any) != "")
|
||||
assertNotEquals("", (p : Any))
|
||||
}
|
||||
|
||||
test fun pairHashCode() {
|
||||
assertTrue(p.hashCode() == Pair(1, "a").hashCode())
|
||||
assertTrue(p.hashCode() != Pair(2, "a").hashCode())
|
||||
assertTrue(Pair(null, "b").hashCode() != 0)
|
||||
assertTrue(Pair("b", null).hashCode() != 0)
|
||||
assertTrue(Pair(null, null).hashCode() == 0)
|
||||
assertEquals(Pair(1, "a").hashCode(), p.hashCode())
|
||||
assertNotEquals(Pair(2, "a").hashCode(), p.hashCode())
|
||||
assertNotEquals(0, Pair(null, "b").hashCode())
|
||||
assertNotEquals(0, Pair("b", null).hashCode())
|
||||
assertEquals(0, Pair(null, null).hashCode())
|
||||
}
|
||||
|
||||
test fun pairHashSet() {
|
||||
val s = hashSet(Pair(1, "a"), Pair(1, "b"), Pair(1, "a"))
|
||||
assertTrue(s.size == 2)
|
||||
assertEquals(2, s.size)
|
||||
assertTrue(s.contains(p))
|
||||
}
|
||||
}
|
||||
|
||||
class TripleTest {
|
||||
val t = Triple(1, "a", 0.0)
|
||||
val t = Triple(1, "a", 0.07)
|
||||
|
||||
test fun tripleFirstAndSecond() {
|
||||
assertTrue(t.first == 1)
|
||||
assertTrue(t.second == "a")
|
||||
assertTrue(t.third == 0.0)
|
||||
assertEquals(1, t.first)
|
||||
assertEquals("a", t.second)
|
||||
assertEquals(0.07, t.third)
|
||||
}
|
||||
|
||||
test fun tripleMultiAssignment() {
|
||||
val (a, b, c) = t
|
||||
assertTrue(a == 1)
|
||||
assertTrue(b == "a")
|
||||
assertTrue(c == 0.0)
|
||||
assertEquals(1, a)
|
||||
assertEquals("a", b)
|
||||
assertEquals(0.07, c)
|
||||
}
|
||||
|
||||
test fun tripleToString() {
|
||||
assertEquals("(1, a, 0.0)", t.toString())
|
||||
assertEquals("(1, a, 0.07)", t.toString())
|
||||
}
|
||||
|
||||
test fun tripleEquals() {
|
||||
assertTrue(t == Triple(1, "a", 0.0))
|
||||
assertTrue(t != Triple(2, "a", 0.0))
|
||||
assertTrue(t != Triple(1, "b", 0.0))
|
||||
assertTrue(t != Triple(1, "a", 0.1))
|
||||
assertEquals(Triple(1, "a", 0.07), t)
|
||||
assertNotEquals(Triple(2, "a", 0.07), t)
|
||||
assertNotEquals(Triple(1, "b", 0.07), t)
|
||||
assertNotEquals(Triple(1, "a", 0.1), t)
|
||||
assertTrue(!t.equals(null))
|
||||
assertTrue((t : Any) != "")
|
||||
assertNotEquals("", (t : Any))
|
||||
}
|
||||
|
||||
test fun tripleHashCode() {
|
||||
assertTrue(t.hashCode() == Triple(1, "a", 0.0).hashCode())
|
||||
assertTrue(t.hashCode() != Triple(2, "a", 0.0).hashCode())
|
||||
assertTrue(Triple(null, "b", 0.0).hashCode() != 0)
|
||||
assertTrue(Triple("b", null, 0.0).hashCode() != 0)
|
||||
assertTrue(Triple("b", 1, null).hashCode() != 0)
|
||||
assertTrue(Triple(null, null, null).hashCode() == 0)
|
||||
assertEquals(Triple(1, "a", 0.07).hashCode(), t.hashCode())
|
||||
assertNotEquals(Triple(2, "a", 0.07).hashCode(), t.hashCode())
|
||||
assertNotEquals(0, Triple(null, "b", 0.07).hashCode())
|
||||
assertNotEquals(0, Triple("b", null, 0.07).hashCode())
|
||||
assertNotEquals(0, Triple("b", 1, null).hashCode())
|
||||
assertEquals(0, Triple(null, null, null).hashCode())
|
||||
}
|
||||
|
||||
test fun tripleHashSet() {
|
||||
val s = hashSet(Triple(1, "a", 0.0), Triple(1, "b", 0.0), Triple(1, "a", 0.0))
|
||||
assertTrue(s.size == 2)
|
||||
val s = hashSet(Triple(1, "a", 0.07), Triple(1, "b", 0.07), Triple(1, "a", 0.07))
|
||||
assertEquals(2, s.size)
|
||||
assertTrue(s.contains(t))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,10 @@ class CollectionJVMTest {
|
||||
}
|
||||
}
|
||||
|
||||
test fun first() {
|
||||
assertEquals(19, TreeSet(arrayListOf(90, 47, 19)).first())
|
||||
}
|
||||
|
||||
test fun last() {
|
||||
val data = arrayListOf("foo", "bar")
|
||||
assertEquals("bar", data.last())
|
||||
@@ -85,28 +89,19 @@ class CollectionJVMTest {
|
||||
assertTrue(linkedListOf(15, 19, 20).contains(15))
|
||||
}
|
||||
|
||||
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 toArray() {
|
||||
val data = arrayListOf("foo", "bar")
|
||||
val arr = data.toArray()
|
||||
println("Got array ${arr}")
|
||||
assertEquals(2, arr.size)
|
||||
todo {
|
||||
assertTrue {
|
||||
arr is Array<String>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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 }
|
||||
test fun takeReturnsFirstNElements() {
|
||||
expect(setOf(1, 2)) { sortedSetOf(1, 2, 3, 4, 5).take(2).toSet() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,9 +30,10 @@ class CollectionTest {
|
||||
assertEquals(2, foo.size)
|
||||
assertEquals(arrayListOf("foo", "bar"), foo)
|
||||
|
||||
assertTrue {
|
||||
foo is List<String>
|
||||
}
|
||||
// TODO uncomment this when KT-2468 will be fixed
|
||||
// assertTrue {
|
||||
// foo is List<String>
|
||||
// }
|
||||
}
|
||||
|
||||
test fun mapNotNull() {
|
||||
@@ -41,9 +42,10 @@ class CollectionTest {
|
||||
assertEquals(2, foo.size)
|
||||
assertEquals(arrayListOf(3, 3), foo)
|
||||
|
||||
assertTrue {
|
||||
foo is List<Int>
|
||||
}
|
||||
// TODO uncomment this when KT-2468 will be fixed
|
||||
// assertTrue {
|
||||
// foo is List<Int>
|
||||
// }
|
||||
}
|
||||
|
||||
test fun filterIntoSet() {
|
||||
@@ -148,7 +150,9 @@ class CollectionTest {
|
||||
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 }
|
||||
}
|
||||
}
|
||||
@@ -159,7 +163,9 @@ class CollectionTest {
|
||||
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 }
|
||||
}
|
||||
}
|
||||
@@ -229,7 +235,10 @@ class CollectionTest {
|
||||
assertEquals(arrayListOf("foo", "bar"), notNull)
|
||||
|
||||
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
|
||||
hasNulls.requireNoNulls()
|
||||
}
|
||||
@@ -277,9 +286,9 @@ class CollectionTest {
|
||||
assertEquals(arrayListOf("foo", "bar", "abc"), coll.takeWhile { it.size == 3 })
|
||||
}
|
||||
|
||||
test fun toArray() {
|
||||
test fun copyToArray() {
|
||||
val data = arrayListOf("foo", "bar")
|
||||
val arr = data.toArray()
|
||||
val arr = data.copyToArray()
|
||||
println("Got array ${arr}")
|
||||
assertEquals(2, arr.size)
|
||||
todo {
|
||||
@@ -297,7 +306,11 @@ class CollectionTest {
|
||||
}
|
||||
|
||||
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() {
|
||||
@@ -344,7 +357,6 @@ class CollectionTest {
|
||||
assertTrue(arrayListOf(15, 19, 20).contains(15))
|
||||
|
||||
assertTrue(IterableWrapper(hashSetOf(45, 14, 13)).contains(14))
|
||||
assertFalse(IterableWrapper(linkedListOf<Int>()).contains(15))
|
||||
}
|
||||
|
||||
test fun sortForMutableIterable() {
|
||||
@@ -436,6 +448,29 @@ class CollectionTest {
|
||||
expect(listOf<Long>()) { listOf(1L) take 0 }
|
||||
expect(listOf(1)) { (1..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
|
||||
fun fold() {
|
||||
|
||||
expect(231) { data.fold(1, {a, b -> a + if (b == "foo") 200 else 30 }) }
|
||||
}
|
||||
|
||||
Test
|
||||
fun reduce() {
|
||||
|
||||
val reduced = data.reduce {a, b -> a + b }
|
||||
assertEquals(6, reduced.size)
|
||||
assertTrue(reduced == "foobar" || reduced == "barfoo")
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ import kotlin.test.assertEquals
|
||||
import org.junit.Test as test
|
||||
|
||||
// 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(
|
||||
sequence: Progression<N>,
|
||||
expectedStart: N,
|
||||
+1
-1
@@ -5,7 +5,7 @@ import java.lang.Float as jFloat
|
||||
import org.junit.Test as test
|
||||
import kotlin.test.*
|
||||
|
||||
public class RangeTestJVM {
|
||||
public class RangeJVMTest {
|
||||
|
||||
test fun doubleRange() {
|
||||
val range = -1.0..3.14159265358979
|
||||
@@ -1,9 +1,7 @@
|
||||
package language
|
||||
|
||||
import kotlin.util.*
|
||||
import java.util.*
|
||||
|
||||
import junit.framework.TestCase
|
||||
import org.junit.Test as test
|
||||
import kotlin.test.*
|
||||
|
||||
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?
|
||||
// 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)))
|
||||
|
||||
fun testExpressions(): Unit {
|
||||
println(customerTemplate(customer))
|
||||
test fun testExpressions(): Unit {
|
||||
assertEquals(EXPECTED, customerTemplate(customer))
|
||||
}
|
||||
}
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package test.text
|
||||
|
||||
import kotlin.*
|
||||
import kotlin.test.*
|
||||
import kotlin.util.*
|
||||
import org.junit.Test as test
|
||||
|
||||
class StringUtilTest() {
|
||||
|
||||
@@ -32,51 +32,50 @@
|
||||
<delete dir="${basedir}/target/tests" failonerror="false"/>
|
||||
<mkdir dir="${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">
|
||||
<include name="ArraysTest.kt"/>
|
||||
<include name="GetOrElseTest.kt"/>
|
||||
<include name="StringTest.kt"/>
|
||||
<include name="**/*.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="**/*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>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
Reference in New Issue
Block a user