Get rid of deprecated annotations and modifiers in stdlib (besides JS)

This commit is contained in:
Denis Zharkov
2015-09-14 16:35:30 +03:00
parent 9c4564a5a6
commit 5cecaa6f87
133 changed files with 1203 additions and 1085 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ class AnnotatedClass
class AnnotationTest {
test fun annotationType() {
@test fun annotationType() {
val annotations = javaClass<AnnotatedClass>().getAnnotations()!!
var foundMyAnno = false
+2 -1
View File
@@ -7,7 +7,8 @@ import java.io.Serializable
/**
*/
class DataClassTest {
Test fun dataClass() {
@Test
fun dataClass() {
val p = Person("James", 43)
println("Got $p")
assertEquals("Person(name=James, age=43)", "$p", "toString")
@@ -23,14 +23,14 @@ import kotlin.test.*
import org.junit.Test as test
class CompanionObjectsExtensionsTest {
test fun intTest() {
@test fun intTest() {
val i = Int
assertEquals(java.lang.Integer.MAX_VALUE, Int.MAX_VALUE)
assertEquals(java.lang.Integer.MIN_VALUE, Int.MIN_VALUE)
}
test fun doubleTest() {
@test fun doubleTest() {
val d = Double
assertEquals(java.lang.Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY)
@@ -41,7 +41,7 @@ class CompanionObjectsExtensionsTest {
assertEquals(java.lang.Double.MIN_VALUE, Double.MIN_VALUE)
}
test fun floatTest() {
@test fun floatTest() {
val f = Float
assertEquals(java.lang.Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY)
@@ -52,34 +52,34 @@ class CompanionObjectsExtensionsTest {
assertEquals(java.lang.Float.MIN_VALUE, Float.MIN_VALUE)
}
test fun longTest() {
@test fun longTest() {
val l = Long
assertEquals(java.lang.Long.MAX_VALUE, Long.MAX_VALUE)
assertEquals(java.lang.Long.MIN_VALUE, Long.MIN_VALUE)
}
test fun shortTest() {
@test fun shortTest() {
val s = Short
assertEquals(java.lang.Short.MAX_VALUE, Short.MAX_VALUE)
assertEquals(java.lang.Short.MIN_VALUE, Short.MIN_VALUE)
}
test fun byteTest() {
@test fun byteTest() {
val b = Byte
assertEquals(java.lang.Byte.MAX_VALUE, Byte.MAX_VALUE)
assertEquals(java.lang.Byte.MIN_VALUE, Byte.MIN_VALUE)
}
test fun charTest() {
@test fun charTest() {
val ch = Char
assertEquals(ch, Char)
}
test fun stringTest() {
@test fun stringTest() {
val s = String
assertEquals(s, String)
+2 -2
View File
@@ -9,12 +9,12 @@ import java.io.*
class ExceptionTest {
test fun printStackTraceOnRuntimeException() {
@test fun printStackTraceOnRuntimeException() {
assertPrintStackTrace(RuntimeException("Crikey!"))
assertPrintStackTraceStream(RuntimeException("Crikey2"))
}
test fun printStackTraceOnError() {
@test fun printStackTraceOnError() {
assertPrintStackTrace(Error("Oh dear"))
assertPrintStackTraceStream(Error("Oh dear2"))
}
+3 -3
View File
@@ -9,7 +9,7 @@ class GetOrElseTest {
val v2: String? = null
var counter = 0
test fun defaultValue() {
@test fun defaultValue() {
assertEquals("hello", v1?: "bar")
expect("hello") {
@@ -17,7 +17,7 @@ class GetOrElseTest {
}
}
test fun defaultValueOnNull() {
@test fun defaultValueOnNull() {
assertEquals("bar", v2?: "bar")
expect("bar") {
@@ -30,7 +30,7 @@ class GetOrElseTest {
return "bar"
}
test fun lazyDefaultValue() {
@test fun lazyDefaultValue() {
counter = 0
assertEquals("hello", v1?: calculateBar())
+2 -2
View File
@@ -8,7 +8,7 @@ import kotlin.test.*
import org.junit.Test as test
class MathTest {
test fun testBigInteger() {
@test fun testBigInteger() {
val a = BigInteger("2")
val b = BigInteger("3")
@@ -21,7 +21,7 @@ class MathTest {
assertEquals(BigInteger("-2"), -a remainder b)
}
test fun testBigDecimal() {
@test fun testBigDecimal() {
val a = BigDecimal("2")
val b = BigDecimal("3")
+2 -2
View File
@@ -5,12 +5,12 @@ import kotlin.test.*
class NaturalLanguageTest {
test fun `strings equal`() {
@test fun `strings equal`() {
val actual = "abc"
assertEquals("abc", actual)
}
test fun `numbers equal`() {
@test fun `numbers equal`() {
val actual = 5
assertEquals(5, actual)
}
+3 -3
View File
@@ -8,19 +8,19 @@ import java.io.*
import org.junit.Test as test
class OldStdlibTest() {
test fun testCollectionEmpty() {
@test fun testCollectionEmpty() {
assertNot {
listOf(0, 1, 2).isEmpty()
}
}
test fun testCollectionSize() {
@test fun testCollectionSize() {
assertTrue {
listOf(0, 1, 2).size() == 3
}
}
test fun testInputStreamIterator() {
@test fun testInputStreamIterator() {
val x = ByteArray (10)
for(index in 0..9) {
+22 -11
View File
@@ -14,27 +14,32 @@ class OrderingTest {
val v1 = Item("wine", 9)
val v2 = Item("beer", 10)
Test fun compareByCompareTo() {
@Test
fun compareByCompareTo() {
val diff = v1.compareTo(v2)
assertTrue(diff < 0)
}
Test fun compareByNameFirst() {
@Test
fun compareByNameFirst() {
val diff = compareValuesBy(v1, v2, { it.name }, { it.rating })
assertTrue(diff > 0)
}
Test fun compareByRatingFirst() {
@Test
fun compareByRatingFirst() {
val diff = compareValuesBy(v1, v2, { it.rating }, { it.name })
assertTrue(diff < 0)
}
Test fun compareSameObjectsByRatingFirst() {
@Test
fun compareSameObjectsByRatingFirst() {
val diff = compareValuesBy(v1, v1, { it.rating }, { it.name })
assertTrue(diff == 0)
}
Test fun compareNullables() {
@Test
fun compareNullables() {
val v1: Item? = this.v1
val v2: Item? = null
val diff = compareValuesBy(v1, v2) { it?.rating }
@@ -43,7 +48,8 @@ class OrderingTest {
assertTrue(diff2 < 0)
}
Test fun sortComparatorThenComparator() {
@Test
fun sortComparatorThenComparator() {
val comparator = comparator<Item> { a, b -> a.name.compareTo(b.name) } thenComparator { a, b -> a.rating.compareTo(b.rating) }
val diff = comparator.compare(v1, v2)
@@ -53,7 +59,8 @@ class OrderingTest {
assertEquals(v1, items[1])
}
Test fun combineComparators() {
@Test
fun combineComparators() {
val byName = compareBy<Item> { it.name }
val byRating = compareBy<Item> { it.rating }
val v3 = Item(v1.name, v1.rating + 1)
@@ -67,7 +74,8 @@ class OrderingTest {
assertTrue( (byRating thenDescending byName).compare(v4, v2) < 0 )
}
Test fun sortByThenBy() {
@Test
fun sortByThenBy() {
val comparator = compareBy<Item> { it.rating } thenBy { it.name }
val diff = comparator.compare(v1, v2)
@@ -77,7 +85,8 @@ class OrderingTest {
assertEquals(v2, items[1])
}
Test fun sortByThenByDescending() {
@Test
fun sortByThenByDescending() {
val comparator = compareBy<Item> { it.rating } thenByDescending { it.name }
val diff = comparator.compare(v1, v2)
@@ -87,7 +96,8 @@ class OrderingTest {
assertEquals(v2, items[1])
}
Test fun sortUsingFunctionalComparator() {
@Test
fun sortUsingFunctionalComparator() {
val comparator = compareBy<Item>({ it.name }, { it.rating })
val diff = comparator.compare(v1, v2)
assertTrue(diff > 0)
@@ -96,7 +106,8 @@ class OrderingTest {
assertEquals(v1, items[1])
}
Test fun sortUsingCustomComparator() {
@Test
fun sortUsingCustomComparator() {
val comparator = object : Comparator<Item> {
override fun compare(o1: Item, o2: Item): Int {
return compareValuesBy(o1, o2, { it.name }, { it.rating })
+21 -21
View File
@@ -5,7 +5,7 @@ import kotlin.test.*
class PreconditionsTest() {
test fun passingRequire() {
@test fun passingRequire() {
require(true)
var called = false
@@ -13,32 +13,32 @@ class PreconditionsTest() {
assertFalse(called)
}
test fun failingRequire() {
@test fun failingRequire() {
val error = assertFailsWith(IllegalArgumentException::class) {
require(false)
}
assertNotNull(error.getMessage())
}
test fun passingRequireWithMessage() {
@test fun passingRequireWithMessage() {
require(true, "Hello")
}
test fun failingRequireWithMessage() {
@test fun failingRequireWithMessage() {
val error = assertFailsWith(IllegalArgumentException::class) {
require(false, "Hello")
}
assertEquals("Hello", error.getMessage())
}
test fun failingRequireWithLazyMessage() {
@test fun failingRequireWithLazyMessage() {
val error = assertFailsWith(IllegalArgumentException::class) {
require(false) { "Hello" }
}
assertEquals("Hello", error.getMessage())
}
test fun passingCheck() {
@test fun passingCheck() {
check(true)
var called = false
@@ -46,45 +46,45 @@ class PreconditionsTest() {
assertFalse(called)
}
test fun failingCheck() {
@test fun failingCheck() {
val error = assertFailsWith(IllegalStateException::class) {
check(false)
}
assertNotNull(error.getMessage())
}
test fun passingCheckWithMessage() {
@test fun passingCheckWithMessage() {
check(true, "Hello")
}
test fun failingCheckWithMessage() {
@test fun failingCheckWithMessage() {
val error = assertFailsWith(IllegalStateException::class) {
check(false, "Hello")
}
assertEquals("Hello", error.getMessage())
}
test fun failingCheckWithLazyMessage() {
@test fun failingCheckWithLazyMessage() {
val error = assertFailsWith(IllegalStateException::class) {
check(false) { "Hello" }
}
assertEquals("Hello", error.getMessage())
}
test fun requireNotNull() {
@test fun requireNotNull() {
val s1: String? = "S1"
val r1: String = requireNotNull(s1)
assertEquals("S1", r1)
}
test fun requireNotNullFails() {
@test fun requireNotNullFails() {
assertFailsWith(IllegalArgumentException::class) {
val s2: String? = null
requireNotNull(s2)
}
}
test fun requireNotNullWithLazyMessage() {
@test fun requireNotNullWithLazyMessage() {
val error = assertFailsWith(IllegalArgumentException::class) {
val obj: Any? = null
requireNotNull(obj) { "Message" }
@@ -99,20 +99,20 @@ class PreconditionsTest() {
assertFalse(lazyCalled, "Message is not evaluated if the condition is met")
}
test fun checkNotNull() {
@test fun checkNotNull() {
val s1: String? = "S1"
val r1: String = checkNotNull(s1)
assertEquals("S1", r1)
}
test fun checkNotNullFails() {
@test fun checkNotNullFails() {
assertFailsWith(IllegalStateException::class) {
val s2: String? = null
checkNotNull(s2)
}
}
test fun passingAssert() {
@test fun passingAssert() {
assert(true)
var called = false
assert(true) { called = true; "some message" }
@@ -121,7 +121,7 @@ class PreconditionsTest() {
}
test fun failingAssert() {
@test fun failingAssert() {
val error = assertFails {
assert(false)
}
@@ -132,7 +132,7 @@ class PreconditionsTest() {
}
}
test fun error() {
@test fun error() {
val error = assertFails {
error("There was a problem")
}
@@ -143,11 +143,11 @@ class PreconditionsTest() {
}
}
test fun passingAssertWithMessage() {
@test fun passingAssertWithMessage() {
assert(true, "Hello")
}
test fun failingAssertWithMessage() {
@test fun failingAssertWithMessage() {
val error = assertFails {
assert(false, "Hello")
}
@@ -158,7 +158,7 @@ class PreconditionsTest() {
}
}
test fun failingAssertWithLazyMessage() {
@test fun failingAssertWithLazyMessage() {
val error = assertFails {
assert(false) { "Hello" }
}
+1 -1
View File
@@ -9,7 +9,7 @@ private fun listDifference<T>(first : List<T>, second : List<T>) : List<T> {
class StdLibIssuesTest {
test fun test_KT_1131() {
@test fun test_KT_1131() {
val data = arrayListOf("blah", "foo", "bar")
val filterValues = arrayListOf("bar", "something", "blah")
+14 -14
View File
@@ -8,22 +8,22 @@ import kotlin.test.assertNotEquals
class PairTest {
val p = Pair(1, "a")
test fun pairFirstAndSecond() {
@test fun pairFirstAndSecond() {
assertEquals(1, p.first)
assertEquals("a", p.second)
}
test fun pairMultiAssignment() {
@test fun pairMultiAssignment() {
val (a, b) = p
assertEquals(1, a)
assertEquals("a", b)
}
test fun pairToString() {
@test fun pairToString() {
assertEquals("(1, a)", p.toString())
}
test fun pairEquals() {
@test fun pairEquals() {
assertEquals(Pair(1, "a"), p)
assertNotEquals(Pair(2, "a"), p)
assertNotEquals(Pair(1, "b"), p)
@@ -31,7 +31,7 @@ class PairTest {
assertNotEquals("", (p : Any))
}
test fun pairHashCode() {
@test fun pairHashCode() {
assertEquals(Pair(1, "a").hashCode(), p.hashCode())
assertNotEquals(Pair(2, "a").hashCode(), p.hashCode())
assertNotEquals(0, Pair(null, "b").hashCode())
@@ -39,13 +39,13 @@ class PairTest {
assertEquals(0, Pair(null, null).hashCode())
}
test fun pairHashSet() {
@test fun pairHashSet() {
val s = hashSetOf(Pair(1, "a"), Pair(1, "b"), Pair(1, "a"))
assertEquals(2, s.size())
assertTrue(s.contains(p))
}
test fun pairToList() {
@test fun pairToList() {
assertEquals(listOf(1, 2), (1 to 2).toList())
assertEquals(listOf(1, null), (1 to null).toList())
assertEquals(listOf(1, "2"), (1 to "2").toList())
@@ -55,24 +55,24 @@ class PairTest {
class TripleTest {
val t = Triple(1, "a", 0.07)
test fun tripleFirstAndSecond() {
@test fun tripleFirstAndSecond() {
assertEquals(1, t.first)
assertEquals("a", t.second)
assertEquals(0.07, t.third)
}
test fun tripleMultiAssignment() {
@test fun tripleMultiAssignment() {
val (a, b, c) = t
assertEquals(1, a)
assertEquals("a", b)
assertEquals(0.07, c)
}
test fun tripleToString() {
@test fun tripleToString() {
assertEquals("(1, a, 0.07)", t.toString())
}
test fun tripleEquals() {
@test fun tripleEquals() {
assertEquals(Triple(1, "a", 0.07), t)
assertNotEquals(Triple(2, "a", 0.07), t)
assertNotEquals(Triple(1, "b", 0.07), t)
@@ -81,7 +81,7 @@ class TripleTest {
assertNotEquals("", (t : Any))
}
test fun tripleHashCode() {
@test fun tripleHashCode() {
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())
@@ -90,13 +90,13 @@ class TripleTest {
assertEquals(0, Triple(null, null, null).hashCode())
}
test fun tripleHashSet() {
@test fun tripleHashSet() {
val s = hashSetOf(Triple(1, "a", 0.07), Triple(1, "b", 0.07), Triple(1, "a", 0.07))
assertEquals(2, s.size())
assertTrue(s.contains(t))
}
test fun tripleToList() {
@test fun tripleToList() {
assertEquals(listOf(1, 2, 3), (Triple(1, 2, 3)).toList())
assertEquals(listOf(1, null, 3), (Triple(1, null, 3)).toList())
assertEquals(listOf(1, 2, "3"), (Triple(1, 2, "3")).toList())
+1 -1
View File
@@ -8,7 +8,7 @@ import org.junit.Test as test
class BrowserTest {
test fun accessBrowserDOM() {
@test fun accessBrowserDOM() {
registerBrowserPage()
val h1 = document["h1"].first()
@@ -5,7 +5,7 @@ import org.junit.Test as test
class ArraysJVMTest {
test fun orEmptyNull() {
@test fun orEmptyNull() {
val x: Array<String>? = null
val y: Array<out String>? = null
val xArray = x.orEmpty()
@@ -14,7 +14,7 @@ class ArraysJVMTest {
expect(0) { yArray.size() }
}
test fun orEmptyNotNull() {
@test fun orEmptyNotNull() {
val x: Array<String>? = arrayOf("1", "2")
val xArray = x.orEmpty()
expect(2) { xArray.size() }
+67 -67
View File
@@ -17,7 +17,7 @@ fun assertArrayNotSameButEquals(expected: BooleanArray, actual: BooleanArray, me
class ArraysTest {
test fun emptyArrayLastIndex() {
@test fun emptyArrayLastIndex() {
val arr1 = IntArray(0)
assertEquals(-1, arr1.lastIndex)
@@ -25,7 +25,7 @@ class ArraysTest {
assertEquals(-1, arr2.lastIndex)
}
test fun arrayLastIndex() {
@test fun arrayLastIndex() {
val arr1 = intArrayOf(0, 1, 2, 3, 4)
assertEquals(4, arr1.lastIndex)
assertEquals(4, arr1[arr1.lastIndex])
@@ -35,7 +35,7 @@ class ArraysTest {
assertEquals("4", arr2[arr2.lastIndex])
}
test fun byteArray() {
@test fun byteArray() {
val arr = ByteArray(2)
val expected: Byte = 0
@@ -44,7 +44,7 @@ class ArraysTest {
assertEquals(expected, arr[1])
}
test fun shortArray() {
@test fun shortArray() {
val arr = ShortArray(2)
val expected: Short = 0
@@ -53,7 +53,7 @@ class ArraysTest {
assertEquals(expected, arr[1])
}
test fun intArray() {
@test fun intArray() {
val arr = IntArray(2)
assertEquals(arr.size(), 2)
@@ -61,7 +61,7 @@ class ArraysTest {
assertEquals(0, arr[1])
}
test fun longArray() {
@test fun longArray() {
val arr = LongArray(2)
val expected: Long = 0
@@ -70,7 +70,7 @@ class ArraysTest {
assertEquals(expected, arr[1])
}
test fun floatArray() {
@test fun floatArray() {
val arr = FloatArray(2)
val expected: Float = 0.0F
@@ -79,7 +79,7 @@ class ArraysTest {
assertEquals(expected, arr[1])
}
test fun doubleArray() {
@test fun doubleArray() {
val arr = DoubleArray(2)
assertEquals(arr.size(), 2)
@@ -87,7 +87,7 @@ class ArraysTest {
assertEquals(0.0, arr[1])
}
test fun charArray() {
@test fun charArray() {
val arr = CharArray(2)
val expected: Char = '\u0000'
@@ -96,14 +96,14 @@ class ArraysTest {
assertEquals(expected, arr[1])
}
test fun booleanArray() {
@test fun booleanArray() {
val arr = BooleanArray(2)
assertEquals(arr.size(), 2)
assertEquals(false, arr[0])
assertEquals(false, arr[1])
}
test fun min() {
@test fun min() {
expect(null, { arrayOf<Int>().min() })
expect(1, { arrayOf(1).min() })
expect(2, { arrayOf(2, 3).min() })
@@ -112,7 +112,7 @@ class ArraysTest {
expect("a", { arrayOf("a", "b").min() })
}
test fun minInPrimitiveArrays() {
@test fun minInPrimitiveArrays() {
expect(null, { intArrayOf().min() })
expect(1, { intArrayOf(1).min() })
expect(2, { intArrayOf(2, 3).min() })
@@ -124,7 +124,7 @@ class ArraysTest {
expect('a', { charArrayOf('a', 'b').min() })
}
test fun max() {
@test fun max() {
expect(null, { arrayOf<Int>().max() })
expect(1, { arrayOf(1).max() })
expect(3, { arrayOf(2, 3).max() })
@@ -133,7 +133,7 @@ class ArraysTest {
expect("b", { arrayOf("a", "b").max() })
}
test fun maxInPrimitiveArrays() {
@test fun maxInPrimitiveArrays() {
expect(null, { intArrayOf().max() })
expect(1, { intArrayOf(1).max() })
expect(3, { intArrayOf(2, 3).max() })
@@ -145,7 +145,7 @@ class ArraysTest {
expect('b', { charArrayOf('a', 'b').max() })
}
test fun minBy() {
@test fun minBy() {
expect(null, { arrayOf<Int>().minBy { it } })
expect(1, { arrayOf(1).minBy { it } })
expect(3, { arrayOf(2, 3).minBy { -it } })
@@ -153,7 +153,7 @@ class ArraysTest {
expect("b", { arrayOf("b", "abc").minBy { it.length() } })
}
test fun minByInPrimitiveArrays() {
@test fun minByInPrimitiveArrays() {
expect(null, { intArrayOf().minBy { it } })
expect(1, { intArrayOf(1).minBy { it } })
expect(3, { intArrayOf(2, 3).minBy { -it } })
@@ -164,7 +164,7 @@ class ArraysTest {
expect(2.0, { doubleArrayOf(2.0, 3.0).minBy { Math.sqrt(it) } })
}
test fun maxBy() {
@test fun maxBy() {
expect(null, { arrayOf<Int>().maxBy { it } })
expect(1, { arrayOf(1).maxBy { it } })
expect(2, { arrayOf(2, 3).maxBy { -it } })
@@ -172,7 +172,7 @@ class ArraysTest {
expect("abc", { arrayOf("b", "abc").maxBy { it.length() } })
}
test fun maxByInPrimitiveArrays() {
@test fun maxByInPrimitiveArrays() {
expect(null, { intArrayOf().maxBy { it } })
expect(1, { intArrayOf(1).maxBy { it } })
expect(2, { intArrayOf(2, 3).maxBy { -it } })
@@ -183,29 +183,29 @@ class ArraysTest {
expect(3.0, { doubleArrayOf(2.0, 3.0).maxBy { Math.sqrt(it) } })
}
test fun minIndex() {
@test fun minIndex() {
val a = intArrayOf(1, 7, 9, -42, 54, 93)
expect(3, { a.indices.minBy { a[it] } })
}
test fun maxIndex() {
@test fun maxIndex() {
val a = intArrayOf(1, 7, 9, 239, 54, 93)
expect(3, { a.indices.maxBy { a[it] } })
}
test fun minByEvaluateOnce() {
@test fun minByEvaluateOnce() {
var c = 0
expect(1, { arrayOf(5, 4, 3, 2, 1).minBy { c++; it * it } })
assertEquals(5, c)
}
test fun maxByEvaluateOnce() {
@test fun maxByEvaluateOnce() {
var c = 0
expect(5, { arrayOf(5, 4, 3, 2, 1).maxBy { c++; it * it } })
assertEquals(5, c)
}
test fun sum() {
@test fun sum() {
expect(0) { arrayOf<Int>().sum() }
expect(14) { arrayOf(2, 3, 9).sum() }
expect(3.0) { arrayOf(1.0, 2.0).sum() }
@@ -215,7 +215,7 @@ class ArraysTest {
expect(3.0F) { arrayOf<Float>(1.0F, 2.0F).sum() }
}
test fun sumInPrimitiveArrays() {
@test fun sumInPrimitiveArrays() {
expect(0) { intArrayOf().sum() }
expect(14) { intArrayOf(2, 3, 9).sum() }
expect(3.0) { doubleArrayOf(1.0, 2.0).sum() }
@@ -225,7 +225,7 @@ class ArraysTest {
expect(3.0F) { floatArrayOf(1.0F, 2.0F).sum() }
}
test fun average() {
@test fun average() {
expect(0.0) { arrayOf<Int>().average() }
expect(3.8) { arrayOf(1, 2, 5, 8, 3).average() }
expect(2.1) { arrayOf(1.6, 2.6, 3.6, 0.6).average() }
@@ -236,7 +236,7 @@ class ArraysTest {
// for each arr with size > 0 arr.average() = arr.sum().toDouble() / arr.size()
}
test fun indexOfInPrimitiveArrays() {
@test fun indexOfInPrimitiveArrays() {
expect(-1) { byteArrayOf(1, 2, 3) indexOf 0 }
expect(0) { byteArrayOf(1, 2, 3) indexOf 1 }
expect(1) { byteArrayOf(1, 2, 3) indexOf 2 }
@@ -277,7 +277,7 @@ class ArraysTest {
expect(-1) { booleanArrayOf(true) indexOf false }
}
test fun indexOf() {
@test fun indexOf() {
expect(-1) { arrayOf("cat", "dog", "bird").indexOf("mouse") }
expect(0) { arrayOf("cat", "dog", "bird").indexOf("cat") }
expect(1) { arrayOf("cat", "dog", "bird").indexOf("dog") }
@@ -295,7 +295,7 @@ class ArraysTest {
expect(2) { sequenceOf("cat", "dog", "bird").indexOfFirst { it.endsWith('d') } }
}
test fun lastIndexOf() {
@test fun lastIndexOf() {
expect(-1) { arrayOf("cat", "dog", "bird").lastIndexOf("mouse") }
expect(0) { arrayOf("cat", "dog", "bird").lastIndexOf("cat") }
expect(1) { arrayOf("cat", "dog", "bird").lastIndexOf("dog") }
@@ -315,7 +315,7 @@ class ArraysTest {
expect(3) { sequenceOf("cat", "dog", "bird", "red").indexOfLast { it.endsWith('d') } }
}
test fun isEmpty() {
@test fun isEmpty() {
assertTrue(emptyArray<String>().isEmpty())
assertFalse(arrayOf("").isEmpty())
assertTrue(intArrayOf().isEmpty())
@@ -336,12 +336,12 @@ class ArraysTest {
assertFalse(booleanArrayOf(false).isEmpty())
}
test fun isNotEmpty() {
@test fun isNotEmpty() {
assertFalse(intArrayOf().isNotEmpty())
assertTrue(intArrayOf(1).isNotEmpty())
}
test fun plus() {
@test fun plus() {
assertEquals(listOf("1", "2", "3", "4"), listOf("1", "2") + arrayOf("3", "4"))
assertArrayNotSameButEquals(arrayOf("1", "2", "3"), arrayOf("1", "2") + "3")
assertArrayNotSameButEquals(arrayOf("1", "2", "3", "4"), arrayOf("1", "2") + arrayOf("3", "4"))
@@ -351,7 +351,7 @@ class ArraysTest {
assertArrayNotSameButEquals(intArrayOf(1, 2, 3, 4), intArrayOf(1, 2) + intArrayOf(3, 4))
}
test fun plusVararg() {
@test fun plusVararg() {
fun stringOnePlus(vararg a: String) = arrayOf("1") + a
fun longOnePlus(vararg a: Long) = longArrayOf(1) + a
fun intOnePlus(vararg a: Int) = intArrayOf(1) + a
@@ -361,7 +361,7 @@ class ArraysTest {
assertArrayNotSameButEquals(longArrayOf(1, 2), longOnePlus(2), "LongArray.plus")
}
test fun plusAssign() {
@test fun plusAssign() {
// lets use a mutable variable
var result = arrayOf("a")
result += "foo"
@@ -370,23 +370,23 @@ class ArraysTest {
assertArrayNotSameButEquals(arrayOf("a", "foo", "beer", "cheese", "wine"), result)
}
test fun first() {
@test fun first() {
expect(1) { arrayOf(1, 2, 3).first() }
expect(2) { arrayOf(1, 2, 3).first { it % 2 == 0 } }
}
test fun last() {
@test fun last() {
expect(3) { arrayOf(1, 2, 3).last() }
expect(2) { arrayOf(1, 2, 3).last { it % 2 == 0 } }
}
test fun contains() {
@test fun contains() {
assertTrue(arrayOf("1", "2", "3", "4").contains("2"))
assertTrue("3" in arrayOf("1", "2", "3", "4"))
assertTrue("0" !in arrayOf("1", "2", "3", "4"))
}
test fun slice() {
@test fun slice() {
val iter: Iterable<Int> = listOf(3, 1, 2)
assertEquals(listOf("B"), arrayOf("A", "B", "C").slice(1..1))
@@ -403,7 +403,7 @@ class ArraysTest {
assertEquals(listOf(true, false, true), booleanArrayOf(true, false, true, true).slice(iter))
}
test fun sliceArray() {
@test fun sliceArray() {
val coll: Collection<Int> = listOf(3, 1, 2)
assertArrayNotSameButEquals(arrayOf("B"), arrayOf("A", "B", "C").sliceArray(1..1))
@@ -420,7 +420,7 @@ class ArraysTest {
assertArrayNotSameButEquals(booleanArrayOf(true, false, true), booleanArrayOf(true, false, true, true).sliceArray(coll))
}
test fun asIterable() {
@test fun asIterable() {
val arr1 = intArrayOf(1, 2, 3, 4, 5)
val iter1 = arr1.asIterable()
assertEquals(arr1.toList(), iter1.toList())
@@ -442,7 +442,7 @@ class ArraysTest {
assertEquals(iter4.toList(), emptyList<String>())
}
test fun asList() {
@test fun asList() {
assertEquals(listOf(1, 2, 3), intArrayOf(1, 2, 3).asList())
assertEquals(listOf<Byte>(1, 2, 3), byteArrayOf(1, 2, 3).asList())
assertEquals(listOf(true, false), booleanArrayOf(true, false).asList())
@@ -457,7 +457,7 @@ class ArraysTest {
assertEquals(10, intsAsList[1], "Should reflect changes in original array")
}
test fun toPrimitiveArray() {
@test fun toPrimitiveArray() {
val genericArray: Array<Int> = arrayOf(1, 2, 3)
val primitiveArray: IntArray = genericArray.toIntArray()
expect(3) { primitiveArray.size() }
@@ -469,14 +469,14 @@ class ArraysTest {
assertEquals(charList, charArray.asList())
}
test fun toTypedArray() {
@test fun toTypedArray() {
val primitiveArray: LongArray = longArrayOf(1, 2, Long.MAX_VALUE)
val genericArray: Array<Long> = primitiveArray.toTypedArray()
expect(3) { genericArray.size() }
assertEquals(primitiveArray.asList(), genericArray.asList())
}
test fun copyOf() {
@test fun copyOf() {
booleanArrayOf(true, false, true).let { assertArrayNotSameButEquals(it, it.copyOf()) }
byteArrayOf(0, 1, 2, 3, 4, 5).let { assertArrayNotSameButEquals(it, it.copyOf()) }
shortArrayOf(0, 1, 2, 3, 4, 5).let { assertArrayNotSameButEquals(it, it.copyOf()) }
@@ -487,7 +487,7 @@ class ArraysTest {
charArrayOf('0', '1', '2', '3', '4', '5').let { assertArrayNotSameButEquals(it, it.copyOf()) }
}
test fun copyAndResize() {
@test fun copyAndResize() {
assertArrayNotSameButEquals(arrayOf("1", "2"), arrayOf("1", "2", "3").copyOf(2))
assertArrayNotSameButEquals(arrayOf("1", "2", null), arrayOf("1", "2").copyOf(3))
@@ -501,7 +501,7 @@ class ArraysTest {
assertArrayNotSameButEquals(charArrayOf('A', 'B', '\u0000'), charArrayOf('A', 'B').copyOf(3))
}
test fun copyOfRange() {
@test fun copyOfRange() {
assertArrayNotSameButEquals(booleanArrayOf(true, false, true), booleanArrayOf(true, false, true, true).copyOfRange(0, 3))
assertArrayNotSameButEquals(byteArrayOf(0, 1, 2), byteArrayOf(0, 1, 2, 3, 4, 5).copyOfRange(0, 3))
assertArrayNotSameButEquals(shortArrayOf(0, 1, 2), shortArrayOf(0, 1, 2, 3, 4, 5).copyOfRange(0, 3))
@@ -514,7 +514,7 @@ class ArraysTest {
test fun reduce() {
@test fun reduce() {
expect(-4) { intArrayOf(1, 2, 3) reduce { a, b -> a - b } }
expect(-4.toLong()) { longArrayOf(1, 2, 3) reduce { a, b -> a - b } }
expect(-4F) { floatArrayOf(1F, 2F, 3F) reduce { a, b -> a - b } }
@@ -530,7 +530,7 @@ class ArraysTest {
} is UnsupportedOperationException)
}
test fun reduceRight() {
@test fun reduceRight() {
expect(2) { intArrayOf(1, 2, 3) reduceRight { a, b -> a - b } }
expect(2.toLong()) { longArrayOf(1, 2, 3) reduceRight { a, b -> a - b } }
expect(2F) { floatArrayOf(1F, 2F, 3F) reduceRight { a, b -> a - b } }
@@ -546,7 +546,7 @@ class ArraysTest {
} is UnsupportedOperationException)
}
test fun reversed() {
@test fun reversed() {
expect(listOf(3, 2, 1)) { intArrayOf(1, 2, 3).reversed() }
expect(listOf<Byte>(3, 2, 1)) { byteArrayOf(1, 2, 3).reversed() }
expect(listOf<Short>(3, 2, 1)) { shortArrayOf(1, 2, 3).reversed() }
@@ -557,7 +557,7 @@ class ArraysTest {
expect(listOf(false, false, true)) { booleanArrayOf(true, false, false).reversed() }
}
test fun reversedArray() {
@test fun reversedArray() {
assertArrayNotSameButEquals(intArrayOf(3, 2, 1), intArrayOf(1, 2, 3).reversedArray())
assertArrayNotSameButEquals(byteArrayOf(3, 2, 1), byteArrayOf(1, 2, 3).reversedArray())
assertArrayNotSameButEquals(shortArrayOf(3, 2, 1), shortArrayOf(1, 2, 3).reversedArray())
@@ -568,7 +568,7 @@ class ArraysTest {
assertArrayNotSameButEquals(booleanArrayOf(false, false, true), booleanArrayOf(true, false, false).reversedArray())
}
test fun drop() {
@test fun drop() {
expect(listOf(1), { intArrayOf(1).drop(0) })
expect(listOf(), { intArrayOf().drop(1) })
expect(listOf(), { intArrayOf(1).drop(1) })
@@ -586,7 +586,7 @@ class ArraysTest {
}
}
test fun dropLast() {
@test fun dropLast() {
expect(listOf(), { intArrayOf().dropLast(1) })
expect(listOf(), { intArrayOf(1).dropLast(1) })
expect(listOf(1), { intArrayOf(1).dropLast(0) })
@@ -604,7 +604,7 @@ class ArraysTest {
}
}
test fun dropWhile() {
@test fun dropWhile() {
expect(listOf(), { intArrayOf().dropWhile { it < 3 } })
expect(listOf(), { intArrayOf(1).dropWhile { it < 3 } })
expect(listOf(3, 1), { intArrayOf(2, 3, 1).dropWhile { it < 3 } })
@@ -618,7 +618,7 @@ class ArraysTest {
expect(listOf("b", "a"), { arrayOf("a", "b", "a").dropWhile { it < "b" } })
}
test fun dropLastWhile() {
@test fun dropLastWhile() {
expect(listOf(), { intArrayOf().dropLastWhile { it < 3 } })
expect(listOf(), { intArrayOf(1).dropLastWhile { it < 3 } })
expect(listOf(2, 3), { intArrayOf(2, 3, 1).dropLastWhile { it < 3 } })
@@ -632,7 +632,7 @@ class ArraysTest {
expect(listOf("a", "b"), { arrayOf("a", "b", "a").dropLastWhile { it < "b" } })
}
test fun take() {
@test fun take() {
expect(listOf(), { intArrayOf().take(1) })
expect(listOf(), { intArrayOf(1).take(0) })
expect(listOf(1), { intArrayOf(1).take(1) })
@@ -650,7 +650,7 @@ class ArraysTest {
}
}
test fun takeLast() {
@test fun takeLast() {
expect(listOf(), { intArrayOf().takeLast(1) })
expect(listOf(), { intArrayOf(1).takeLast(0) })
expect(listOf(1), { intArrayOf(1).takeLast(1) })
@@ -668,7 +668,7 @@ class ArraysTest {
}
}
test fun takeWhile() {
@test fun takeWhile() {
expect(listOf(), { intArrayOf().takeWhile { it < 3 } })
expect(listOf(1), { intArrayOf(1).takeWhile { it < 3 } })
expect(listOf(2), { intArrayOf(2, 3, 1).takeWhile { it < 3 } })
@@ -682,7 +682,7 @@ class ArraysTest {
expect(listOf("a"), { arrayOf("a", "c", "b").takeWhile { it < "c" } })
}
test fun takeLastWhile() {
@test fun takeLastWhile() {
expect(listOf(), { intArrayOf().takeLastWhile { it < 3 } })
expect(listOf(1), { intArrayOf(1).takeLastWhile { it < 3 } })
expect(listOf(1), { intArrayOf(2, 3, 1).takeLastWhile { it < 3 } })
@@ -696,7 +696,7 @@ class ArraysTest {
expect(listOf("b"), { arrayOf("a", "c", "b").takeLastWhile { it < "c" } })
}
test fun filter() {
@test fun filter() {
expect(listOf(), { intArrayOf().filter { it > 2 } })
expect(listOf(), { intArrayOf(1).filter { it > 2 } })
expect(listOf(3), { intArrayOf(2, 3).filter { it > 2 } })
@@ -710,7 +710,7 @@ class ArraysTest {
expect(listOf("b"), { arrayOf("a", "b").filter { it > "a" } })
}
test fun filterNot() {
@test fun filterNot() {
expect(listOf(), { intArrayOf().filterNot { it > 2 } })
expect(listOf(1), { intArrayOf(1).filterNot { it > 2 } })
expect(listOf(2), { intArrayOf(2, 3).filterNot { it > 2 } })
@@ -724,11 +724,11 @@ class ArraysTest {
expect(listOf("a"), { arrayOf("a", "b").filterNot { it > "a" } })
}
test fun filterNotNull() {
@test fun filterNotNull() {
expect(listOf("a"), { arrayOf("a", null).filterNotNull() })
}
test fun asListPrimitives() {
@test fun asListPrimitives() {
// Array of primitives
val arr = intArrayOf(1, 2, 3, 4, 2, 5)
val list = arr.asList()
@@ -760,7 +760,7 @@ class ArraysTest {
assertEquals(IntArray(0).asList(), emptyList<Int>())
}
test fun asListObjects() {
@test fun asListObjects() {
val arr = arrayOf("a", "b", "c", "d", "b", "e")
val list = arr.asList()
@@ -793,7 +793,7 @@ class ArraysTest {
assertEquals(Array(0, { "" }).asList(), emptyList<String>())
}
test fun sort() {
@test fun sort() {
val intArr = intArrayOf(5, 2, 1, 9, 80, Int.MIN_VALUE, Int.MAX_VALUE)
intArr.sort()
assertArrayNotSameButEquals(intArrayOf(Int.MIN_VALUE, 1, 2, 5, 9, 80, Int.MAX_VALUE), intArr)
@@ -811,7 +811,7 @@ class ArraysTest {
assertArrayNotSameButEquals(arrayOf("80", "9", "Foo", "all"), strArr)
}
test fun sorted() {
@test fun sorted() {
assertTrue(arrayOf<Long>().sorted().none())
assertEquals(listOf(1), arrayOf(1).sorted())
@@ -849,14 +849,14 @@ class ArraysTest {
}
}
test fun sortedBy() {
@test fun sortedBy() {
val values = arrayOf("ac", "aD", "aba")
val indices = values.indices.toList().toIntArray()
assertEquals(listOf(1, 2, 0), indices.sortedBy { values[it] })
}
test fun sortedNullableBy() {
@test fun sortedNullableBy() {
fun String.nullIfEmpty() = if (isEmpty()) null else this
arrayOf(null, "").let {
expect(listOf(null, "")) { it.sortedWith(nullsFirst(compareBy { it })) }
@@ -865,7 +865,7 @@ class ArraysTest {
}
}
test fun sortedWith() {
@test fun sortedWith() {
val comparator = compareBy { it: Int -> it % 3 }.thenByDescending { it }
fun arrayData<A, T>(array: A, comparator: Comparator<T>) = ArraySortedChecker<A, T>(array, comparator)
@@ -20,7 +20,7 @@ class CollectionJVMTest {
private data class IdentityData(public val value: Int)
test fun removeAllWithDifferentEquality() {
@test fun removeAllWithDifferentEquality() {
val data = listOf(IdentityData(1), IdentityData(1))
val list = data.toArrayList()
list -= identitySetOf(data[0]) as Iterable<IdentityData>
@@ -35,7 +35,7 @@ class CollectionJVMTest {
assertTrue(set3.isEmpty(), "Array doesn't have contains, equality contains is used instead")
}
test fun flatMap() {
@test fun flatMap() {
val data = listOf("", "foo", "bar", "x", "")
val characters = data.flatMap { it.toCharList() }
println("Got list of characters ${characters}")
@@ -45,7 +45,7 @@ class CollectionJVMTest {
}
test fun filterIntoLinkedList() {
@test fun filterIntoLinkedList() {
val data = listOf("foo", "bar")
val foo = data.filterTo(linkedListOf<String>()) { it.startsWith("f") }
@@ -60,7 +60,7 @@ class CollectionJVMTest {
}
}
test fun filterNotIntoLinkedListOf() {
@test fun filterNotIntoLinkedListOf() {
val data = listOf("foo", "bar")
val foo = data.filterNotTo(linkedListOf<String>()) { it.startsWith("f") }
@@ -75,7 +75,7 @@ class CollectionJVMTest {
}
}
test fun filterNotNullIntoLinkedListOf() {
@test fun filterNotNullIntoLinkedListOf() {
val data = listOf(null, "foo", null, "bar")
val foo = data.filterNotNullTo(linkedListOf<String>())
@@ -87,7 +87,7 @@ class CollectionJVMTest {
}
}
test fun filterIntoSortedSet() {
@test fun filterIntoSortedSet() {
val data = listOf("foo", "bar")
val sorted = data.filterTo(sortedSetOf<String>()) { it.length() == 3 }
assertEquals(2, sorted.size())
@@ -97,26 +97,26 @@ class CollectionJVMTest {
}
}
test fun first() {
@test fun first() {
assertEquals(19, TreeSet(listOf(90, 47, 19)).first())
}
test fun last() {
@test fun last() {
val data = listOf("foo", "bar")
assertEquals("bar", data.last())
assertEquals(25, listOf(15, 19, 20, 25).last())
assertEquals('a', linkedListOf('a').last())
}
test fun lastException() {
@test fun lastException() {
fails { linkedListOf<String>().last() }
}
test fun contains() {
@test fun contains() {
assertTrue(linkedListOf(15, 19, 20).contains(15))
}
test fun toArray() {
@test fun toArray() {
val data = listOf("foo", "bar")
val arr = data.toTypedArray()
println("Got array ${arr}")
@@ -128,11 +128,11 @@ class CollectionJVMTest {
}
}
test fun takeReturnsFirstNElements() {
@test fun takeReturnsFirstNElements() {
expect(setOf(1, 2)) { sortedSetOf(1, 2, 3, 4, 5).take(2).toSet() }
}
test fun filterIsInstanceList() {
@test fun filterIsInstanceList() {
val values: List<Any> = listOf(1, 2, 3.toDouble(), "abc", "cde")
val intValues: List<Int> = values.filterIsInstance<Int>()
@@ -151,7 +151,7 @@ class CollectionJVMTest {
assertEquals(0, charValues.size())
}
test fun filterIsInstanceArray() {
@test fun filterIsInstanceArray() {
val src: Array<Any> = arrayOf(1, 2, 3.toDouble(), "abc", "cde")
val intValues: List<Int> = src.filterIsInstance<Int>()
@@ -170,11 +170,11 @@ class CollectionJVMTest {
assertEquals(0, charValues.size())
}
test fun emptyListIsSerializable() = testSingletonSerialization(emptyList<Any>())
@test fun emptyListIsSerializable() = testSingletonSerialization(emptyList<Any>())
test fun emptySetIsSerializable() = testSingletonSerialization(emptySet<Any>())
@test fun emptySetIsSerializable() = testSingletonSerialization(emptySet<Any>())
test fun emptyMapIsSerializable() = testSingletonSerialization(emptyMap<Any, Any>())
@test fun emptyMapIsSerializable() = testSingletonSerialization(emptyMap<Any, Any>())
private fun testSingletonSerialization(value: Any) {
val result = serializeAndDeserialize(value)
@@ -7,14 +7,14 @@ import test.collections.behaviors.*
class CollectionTest {
test fun joinTo() {
@test fun joinTo() {
val data = listOf("foo", "bar")
val buffer = StringBuilder()
data.joinTo(buffer, "-", "{", "}")
assertEquals("{foo-bar}", buffer.toString())
}
test fun join() {
@test fun join() {
val data = listOf("foo", "bar")
val text = data.join("-", "<", ">")
assertEquals("<foo-bar>", text)
@@ -24,7 +24,7 @@ class CollectionTest {
assertEquals("a, b, c, *", text2)
}
test fun filterNotNull() {
@test fun filterNotNull() {
val data = listOf(null, "foo", null, "bar")
val foo = data.filterNotNull()
@@ -36,7 +36,7 @@ class CollectionTest {
}
}
test fun mapNotNull() {
@test fun mapNotNull() {
val data = listOf(null, "foo", null, "bar")
val foo = data.mapNotNull { it.length() }
assertEquals(2, foo.size())
@@ -47,7 +47,7 @@ class CollectionTest {
}
}
test fun listOfNotNull() {
@test fun listOfNotNull() {
val l1: List<Int> = listOfNotNull(null)
assertTrue(l1.isEmpty())
@@ -59,7 +59,7 @@ class CollectionTest {
assertEquals(listOf("value1", "value2"), l3)
}
test fun filterIntoSet() {
@test fun filterIntoSet() {
val data = listOf("foo", "bar")
val foo = data.filterTo(hashSetOf<String>()) { it.startsWith("f") }
@@ -74,7 +74,7 @@ class CollectionTest {
}
}
test fun fold() {
@test fun fold() {
// lets calculate the sum of some numbers
expect(10) {
val numbers = listOf(1, 2, 3, 4)
@@ -93,7 +93,7 @@ class CollectionTest {
}
}
test fun foldWithDifferentTypes() {
@test fun foldWithDifferentTypes() {
expect(7) {
val numbers = listOf("a", "ab", "abc")
numbers.fold(1) { a, b -> a + b.length() }
@@ -105,49 +105,49 @@ class CollectionTest {
}
}
test fun foldWithNonCommutativeOperation() {
@test fun foldWithNonCommutativeOperation() {
expect(1) {
val numbers = listOf(1, 2, 3)
numbers.fold(7) { a, b -> a - b }
}
}
test fun foldRight() {
@test fun foldRight() {
expect("1234") {
val numbers = listOf(1, 2, 3, 4)
numbers.map { it.toString() }.foldRight("") { a, b -> a + b }
}
}
test fun foldRightWithDifferentTypes() {
@test fun foldRightWithDifferentTypes() {
expect("1234") {
val numbers = listOf(1, 2, 3, 4)
numbers.foldRight("") { a, b -> "" + a + b }
}
}
test fun foldRightWithNonCommutativeOperation() {
@test fun foldRightWithNonCommutativeOperation() {
expect(-5) {
val numbers = listOf(1, 2, 3)
numbers.foldRight(7) { a, b -> a - b }
}
}
test
@test
fun merge() {
expect(listOf("ab", "bc", "cd")) {
listOf("a", "b", "c").merge(listOf("b", "c", "d")) { a, b -> a + b }
}
}
test
@test
fun zip() {
expect(listOf("a" to "b", "b" to "c", "c" to "d")) {
listOf("a", "b", "c").zip(listOf("b", "c", "d"))
}
}
test fun partition() {
@test fun partition() {
val data = listOf("foo", "bar", "something", "xyz")
val pair = data.partition { it.length() == 3 }
@@ -155,7 +155,7 @@ class CollectionTest {
assertEquals(listOf("something"), pair.second, "pair.second")
}
test fun reduce() {
@test fun reduce() {
expect("1234") {
val list = listOf("1", "2", "3", "4")
list.reduce { a, b -> a + b }
@@ -168,7 +168,7 @@ class CollectionTest {
}
}
test fun reduceRight() {
@test fun reduceRight() {
expect("1234") {
val list = listOf("1", "2", "3", "4")
list.reduceRight { a, b -> a + b }
@@ -181,7 +181,7 @@ class CollectionTest {
}
}
test fun groupBy() {
@test fun groupBy() {
val words = listOf("a", "abc", "ab", "def", "abcd")
val byLength = words.groupBy { it.length() }
assertEquals(4, byLength.size())
@@ -197,14 +197,14 @@ class CollectionTest {
assertEquals(2, l3.size())
}
test fun plusRanges() {
@test fun plusRanges() {
val range1 = 1..3
val range2 = 4..7
val combined = range1 + range2
assertEquals((1..7).toList(), combined)
}
test fun mapRanges() {
@test fun mapRanges() {
val range = 1..3 map { it * 2 }
assertEquals(listOf(2, 4, 6), range)
}
@@ -216,18 +216,18 @@ class CollectionTest {
assertEquals(listOf("foo", "bar", "cheese", "wine"), list2)
}
test fun plusElement() = testPlus { it + "cheese" + "wine" }
test fun plusCollection() = testPlus { it + listOf("cheese", "wine") }
test fun plusArray() = testPlus { it + arrayOf("cheese", "wine") }
test fun plusSequence() = testPlus { it + sequenceOf("cheese", "wine") }
@test fun plusElement() = testPlus { it + "cheese" + "wine" }
@test fun plusCollection() = testPlus { it + listOf("cheese", "wine") }
@test fun plusArray() = testPlus { it + arrayOf("cheese", "wine") }
@test fun plusSequence() = testPlus { it + sequenceOf("cheese", "wine") }
test fun plusCollectionBug() {
@test fun plusCollectionBug() {
val list = listOf("foo", "bar") + listOf("cheese", "wine")
assertEquals(listOf("foo", "bar", "cheese", "wine"), list)
}
test fun plusAssign() {
@test fun plusAssign() {
// lets use a mutable variable of readonly list
var l: List<String> = listOf("cheese")
val lOriginal = l
@@ -254,12 +254,12 @@ class CollectionTest {
assertEquals(expected_, b.toList())
}
test fun minusElement() = testMinus(expected = listOf("foo", "bar")) { it - "bar" - "zoo" }
test fun minusCollection() = testMinus { it - listOf("bar", "zoo") }
test fun minusArray() = testMinus { it - arrayOf("bar", "zoo") }
test fun minusSequence() = testMinus { it - sequenceOf("bar", "zoo") }
@test fun minusElement() = testMinus(expected = listOf("foo", "bar")) { it - "bar" - "zoo" }
@test fun minusCollection() = testMinus { it - listOf("bar", "zoo") }
@test fun minusArray() = testMinus { it - arrayOf("bar", "zoo") }
@test fun minusSequence() = testMinus { it - sequenceOf("bar", "zoo") }
test fun minusIsEager() {
@test fun minusIsEager() {
val source = listOf("foo", "bar")
val list = arrayListOf<String>()
val result = source - list
@@ -270,7 +270,7 @@ class CollectionTest {
assertEquals(source, result)
}
test fun minusAssign() {
@test fun minusAssign() {
// lets use a mutable variable of readonly list
val data: List<String> = listOf("cheese", "foo", "beer", "cheese", "wine")
var l = data
@@ -293,7 +293,7 @@ class CollectionTest {
test fun requireNoNulls() {
@test fun requireNoNulls() {
val data = arrayListOf<String?>("foo", "bar")
val notNull = data.requireNoNulls()
assertEquals(listOf("foo", "bar"), notNull)
@@ -308,37 +308,37 @@ class CollectionTest {
}
}
test fun reverse() {
@test fun reverse() {
val data = listOf("foo", "bar")
val rev = data.reversed()
assertEquals(listOf("bar", "foo"), rev)
}
test fun reverseFunctionShouldReturnReversedCopyForList() {
@test fun reverseFunctionShouldReturnReversedCopyForList() {
val list: List<Int> = listOf(2, 3, 1)
expect(listOf(1, 3, 2)) { list.reversed() }
expect(listOf(2, 3, 1)) { list }
}
test fun reverseFunctionShouldReturnReversedCopyForIterable() {
@test fun reverseFunctionShouldReturnReversedCopyForIterable() {
val iterable: Iterable<Int> = listOf(2, 3, 1)
expect(listOf(1, 3, 2)) { iterable.reversed() }
expect(listOf(2, 3, 1)) { iterable }
}
test fun drop() {
@test fun drop() {
val coll = listOf("foo", "bar", "abc")
assertEquals(listOf("bar", "abc"), coll.drop(1))
assertEquals(listOf("abc"), coll.drop(2))
}
test fun dropWhile() {
@test fun dropWhile() {
val coll = listOf("foo", "bar", "abc")
assertEquals(listOf("bar", "abc"), coll.dropWhile { it.startsWith("f") })
}
test fun dropLast() {
@test fun dropLast() {
val coll = listOf("foo", "bar", "abc")
assertEquals(coll, coll.dropLast(0))
assertEquals(emptyList<String>(), coll.dropLast(coll.size()))
@@ -349,7 +349,7 @@ class CollectionTest {
fails { coll.dropLast(-1) }
}
test fun dropLastWhile() {
@test fun dropLastWhile() {
val coll = listOf("Foo", "bare", "abc" )
assertEquals(coll, coll.dropLastWhile { false })
assertEquals(listOf<String>(), coll.dropLastWhile { true })
@@ -357,7 +357,7 @@ class CollectionTest {
assertEquals(listOf("Foo"), coll.dropLastWhile { it.all { it in 'a'..'z' } })
}
test fun take() {
@test fun take() {
val coll = listOf("foo", "bar", "abc")
assertEquals(emptyList<String>(), coll.take(0))
assertEquals(listOf("foo"), coll.take(1))
@@ -368,7 +368,7 @@ class CollectionTest {
fails { coll.take(-1) }
}
test fun takeWhile() {
@test fun takeWhile() {
val coll = listOf("foo", "bar", "abc")
assertEquals(emptyList<String>(), coll.takeWhile { false })
assertEquals(coll, coll.takeWhile { true })
@@ -376,7 +376,7 @@ class CollectionTest {
assertEquals(listOf("foo", "bar", "abc"), coll.takeWhile { it.length() == 3 })
}
test fun takeLast() {
@test fun takeLast() {
val coll = listOf("foo", "bar", "abc")
assertEquals(emptyList<String>(), coll.takeLast(0))
@@ -388,7 +388,7 @@ class CollectionTest {
fails { coll.takeLast(-1) }
}
test fun takeLastWhile() {
@test fun takeLastWhile() {
val coll = listOf("foo", "bar", "abc")
assertEquals(emptyList<String>(), coll.takeLastWhile { false })
assertEquals(coll, coll.takeLastWhile { true })
@@ -396,7 +396,7 @@ class CollectionTest {
assertEquals(listOf("bar", "abc"), coll.takeLastWhile { it[0] < 'c' })
}
test fun copyToArray() {
@test fun copyToArray() {
val data = listOf("foo", "bar")
val arr = data.toTypedArray()
println("Got array ${arr}")
@@ -408,14 +408,14 @@ class CollectionTest {
}
}
test fun count() {
@test fun count() {
val data = listOf("foo", "bar")
assertEquals(2, data.count())
assertEquals(3, hashSetOf(12, 14, 15).count())
assertEquals(0, ArrayList<Double>().count())
}
test fun first() {
@test fun first() {
val data = listOf("foo", "bar")
assertEquals("foo", data.first())
assertEquals(15, listOf(15, 19, 20, 25).first())
@@ -423,7 +423,7 @@ class CollectionTest {
fails { arrayListOf<Int>().first() }
}
test fun last() {
@test fun last() {
val data = listOf("foo", "bar")
assertEquals("bar", data.last())
assertEquals(25, listOf(15, 19, 20, 25).last())
@@ -431,7 +431,7 @@ class CollectionTest {
fails { arrayListOf<Int>().last() }
}
test fun subscript() {
@test fun subscript() {
val list = arrayListOf("foo", "bar")
assertEquals("foo", list[0])
assertEquals("bar", list[1])
@@ -454,7 +454,7 @@ class CollectionTest {
assertEquals(listOf("new", "thing", "works"), list)
}
test fun indices() {
@test fun indices() {
val data = listOf("foo", "bar")
val indices = data.indices
assertEquals(0, indices.start)
@@ -462,14 +462,14 @@ class CollectionTest {
assertEquals(0..data.size() - 1, indices)
}
test fun contains() {
@test fun contains() {
assertFalse(hashSetOf<Int>().contains(12))
assertTrue(listOf(15, 19, 20).contains(15))
assertTrue(IterableWrapper(hashSetOf(45, 14, 13)).contains(14))
}
test fun min() {
@test fun min() {
expect(null, { listOf<Int>().min() })
expect(1, { listOf(1).min() })
expect(2, { listOf(2, 3).min() })
@@ -480,7 +480,7 @@ class CollectionTest {
expect(2, { listOf(2, 3).asSequence().min() })
}
test fun max() {
@test fun max() {
expect(null, { listOf<Int>().max() })
expect(1, { listOf(1).max() })
expect(3, { listOf(2, 3).max() })
@@ -491,7 +491,7 @@ class CollectionTest {
expect(3, { listOf(2, 3).asSequence().max() })
}
test fun minBy() {
@test fun minBy() {
expect(null, { listOf<Int>().minBy { it } })
expect(1, { listOf(1).minBy { it } })
expect(3, { listOf(2, 3).minBy { -it } })
@@ -501,7 +501,7 @@ class CollectionTest {
expect(3, { listOf(2, 3).asSequence().minBy { -it } })
}
test fun maxBy() {
@test fun maxBy() {
expect(null, { listOf<Int>().maxBy { it } })
expect(1, { listOf(1).maxBy { it } })
expect(2, { listOf(2, 3).maxBy { -it } })
@@ -511,7 +511,7 @@ class CollectionTest {
expect(2, { listOf(2, 3).asSequence().maxBy { -it } })
}
test fun minByEvaluateOnce() {
@test fun minByEvaluateOnce() {
var c = 0
expect(1, { listOf(5, 4, 3, 2, 1).minBy { c++; it * it } })
assertEquals(5, c)
@@ -520,7 +520,7 @@ class CollectionTest {
assertEquals(5, c)
}
test fun maxByEvaluateOnce() {
@test fun maxByEvaluateOnce() {
var c = 0
expect(5, { listOf(5, 4, 3, 2, 1).maxBy { c++; it * it } })
assertEquals(5, c)
@@ -529,7 +529,7 @@ class CollectionTest {
assertEquals(5, c)
}
test fun sum() {
@test fun sum() {
expect(0) { arrayListOf<Int>().sum() }
expect(14) { listOf(2, 3, 9).sum() }
expect(3.0) { listOf(1.0, 2.0).sum() }
@@ -538,7 +538,7 @@ class CollectionTest {
expect(3.0.toFloat()) { sequenceOf<Float>(1.0.toFloat(), 2.0.toFloat()).sum() }
}
test fun average() {
@test fun average() {
expect(0.0) { arrayListOf<Int>().average() }
expect(3.8) { listOf(1, 2, 5, 8, 3).average() }
expect(2.1) { sequenceOf(1.6, 2.6, 3.6, 0.6).average() }
@@ -548,7 +548,7 @@ class CollectionTest {
expect(n.toDouble()/2) { range.average() }
}
test fun takeReturnsFirstNElements() {
@test fun takeReturnsFirstNElements() {
expect(listOf(1, 2, 3, 4, 5)) { (1..10) take 5 }
expect(listOf(1, 2, 3, 4, 5)) { (1..10).toList().take(5) }
expect(listOf(1, 2)) { (1..10) take 2 }
@@ -559,18 +559,18 @@ class CollectionTest {
expect(listOf(1)) { listOf(1) take 10 }
}
test fun sorted() {
@test fun sorted() {
assertEquals(listOf(1, 3, 7), listOf(3, 7, 1).sorted())
assertEquals(listOf(7, 3, 1), listOf(3, 7, 1).sortedDescending())
}
test fun sortedBy() {
@test fun sortedBy() {
assertEquals(listOf("two" to 2, "three" to 3), listOf("three" to 3, "two" to 2).sortedBy { it.second })
assertEquals(listOf("three" to 3, "two" to 2), listOf("three" to 3, "two" to 2).sortedBy { it.first })
assertEquals(listOf("three", "two"), listOf("two", "three").sortedByDescending { it.length() })
}
test fun sortedNullableBy() {
@test fun sortedNullableBy() {
fun String.nullIfEmpty() = if (isEmpty()) null else this
listOf(null, "", "a").let {
expect(listOf(null, "", "a")) { it.sortedWith(nullsFirst(compareBy { it })) }
@@ -579,7 +579,7 @@ class CollectionTest {
}
}
test fun sortedByNullable() {
@test fun sortedByNullable() {
fun String.nonEmptyLength() = if (isEmpty()) null else length()
listOf("", "sort", "abc").let {
assertEquals(listOf("", "abc", "sort"), it.sortedBy { it.nonEmptyLength() })
@@ -588,7 +588,7 @@ class CollectionTest {
}
}
test fun sortedWith() {
@test fun sortedWith() {
val comparator = compareBy<String> { it.toUpperCase().reversed() }
val data = listOf("cat", "dad", "BAD")
@@ -597,18 +597,18 @@ class CollectionTest {
expect(listOf("BAD", "dad", "cat")) { data.sortedWith(comparator.reversed().reversed()) }
}
test fun decomposeFirst() {
@test fun decomposeFirst() {
val (first) = listOf(1, 2)
assertEquals(first, 1)
}
test fun decomposeSplit() {
@test fun decomposeSplit() {
val (key, value) = "key = value".split("=").map { it.trim() }
assertEquals(key, "key")
assertEquals(value, "value")
}
test fun decomposeList() {
@test fun decomposeList() {
val (a, b, c, d, e) = listOf(1, 2, 3, 4, 5)
assertEquals(a, 1)
assertEquals(b, 2)
@@ -617,7 +617,7 @@ class CollectionTest {
assertEquals(e, 5)
}
test fun decomposeArray() {
@test fun decomposeArray() {
val (a, b, c, d, e) = arrayOf(1, 2, 3, 4, 5)
assertEquals(a, 1)
assertEquals(b, 2)
@@ -626,7 +626,7 @@ class CollectionTest {
assertEquals(e, 5)
}
test fun decomposeIntArray() {
@test fun decomposeIntArray() {
val (a, b, c, d, e) = intArrayOf(1, 2, 3, 4, 5)
assertEquals(a, 1)
assertEquals(b, 2)
@@ -635,39 +635,39 @@ class CollectionTest {
assertEquals(e, 5)
}
test fun unzipList() {
@test fun unzipList() {
val list = listOf(1 to 'a', 2 to 'b', 3 to 'c')
val (ints, chars) = list.unzip()
assertEquals(listOf(1, 2, 3), ints)
assertEquals(listOf('a', 'b', 'c'), chars)
}
test fun unzipArray() {
@test fun unzipArray() {
val array = arrayOf(1 to 'a', 2 to 'b', 3 to 'c')
val (ints, chars) = array.unzip()
assertEquals(listOf(1, 2, 3), ints)
assertEquals(listOf('a', 'b', 'c'), chars)
}
test fun specialLists() {
@test fun specialLists() {
compare(arrayListOf<Int>(), listOf<Int>()) { listBehavior() }
compare(arrayListOf<Double>(), emptyList<Double>()) { listBehavior() }
compare(arrayListOf("value"), listOf("value")) { listBehavior() }
}
test fun specialSets() {
@test fun specialSets() {
compare(linkedSetOf<Int>(), setOf<Int>()) { setBehavior() }
compare(hashSetOf<Double>(), emptySet<Double>()) { setBehavior() }
compare(listOf("value").toMutableSet(), setOf("value")) { setBehavior() }
}
test fun specialMaps() {
@test fun specialMaps() {
compare(hashMapOf<String, Int>(), mapOf<String, Int>()) { mapBehavior() }
compare(linkedMapOf<Int, String>(), emptyMap<Int, String>()) { mapBehavior() }
compare(linkedMapOf(2 to 3), mapOf(2 to 3)) { mapBehavior() }
}
test fun toStringTest() {
@test fun toStringTest() {
// we need toString() inside pattern because of KT-8666
assertEquals("[1, a, null, ${Long.MAX_VALUE.toString()}]", listOf(1, "a", null, Long.MAX_VALUE).toString())
}
@@ -22,33 +22,38 @@ class ListTest : OrderedIterableTests<List<String>>(listOf("foo", "bar"), listOf
class ArrayListTest : OrderedIterableTests<ArrayList<String>>(arrayListOf("foo", "bar"), arrayListOf<String>())
abstract class OrderedIterableTests<T : Iterable<String>>(data: T, empty: T) : IterableTests<T>(data, empty) {
Test fun indexOf() {
@Test
fun indexOf() {
expect(0) { data.indexOf("foo") }
expect(-1) { empty.indexOf("foo") }
expect(1) { data.indexOf("bar") }
expect(-1) { data.indexOf("zap") }
}
Test fun lastIndexOf() {
@Test
fun lastIndexOf() {
expect(0) { data.lastIndexOf("foo") }
expect(-1) { empty.lastIndexOf("foo") }
expect(1) { data.lastIndexOf("bar") }
expect(-1) { data.lastIndexOf("zap") }
}
Test fun indexOfFirst() {
@Test
fun indexOfFirst() {
expect(-1) { data.indexOfFirst { it.contains("p") } }
expect(0) { data.indexOfFirst { it.startsWith('f') } }
expect(-1) { empty.indexOfFirst { it.startsWith('f') } }
}
Test fun indexOfLast() {
@Test
fun indexOfLast() {
expect(-1) { data.indexOfLast { it.contains("p") } }
expect(1) { data.indexOfLast { it.length() == 3 } }
expect(-1) { empty.indexOfLast { it.startsWith('f') } }
}
Test fun elementAt() {
@Test
fun elementAt() {
expect("foo") { data.elementAt(0) }
expect("bar") { data.elementAt(1) }
fails { data.elementAt(2) }
@@ -64,7 +69,8 @@ abstract class OrderedIterableTests<T : Iterable<String>>(data: T, empty: T) : I
}
Test fun first() {
@Test
fun first() {
expect("foo") { data.first() }
fails {
data.first { it.startsWith("x") }
@@ -75,7 +81,8 @@ abstract class OrderedIterableTests<T : Iterable<String>>(data: T, empty: T) : I
expect("foo") { data.first { it.startsWith("f") } }
}
Test fun firstOrNull() {
@Test
fun firstOrNull() {
expect(null) { data.firstOrNull { it.startsWith("x") } }
expect(null) { empty.firstOrNull() }
@@ -83,7 +90,8 @@ abstract class OrderedIterableTests<T : Iterable<String>>(data: T, empty: T) : I
assertEquals("foo", f)
}
Test fun last() {
@Test
fun last() {
assertEquals("bar", data.last())
fails {
data.last { it.startsWith("x") }
@@ -94,7 +102,8 @@ abstract class OrderedIterableTests<T : Iterable<String>>(data: T, empty: T) : I
expect("foo") { data.last { it.startsWith("f") } }
}
Test fun lastOrNull() {
@Test
fun lastOrNull() {
expect(null) { data.lastOrNull { it.startsWith("x") } }
expect(null) { empty.lastOrNull() }
expect("foo") { data.lastOrNull { it.startsWith("f") } }
@@ -102,7 +111,8 @@ abstract class OrderedIterableTests<T : Iterable<String>>(data: T, empty: T) : I
}
abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
Test fun any() {
@Test
fun any() {
expect(true) { data.any() }
expect(false) { empty.any() }
expect(true) { data.any { it.startsWith("f") } }
@@ -110,13 +120,15 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
expect(false) { empty.any { it.startsWith("x") } }
}
Test fun all() {
@Test
fun all() {
expect(true) { data.all { it.length() == 3 } }
expect(false) { data.all { it.startsWith("b") } }
expect(true) { empty.all { it.startsWith("b") } }
}
Test fun none() {
@Test
fun none() {
expect(false) { data.none() }
expect(true) { empty.none() }
expect(false) { data.none { it.length() == 3 } }
@@ -125,7 +137,8 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
expect(true) { empty.none { it.startsWith("b") } }
}
Test fun filter() {
@Test
fun filter() {
val foo = data.filter { it.startsWith("f") }
expect(true) { foo is List<String> }
expect(true) { foo.all { it.startsWith("f") } }
@@ -133,7 +146,8 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
assertEquals(listOf("foo"), foo)
}
Test fun drop() {
@Test
fun drop() {
val foo = data.drop(1)
expect(true) { foo is List<String> }
expect(true) { foo.all { it.startsWith("b") } }
@@ -141,7 +155,8 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
assertEquals(listOf("bar"), foo)
}
Test fun dropWhile() {
@Test
fun dropWhile() {
val foo = data.dropWhile { it[0] == 'f' }
expect(true) { foo is List<String> }
expect(true) { foo.all { it.startsWith("b") } }
@@ -149,7 +164,8 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
assertEquals(listOf("bar"), foo)
}
Test fun filterNot() {
@Test
fun filterNot() {
val notFoo = data.filterNot { it.startsWith("f") }
expect(true) { notFoo is List<String> }
expect(true) { notFoo.none { it.startsWith("f") } }
@@ -157,20 +173,23 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
assertEquals(listOf("bar"), notFoo)
}
Test fun forEach() {
@Test
fun forEach() {
var count = 0
data.forEach { count += it.length() }
assertEquals(6, count)
}
Test fun contains() {
@Test
fun contains() {
assertTrue(data.contains("foo"))
assertTrue("bar" in data)
assertTrue("baz" !in data)
assertFalse("baz" in empty)
}
Test fun single() {
@Test
fun single() {
fails { data.single() }
fails { empty.single() }
expect("foo") { data.single { it.startsWith("f") } }
@@ -180,7 +199,7 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
}
}
Test
@Test
fun singleOrNull() {
expect(null) { data.singleOrNull() }
expect(null) { empty.singleOrNull() }
@@ -191,7 +210,7 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
}
}
Test
@Test
fun map() {
val lengths = data.map { it.length() }
assertTrue {
@@ -201,38 +220,38 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
assertEquals(listOf(3, 3), lengths)
}
Test
@Test
fun flatten() {
assertEquals(listOf(0, 1, 2, 3, 0, 1, 2, 3), data.map { 0..it.length() }.flatten())
}
Test
@Test
fun mapIndexed() {
val shortened = data.mapIndexed { index, value -> value.substring(0..index) }
assertEquals(2, shortened.size())
assertEquals(listOf("f", "ba"), shortened)
}
Test
@Test
fun withIndex() {
val indexed = data.withIndex().map { it.value.substring(0..it.index) }
assertEquals(2, indexed.size())
assertEquals(listOf("f", "ba"), indexed)
}
Test
@Test
fun max() {
expect("foo") { data.max() }
expect("bar") { data.maxBy { it.last() } }
}
Test
@Test
fun min() {
expect("bar") { data.min() }
expect("foo") { data.minBy { it.last() } }
}
Test
@Test
fun count() {
expect(2) { data.count() }
expect(0) { empty.count() }
@@ -244,7 +263,7 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
expect(0) { empty.count { it.startsWith("x") } }
}
Test
@Test
fun sumBy() {
expect(6) { data.sumBy { it.length() } }
expect(0) { empty.sumBy { it.length() } }
@@ -253,7 +272,7 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
expect(0.0) { empty.sumByDouble { it.length().toDouble() / 2 } }
}
Test
@Test
fun withIndices() {
var index = 0
for ((i, d) in data.withIndex()) {
@@ -264,19 +283,19 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
assertEquals(data.count(), index)
}
Test
@Test
fun fold() {
expect(231) { data.fold(1, { a, b -> a + if (b == "foo") 200 else 30 }) }
}
Test
@Test
fun reduce() {
val reduced = data.reduce { a, b -> a + b }
assertEquals(6, reduced.length())
assertTrue(reduced == "foobar" || reduced == "barfoo")
}
Test
@Test
fun mapAndJoinToString() {
val result = data.joinToString(separator = "-") { it.toUpperCase() }
assertEquals("FOO-BAR", result)
@@ -288,16 +307,16 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
assertFalse(result === data)
}
Test
@Test
fun plusElement() = testPlus { it + "zoo" + "g" }
Test
@Test
fun plusCollection() = testPlus { it + listOf("zoo", "g") }
Test
@Test
fun plusArray() = testPlus { it + arrayOf("zoo", "g") }
Test
@Test
fun plusSequence() = testPlus { it + sequenceOf("zoo", "g") }
Test
@Test
fun plusAssign() {
// lets use a mutable variable
var result: Iterable<String> = data
@@ -308,31 +327,31 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
assertEquals(listOf("foo", "bar", "foo", "beer", "cheese", "wine", "zoo", "g"), result)
}
Test
@Test
fun minusElement() {
val result = data - "foo" - "g"
assertEquals(listOf("bar"), result)
}
Test
@Test
fun minusCollection() {
val result = data - listOf("foo", "g")
assertEquals(listOf("bar"), result)
}
Test
@Test
fun minusArray() {
val result = data - arrayOf("foo", "g")
assertEquals(listOf("bar"), result)
}
Test
@Test
fun minusSequence() {
val result = data - sequenceOf("foo", "g")
assertEquals(listOf("bar"), result)
}
Test
@Test
fun minusAssign() {
// lets use a mutable variable
var result: Iterable<String> = data
@@ -6,7 +6,7 @@ import java.util.*
class IteratorsJVMTest {
test fun testEnumeration() {
@test fun testEnumeration() {
val v = Vector<Int>()
for (i in 1..5)
v.add(i)
@@ -4,7 +4,7 @@ import kotlin.test.*
import org.junit.Test as test
class IteratorsTest {
test fun iterationOverIterator() {
@test fun iterationOverIterator() {
val c = listOf(0, 1, 2, 3, 4, 5)
var s = ""
for (i in c.iterator()) {
@@ -11,7 +11,8 @@ class ListBinarySearchTest {
val comparator = compareBy<IncomparableDataItem<Int>?> { it?.value }
Test fun binarySearchByElement() {
@Test
fun binarySearchByElement() {
val list = values
list.forEachIndexed { index, item ->
assertEquals(index, list.binarySearch(item))
@@ -25,7 +26,8 @@ class ListBinarySearchTest {
}
}
Test fun binarySearchByElementNullable() {
@Test
fun binarySearchByElementNullable() {
val list = listOf(null) + values
list.forEachIndexed { index, item ->
assertEquals(index, list.binarySearch(item))
@@ -37,7 +39,8 @@ class ListBinarySearchTest {
}
}
Test fun binarySearchWithComparator() {
@Test
fun binarySearchWithComparator() {
val list = values map { IncomparableDataItem(it) }
list.forEachIndexed { index, item ->
@@ -52,7 +55,8 @@ class ListBinarySearchTest {
}
}
Test fun binarySearchByKey() {
@Test
fun binarySearchByKey() {
val list = values map { IncomparableDataItem(it) }
list.forEachIndexed { index, item ->
@@ -68,7 +72,8 @@ class ListBinarySearchTest {
}
Test fun binarySearchByKeyWithComparator() {
@Test
fun binarySearchByKeyWithComparator() {
val list = values map { IncomparableDataItem(IncomparableDataItem(it)) }
list.forEachIndexed { index, item ->
@@ -87,7 +92,8 @@ class ListBinarySearchTest {
}
}
Test fun binarySearchByMultipleKeys() {
@Test
fun binarySearchByMultipleKeys() {
val list = values.flatMap { v1 -> values.map { v2 -> Pair(v1, v2) } }
list.forEachIndexed { index, item ->
@@ -7,17 +7,20 @@ class ListSpecificTest {
val data = listOf("foo", "bar")
val empty = listOf<String>()
Test fun _toString() {
@Test
fun _toString() {
assertEquals("[foo, bar]", data.toString())
}
Test fun tail() {
@Test
fun tail() {
val data = listOf("foo", "bar", "whatnot")
val actual = data.drop(1)
assertEquals(listOf("bar", "whatnot"), actual)
}
Test fun slice() {
@Test
fun slice() {
val list = listOf('A', 'B', 'C', 'D')
// ABCD
// 0123
@@ -28,7 +31,8 @@ class ListSpecificTest {
assertEquals(listOf('C', 'A', 'D'), list.slice(iter))
}
Test fun getOr() {
@Test
fun getOr() {
expect("foo") { data.get(0) }
expect("bar") { data.get(1) }
fails { data.get(2) }
@@ -44,12 +48,14 @@ class ListSpecificTest {
}
Test fun lastIndex() {
@Test
fun lastIndex() {
assertEquals(-1, empty.lastIndex)
assertEquals(1, data.lastIndex)
}
Test fun mutableList() {
@Test
fun mutableList() {
val items = listOf("beverage", "location", "name")
var list = listOf<String>()
@@ -61,7 +67,8 @@ class ListSpecificTest {
assertEquals("beverage,location,name", list.join(","))
}
Test fun testNullToString() {
@Test
fun testNullToString() {
assertEquals("[null]", listOf<String?>(null).toString())
}
}
@@ -6,7 +6,7 @@ import kotlin.test.*
import org.junit.Test as test
class MapJVMTest {
test fun createSortedMap() {
@test fun createSortedMap() {
val map = sortedMapOf(Pair("c", 3), Pair("b", 2), Pair("a", 1))
assertEquals(1, map["a"])
assertEquals(2, map["b"])
@@ -14,7 +14,7 @@ class MapJVMTest {
assertEquals(listOf("a", "b", "c"), map.keySet().toList())
}
test fun toSortedMap() {
@test fun toSortedMap() {
val map = mapOf(Pair("c", 3), Pair("b", 2), Pair("a", 1))
val sorted = map.toSortedMap()
assertEquals(1, sorted["a"])
@@ -23,7 +23,7 @@ class MapJVMTest {
assertEquals(listOf("a", "b", "c"), sorted.keySet().toList())
}
test fun toSortedMapWithComparator() {
@test fun toSortedMapWithComparator() {
val map = mapOf(Pair("c", 3), Pair("bc", 2), Pair("bd", 4), Pair("abc", 1))
val sorted = map.toSortedMap(compareBy<String> { it.length() } thenBy { it })
assertEquals(listOf("c", "bc", "bd", "abc"), sorted.keySet().toList())
@@ -32,7 +32,7 @@ class MapJVMTest {
assertEquals(3, sorted["c"])
}
test fun toProperties() {
@test fun toProperties() {
val map = mapOf("a" to "A", "b" to "B")
val prop = map.toProperties()
assertEquals(2, prop.size())
@@ -40,7 +40,7 @@ class MapJVMTest {
assertEquals("B", prop.getProperty("b", "fail"))
}
test fun getOrPutFailsOnConcurrentMap() {
@test fun getOrPutFailsOnConcurrentMap() {
val map = ConcurrentHashMap<String, Int>()
fails {
+52 -52
View File
@@ -9,7 +9,7 @@ import org.junit.Test as test
class MapTest {
test fun getOrElse() {
@test fun getOrElse() {
val data = mapOf<String, Int>()
val a = data.getOrElse("foo") { 2 }
assertEquals(2, a)
@@ -23,7 +23,7 @@ class MapTest {
assertEquals(null, c)
}
test fun getOrImplicitDefault() {
@test fun getOrImplicitDefault() {
val data: MutableMap<String, Int> = hashMapOf("bar" to 1)
assertTrue(fails { data.getOrImplicitDefault("foo") } is NoSuchElementException)
assertEquals(1, data.getOrImplicitDefault("bar"))
@@ -44,7 +44,7 @@ class MapTest {
assertEquals(42, withReplacedDefault.getOrImplicitDefault("loop"))
}
test fun getOrPut() {
@test fun getOrPut() {
val data = hashMapOf<String, Int>()
val a = data.getOrPut("foo") { 2 }
assertEquals(2, a)
@@ -59,13 +59,13 @@ class MapTest {
assertEquals(null, c)
}
test fun sizeAndEmpty() {
@test fun sizeAndEmpty() {
val data = hashMapOf<String, Int>()
assertTrue { data.none() }
assertEquals(data.size(), 0)
}
test fun setViaIndexOperators() {
@test fun setViaIndexOperators() {
val map = hashMapOf<String, String>()
assertTrue { map.none() }
assertEquals(map.size(), 0)
@@ -77,7 +77,7 @@ class MapTest {
assertEquals("James", map["name"])
}
test fun iterate() {
@test fun iterate() {
val map = mapOf("beverage" to "beer", "location" to "Mells", "name" to "James")
val list = arrayListOf<String>()
for (e in map) {
@@ -89,13 +89,13 @@ class MapTest {
assertEquals("beverage,beer,location,Mells,name,James", list.join(","))
}
test fun stream() {
@test fun stream() {
val map = mapOf("beverage" to "beer", "location" to "Mells", "name" to "James")
val named = map.asSequence().filter { it.key == "name" }.single()
assertEquals("James", named.value)
}
test fun iterateWithProperties() {
@test fun iterateWithProperties() {
val map = mapOf("beverage" to "beer", "location" to "Mells", "name" to "James")
val list = arrayListOf<String>()
for (e in map) {
@@ -107,7 +107,7 @@ class MapTest {
assertEquals("beverage,beer,location,Mells,name,James", list.join(","))
}
test fun iterateWithExtraction() {
@test fun iterateWithExtraction() {
val map = mapOf("beverage" to "beer", "location" to "Mells", "name" to "James")
val list = arrayListOf<String>()
for ((key, value) in map) {
@@ -119,20 +119,20 @@ class MapTest {
assertEquals("beverage,beer,location,Mells,name,James", list.join(","))
}
test fun contains() {
@test fun contains() {
val map = mapOf("a" to 1, "b" to 2)
assertTrue("a" in map)
assertTrue("c" !in map)
}
test fun map() {
@test fun map() {
val m1 = mapOf("beverage" to "beer", "location" to "Mells")
val list = m1.map { it.value + " rocks" }
assertEquals(listOf("beer rocks", "Mells rocks"), list)
}
test fun mapValues() {
@test fun mapValues() {
val m1 = mapOf("beverage" to "beer", "location" to "Mells")
val m2 = m1.mapValues { it.value + "2" }
@@ -140,7 +140,7 @@ class MapTest {
assertEquals("Mells2", m2["location"])
}
test fun mapKeys() {
@test fun mapKeys() {
val m1 = mapOf("beverage" to "beer", "location" to "Mells")
val m2 = m1.mapKeys { it.key + "2" }
@@ -148,21 +148,21 @@ class MapTest {
assertEquals("Mells", m2["location2"])
}
test fun createUsingPairs() {
@test fun createUsingPairs() {
val map = mapOf(Pair("a", 1), Pair("b", 2))
assertEquals(2, map.size())
assertEquals(1, map["a"])
assertEquals(2, map["b"])
}
test fun createFromIterable() {
@test fun createFromIterable() {
val map = listOf(Pair("a", 1), Pair("b", 2)).toMap()
assertEquals(2, map.size())
assertEquals(1, map.get("a"))
assertEquals(2, map.get("b"))
}
test fun createWithSelector() {
@test fun createWithSelector() {
val map = listOf("a", "bb", "ccc").toMap { it.length() }
assertEquals(3, map.size())
assertEquals("a", map.get(1))
@@ -170,14 +170,14 @@ class MapTest {
assertEquals("ccc", map.get(3))
}
test fun createWithSelectorAndOverwrite() {
@test fun createWithSelectorAndOverwrite() {
val map = listOf("aa", "bb", "ccc").toMap { it.length() }
assertEquals(2, map.size())
assertEquals("bb", map.get(2))
assertEquals("ccc", map.get(3))
}
test fun createWithSelectorForKeyAndValue() {
@test fun createWithSelectorForKeyAndValue() {
val map = listOf("a", "bb", "ccc").toMap({ it.length() }, { it.toUpperCase() })
assertEquals(3, map.size())
assertEquals("A", map.get(1))
@@ -185,14 +185,14 @@ class MapTest {
assertEquals("CCC", map.get(3))
}
test fun createUsingTo() {
@test fun createUsingTo() {
val map = mapOf("a" to 1, "b" to 2)
assertEquals(2, map.size())
assertEquals(1, map["a"])
assertEquals(2, map["b"])
}
test fun createLinkedMap() {
@test fun createLinkedMap() {
val map = linkedMapOf(Pair("c", 3), Pair("b", 2), Pair("a", 1))
assertEquals(1, map["a"])
assertEquals(2, map["b"])
@@ -200,7 +200,7 @@ class MapTest {
assertEquals(listOf("c", "b", "a"), map.keySet().toList())
}
test fun filter() {
@test fun filter() {
val map = mapOf(Pair("b", 3), Pair("c", 2), Pair("a", 2))
val filteredByKey = map.filter { it.key == "b" }
assertEquals(1, filteredByKey.size())
@@ -223,7 +223,7 @@ class MapTest {
assertEquals(2, filteredByValue2["a"])
}
test fun any() {
@test fun any() {
val map = mapOf(Pair("b", 3), Pair("c", 2), Pair("a", 2))
assertTrue(map.any())
assertFalse(emptyMap<String, Int>().any())
@@ -235,7 +235,7 @@ class MapTest {
assertFalse(map.any { it.value == 5 })
}
test fun all() {
@test fun all() {
val map = mapOf(Pair("b", 3), Pair("c", 2), Pair("a", 2))
assertTrue(map.all { it.key != "d" })
assertTrue(emptyMap<String, Int>().all { it.key == "d" })
@@ -244,7 +244,7 @@ class MapTest {
assertFalse(map.all { it.value == 2 })
}
test fun countBy() {
@test fun countBy() {
val map = mapOf(Pair("b", 3), Pair("c", 2), Pair("a", 2))
assertEquals(3, map.count())
@@ -255,7 +255,7 @@ class MapTest {
assertEquals(2, filteredByValue)
}
test fun filterNot() {
@test fun filterNot() {
val map = mapOf(Pair("b", 3), Pair("c", 2), Pair("a", 2))
val filteredByKey = map.filterNot { it.key == "b" }
assertEquals(2, filteredByKey.size())
@@ -277,18 +277,18 @@ class MapTest {
assertEquals(3, map["c"])
}
test fun plusAssign() = testPlusAssign {
@test fun plusAssign() = testPlusAssign {
it += "b" to 4
it += "c" to 3
}
test fun plusAssignList() = testPlusAssign { it += listOf("c" to 3, "b" to 4) }
@test fun plusAssignList() = testPlusAssign { it += listOf("c" to 3, "b" to 4) }
test fun plusAssignArray() = testPlusAssign { it += arrayOf("c" to 3, "b" to 4) }
@test fun plusAssignArray() = testPlusAssign { it += arrayOf("c" to 3, "b" to 4) }
test fun plusAssignSequence() = testPlusAssign { it += sequenceOf("c" to 3, "b" to 4) }
@test fun plusAssignSequence() = testPlusAssign { it += sequenceOf("c" to 3, "b" to 4) }
test fun plusAssignMap() = testPlusAssign { it += mapOf("c" to 3, "b" to 4) }
@test fun plusAssignMap() = testPlusAssign { it += mapOf("c" to 3, "b" to 4) }
fun testPlus(doPlus: (Map<String, Int>) -> Map<String, Int>) {
val original = mapOf("A" to 1, "B" to 2)
@@ -299,15 +299,15 @@ class MapTest {
assertEquals(3, extended["C"])
}
test fun plus() = testPlus { it + ("C" to 3) + ("B" to 4) }
@test fun plus() = testPlus { it + ("C" to 3) + ("B" to 4) }
test fun plusList() = testPlus { it + listOf("C" to 3, "B" to 4) }
@test fun plusList() = testPlus { it + listOf("C" to 3, "B" to 4) }
test fun plusArray() = testPlus { it + arrayOf("C" to 3, "B" to 4) }
@test fun plusArray() = testPlus { it + arrayOf("C" to 3, "B" to 4) }
test fun plusSequence() = testPlus { it + sequenceOf("C" to 3, "B" to 4) }
@test fun plusSequence() = testPlus { it + sequenceOf("C" to 3, "B" to 4) }
test fun plusMap() = testPlus { it + mapOf("C" to 3, "B" to 4) }
@test fun plusMap() = testPlus { it + mapOf("C" to 3, "B" to 4) }
fun testMinus(doMinus: (Map<String, Int>) -> Map<String, Int>) {
@@ -316,15 +316,15 @@ class MapTest {
assertEquals("A" to 1, shortened.entrySet().single().toPair())
}
test fun minus() = testMinus { it - "B" - "C" }
@test fun minus() = testMinus { it - "B" - "C" }
test fun minusList() = testMinus { it - listOf("B", "C") }
@test fun minusList() = testMinus { it - listOf("B", "C") }
test fun minusArray() = testMinus { it - arrayOf("B", "C") }
@test fun minusArray() = testMinus { it - arrayOf("B", "C") }
test fun minusSequence() = testMinus { it - sequenceOf("B", "C") }
@test fun minusSequence() = testMinus { it - sequenceOf("B", "C") }
test fun minusSet() = testMinus { it - setOf("B", "C") }
@test fun minusSet() = testMinus { it - setOf("B", "C") }
@@ -334,16 +334,16 @@ class MapTest {
assertEquals("A" to 1, original.entrySet().single().toPair())
}
test fun minusAssign() = testMinusAssign {
@test fun minusAssign() = testMinusAssign {
it -= "B"
it -= "C"
}
test fun minusAssignList() = testMinusAssign { it -= listOf("B", "C") }
@test fun minusAssignList() = testMinusAssign { it -= listOf("B", "C") }
test fun minusAssignArray() = testMinusAssign { it -= arrayOf("B", "C") }
@test fun minusAssignArray() = testMinusAssign { it -= arrayOf("B", "C") }
test fun minusAssignSequence() = testMinusAssign { it -= sequenceOf("B", "C") }
@test fun minusAssignSequence() = testMinusAssign { it -= sequenceOf("B", "C") }
fun testIdempotent(operation: (Map<String, Int>) -> Map<String, Int>) {
@@ -359,17 +359,17 @@ class MapTest {
}
test fun plusEmptyList() = testIdempotent { it + listOf() }
test fun minusEmptyList() = testIdempotent { it - listOf() }
@test fun plusEmptyList() = testIdempotent { it + listOf() }
@test fun minusEmptyList() = testIdempotent { it - listOf() }
test fun plusEmptySet() = testIdempotent { it + setOf() }
test fun minusEmptySet() = testIdempotent { it - setOf() }
@test fun plusEmptySet() = testIdempotent { it + setOf() }
@test fun minusEmptySet() = testIdempotent { it - setOf() }
test fun plusAssignEmptyList() = testIdempotentAssign { it += listOf() }
test fun minusAssignEmptyList() = testIdempotentAssign { it -= listOf() }
@test fun plusAssignEmptyList() = testIdempotentAssign { it += listOf() }
@test fun minusAssignEmptyList() = testIdempotentAssign { it -= listOf() }
test fun plusAssignEmptySet() = testIdempotentAssign { it += setOf() }
test fun minusAssignEmptySet() = testIdempotentAssign { it -= setOf() }
@test fun plusAssignEmptySet() = testIdempotentAssign { it += setOf() }
@test fun minusAssignEmptySet() = testIdempotentAssign { it -= setOf() }
}
@@ -10,7 +10,7 @@ class MutableCollectionTest {
// TODO: Use apply scope function
test fun addAll() {
@test fun addAll() {
val data = listOf("foo", "bar")
fun assertAdd(f: MutableList<String>.() -> Unit) = assertEquals(data, arrayListOf<String>().let { it.f(); it })
@@ -21,7 +21,7 @@ class MutableCollectionTest {
assertAdd { addAll(data.asSequence()) }
}
test fun removeAll() {
@test fun removeAll() {
val content = arrayOf("foo", "bar", "bar")
val data = listOf("bar")
val expected = listOf("foo")
@@ -35,7 +35,7 @@ class MutableCollectionTest {
}
test fun retainAll() {
@test fun retainAll() {
val content = arrayOf("foo", "bar", "bar")
val data = listOf("bar")
val expected = listOf("bar", "bar")
@@ -25,7 +25,7 @@ import org.junit.Test as test
*/
class ReversedViewsJVMTest {
test fun testMutableSubList() {
@test fun testMutableSubList() {
val original = arrayListOf(1, 2, 3, 4)
val reversedSubList = original.asReversed().subList(1, 3)
@@ -26,11 +26,11 @@ import org.junit.Test as test
class ReversedViewsTest {
test fun testNullToString() {
@test fun testNullToString() {
assertEquals("[null]", listOf<String?>(null).asReversed().toString())
}
test fun testBehavior() {
@test fun testBehavior() {
val original = listOf(2L, 3L, Long.MAX_VALUE)
val reversed = original.reversed()
compare(reversed, original.asReversed()) {
@@ -38,12 +38,12 @@ class ReversedViewsTest {
}
}
test fun testSimple() {
@test fun testSimple() {
assertEquals(listOf(3, 2, 1), listOf(1, 2, 3).asReversed())
assertEquals(listOf(3, 2, 1), listOf(1, 2, 3).asReversed().toList())
}
test fun testRandomAccess() {
@test fun testRandomAccess() {
val reversed = listOf(1, 2, 3).asReversed()
assertEquals(3, reversed[0])
@@ -51,40 +51,40 @@ class ReversedViewsTest {
assertEquals(1, reversed[2])
}
test fun testDoubleReverse() {
@test fun testDoubleReverse() {
assertEquals(listOf(1, 2, 3), listOf(1, 2, 3).asReversed().asReversed())
assertEquals(listOf(2, 3), listOf(1, 2, 3, 4).asReversed().subList(1, 3).asReversed())
}
test fun testEmpty() {
@test fun testEmpty() {
assertEquals(emptyList<Int>(), emptyList<Int>().asReversed())
}
test fun testReversedSubList() {
@test fun testReversedSubList() {
val reversed = (1..10).toList().asReversed()
assertEquals(listOf(9, 8, 7), reversed.subList(1, 4))
}
test fun testMutableSimple() {
@test fun testMutableSimple() {
assertEquals(listOf(3, 2, 1), arrayListOf(1, 2, 3).asReversed())
assertEquals(listOf(3, 2, 1), arrayListOf(1, 2, 3).asReversed().toList())
}
test fun testMutableDoubleReverse() {
@test fun testMutableDoubleReverse() {
assertEquals(listOf(1, 2, 3), arrayListOf(1, 2, 3).asReversed().asReversed())
assertEquals(listOf(2, 3), arrayListOf(1, 2, 3, 4).asReversed().subList(1, 3).asReversed())
}
test fun testMutableEmpty() {
@test fun testMutableEmpty() {
assertEquals(emptyList<Int>(), arrayListOf<Int>().asReversed())
}
test fun testMutableReversedSubList() {
@test fun testMutableReversedSubList() {
val reversed = (1..10).toArrayList().asReversed()
assertEquals(listOf(9, 8, 7), reversed.subList(1, 4))
}
test fun testMutableAdd() {
@test fun testMutableAdd() {
val original = arrayListOf(1, 2, 3)
val reversed = original.asReversed()
@@ -97,7 +97,7 @@ class ReversedViewsTest {
assertEquals(listOf(0, 1, 2, 3, 4), original)
}
test fun testMutableSet() {
@test fun testMutableSet() {
val original = arrayListOf(1, 2, 3)
val reversed = original.asReversed()
@@ -109,7 +109,7 @@ class ReversedViewsTest {
assertEquals(listOf(300, 200, 100), reversed)
}
test fun testMutableRemove() {
@test fun testMutableRemove() {
val original = arrayListOf("a", "b", "c")
val reversed = original.asReversed()
@@ -124,7 +124,7 @@ class ReversedViewsTest {
assertEquals(emptyList<String>(), original)
}
test fun testMutableRemoveByObj() {
@test fun testMutableRemoveByObj() {
val original = arrayListOf("a", "b", "c")
val reversed = original.asReversed()
@@ -133,7 +133,7 @@ class ReversedViewsTest {
assertEquals(listOf("b", "a"), reversed)
}
test fun testMutableClear() {
@test fun testMutableClear() {
val original = arrayListOf(1, 2, 3)
val reversed = original.asReversed()
@@ -143,17 +143,17 @@ class ReversedViewsTest {
assertEquals(emptyList<Int>(), original)
}
test fun testContains() {
@test fun testContains() {
assertTrue { 1 in listOf(1, 2, 3).asReversed() }
assertTrue { 1 in arrayListOf(1, 2, 3).asReversed() }
}
test fun testIndexOf() {
@test fun testIndexOf() {
assertEquals(2, listOf(1, 2, 3).asReversed().indexOf(1))
assertEquals(2, arrayListOf(1, 2, 3).asReversed().indexOf(1))
}
test fun testBidirectionalModifications() {
@test fun testBidirectionalModifications() {
val original = arrayListOf(1, 2, 3, 4)
val reversed = original.asReversed()
@@ -166,7 +166,7 @@ class ReversedViewsTest {
assertEquals(listOf(3, 2), reversed)
}
test fun testGetIOOB() {
@test fun testGetIOOB() {
val success = try {
listOf(1, 2, 3).asReversed().get(3)
true
@@ -177,7 +177,7 @@ class ReversedViewsTest {
assertFalse(success)
}
test fun testSetIOOB() {
@test fun testSetIOOB() {
val success = try {
arrayListOf(1, 2, 3).asReversed().set(3, 0)
true
@@ -188,7 +188,7 @@ class ReversedViewsTest {
assertFalse(success)
}
test fun testAddIOOB() {
@test fun testAddIOOB() {
val success = try {
arrayListOf(1, 2, 3).asReversed().add(4, 0)
true
@@ -199,7 +199,7 @@ class ReversedViewsTest {
assertFalse(success)
}
test fun testRemoveIOOB() {
@test fun testRemoveIOOB() {
val success = try {
arrayListOf(1, 2, 3).asReversed().remove(3)
true
@@ -5,7 +5,7 @@ import kotlin.test.assertEquals
class SequenceJVMTest {
test fun filterIsInstance() {
@test fun filterIsInstance() {
val src: Sequence<Any> = listOf(1, 2, 3.toDouble(), "abc", "cde").asSequence()
val intValues: Sequence<Int> = src.filterIsInstance<Int>()
@@ -19,20 +19,20 @@ fun fibonacci(): Sequence<Int> {
public class SequenceTest {
test fun filterEmptySequence() {
@test fun filterEmptySequence() {
for (sequence in listOf(emptySequence<String>(), sequenceOf<String>())) {
assertEquals(0, sequence.filter { false }.count())
assertEquals(0, sequence.filter { true }.count())
}
}
test fun mapEmptySequence() {
@test fun mapEmptySequence() {
for (sequence in listOf(emptySequence<String>(), sequenceOf<String>())) {
assertEquals(0, sequence.map { true }.count())
}
}
test fun requireNoNulls() {
@test fun requireNoNulls() {
val sequence = sequenceOf<String?>("foo", "bar")
val notNull = sequence.requireNoNulls()
assertEquals(listOf("foo", "bar"), notNull.toList())
@@ -45,25 +45,25 @@ public class SequenceTest {
}
}
test fun filterNullable() {
@test fun filterNullable() {
val data = sequenceOf(null, "foo", null, "bar")
val filtered = data.filter { it == null || it == "foo" }
assertEquals(listOf(null, "foo", null), filtered.toList())
}
test fun filterNot() {
@test fun filterNot() {
val data = sequenceOf(null, "foo", null, "bar")
val filtered = data.filterNot { it == null }
assertEquals(listOf("foo", "bar"), filtered.toList())
}
test fun filterNotNull() {
@test fun filterNotNull() {
val data = sequenceOf(null, "foo", null, "bar")
val filtered = data.filterNotNull()
assertEquals(listOf("foo", "bar"), filtered.toList())
}
test fun mapNotNull() {
@test fun mapNotNull() {
val data = sequenceOf(null, "foo", null, "bar")
val foo = data.mapNotNull { it.length() }
assertEquals(listOf(3, 3), foo.toList())
@@ -73,60 +73,60 @@ public class SequenceTest {
}
}
test fun mapAndJoinToString() {
@test fun mapAndJoinToString() {
assertEquals("3, 5, 8", fibonacci().withIndex().filter { it.index > 3 }.take(3).joinToString { it.value.toString() })
}
test fun withIndex() {
@test fun withIndex() {
val data = sequenceOf("foo", "bar")
val indexed = data.withIndex().map { it.value.substring(0..it.index) }.toList()
assertEquals(2, indexed.size())
assertEquals(listOf("f", "ba"), indexed)
}
test fun filterAndTakeWhileExtractTheElementsWithinRange() {
@test fun filterAndTakeWhileExtractTheElementsWithinRange() {
assertEquals(listOf(144, 233, 377, 610, 987), fibonacci().filter { it > 100 }.takeWhile { it < 1000 }.toList())
}
test fun foldReducesTheFirstNElements() {
@test fun foldReducesTheFirstNElements() {
val sum = { a: Int, b: Int -> a + b }
assertEquals(listOf(13, 21, 34, 55, 89).fold(0, sum), fibonacci().filter { it > 10 }.take(5).fold(0, sum))
}
test fun takeExtractsTheFirstNElements() {
@test fun takeExtractsTheFirstNElements() {
assertEquals(listOf(0, 1, 1, 2, 3, 5, 8, 13, 21, 34), fibonacci().take(10).toList())
}
test fun mapAndTakeWhileExtractTheTransformedElements() {
@test fun mapAndTakeWhileExtractTheTransformedElements() {
assertEquals(listOf(0, 3, 3, 6, 9, 15), fibonacci().map { it * 3 }.takeWhile { i: Int -> i < 20 }.toList())
}
test fun joinConcatenatesTheFirstNElementsAboveAThreshold() {
@test fun joinConcatenatesTheFirstNElementsAboveAThreshold() {
assertEquals("13, 21, 34, 55, 89, ...", fibonacci().filter { it > 10 }.joinToString(separator = ", ", limit = 5))
}
test fun drop() {
@test fun drop() {
assertEquals("13, 21, 34, 55, 89, 144, 233, 377, 610, 987, ...", fibonacci().drop(7).joinToString(limit = 10))
assertEquals("13, 21, 34, 55, 89, 144, 233, 377, 610, 987, ...", fibonacci().drop(3).drop(4).joinToString(limit = 10))
}
test fun take() {
@test fun take() {
assertEquals("0, 1, 1, 2, 3, 5, 8", fibonacci().take(7).joinToString())
assertEquals("2, 3, 5, 8", fibonacci().drop(3).take(4).joinToString())
}
test fun dropWhile() {
@test fun dropWhile() {
assertEquals("233, 377, 610", fibonacci().dropWhile { it < 200 }.take(3).joinToString(limit = 10))
assertEquals("", sequenceOf(1).dropWhile { it < 200 }.joinToString(limit = 10))
}
test fun merge() {
@test fun merge() {
expect(listOf("ab", "bc", "cd")) {
sequenceOf("a", "b", "c").merge(sequenceOf("b", "c", "d")) { a, b -> a + b }.toList()
}
}
test fun toStringJoinsNoMoreThanTheFirstTenElements() {
@test fun toStringJoinsNoMoreThanTheFirstTenElements() {
assertEquals("0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...", fibonacci().joinToString(limit = 10))
assertEquals("13, 21, 34, 55, 89, 144, 233, 377, 610, 987, ...", fibonacci().filter { it > 10 }.joinToString(limit = 10))
assertEquals("144, 233, 377, 610, 987", fibonacci().filter { it > 100 }.takeWhile { it < 1000 }.joinToString())
@@ -141,12 +141,12 @@ public class SequenceTest {
}
test fun plusElement() = testPlus { it + "cheese" + "wine" }
test fun plusCollection() = testPlus { it + listOf("cheese", "wine") }
test fun plusArray() = testPlus { it + arrayOf("cheese", "wine") }
test fun plusSequence() = testPlus { it + sequenceOf("cheese", "wine") }
@test fun plusElement() = testPlus { it + "cheese" + "wine" }
@test fun plusCollection() = testPlus { it + listOf("cheese", "wine") }
@test fun plusArray() = testPlus { it + arrayOf("cheese", "wine") }
@test fun plusSequence() = testPlus { it + sequenceOf("cheese", "wine") }
test fun plusAssign() {
@test fun plusAssign() {
// lets use a mutable variable
var seq = sequenceOf("a")
seq += "foo"
@@ -163,12 +163,12 @@ public class SequenceTest {
assertEquals(expected_, b.toList())
}
test fun minusElement() = testMinus(expected = listOf("foo", "bar")) { it - "bar" - "zoo" }
test fun minusCollection() = testMinus { it - listOf("bar", "zoo") }
test fun minusArray() = testMinus { it - arrayOf("bar", "zoo") }
test fun minusSequence() = testMinus { it - sequenceOf("bar", "zoo") }
@test fun minusElement() = testMinus(expected = listOf("foo", "bar")) { it - "bar" - "zoo" }
@test fun minusCollection() = testMinus { it - listOf("bar", "zoo") }
@test fun minusArray() = testMinus { it - arrayOf("bar", "zoo") }
@test fun minusSequence() = testMinus { it - sequenceOf("bar", "zoo") }
test fun minusIsLazyIterated() {
@test fun minusIsLazyIterated() {
val seq = sequenceOf("foo", "bar")
val list = arrayListOf<String>()
val result = seq - list
@@ -179,7 +179,7 @@ public class SequenceTest {
assertEquals(emptyList<String>(), result.toList())
}
test fun minusAssign() {
@test fun minusAssign() {
// lets use a mutable variable of readonly list
val data = sequenceOf("cheese", "foo", "beer", "cheese", "wine")
var l = data
@@ -194,7 +194,7 @@ public class SequenceTest {
test fun iterationOverSequence() {
@test fun iterationOverSequence() {
var s = ""
for (i in sequenceOf(0, 1, 2, 3, 4, 5)) {
s += i.toString()
@@ -202,7 +202,7 @@ public class SequenceTest {
assertEquals("012345", s)
}
test fun sequenceFromFunction() {
@test fun sequenceFromFunction() {
var count = 3
val sequence = sequence {
@@ -218,7 +218,7 @@ public class SequenceTest {
}
}
test fun sequenceFromFunctionWithInitialValue() {
@test fun sequenceFromFunctionWithInitialValue() {
val values = sequence(3) { n -> if (n > 0) n - 1 else null }
val expected = listOf(3, 2, 1, 0)
assertEquals(expected, values.toList())
@@ -226,7 +226,7 @@ public class SequenceTest {
}
test fun sequenceFromIterator() {
@test fun sequenceFromIterator() {
val list = listOf(3, 2, 1, 0)
val iterator = list.iterator()
val sequence = iterator.asSequence()
@@ -236,7 +236,7 @@ public class SequenceTest {
}
}
test fun makeSequenceOneTimeConstrained() {
@test fun makeSequenceOneTimeConstrained() {
val sequence = sequenceOf(1, 2, 3, 4)
sequence.toList()
sequence.toList()
@@ -256,13 +256,13 @@ public class SequenceTest {
return result
}
test fun sequenceExtensions() {
@test fun sequenceExtensions() {
val d = ArrayList<Int>()
sequenceOf(0, 1, 2, 3, 4, 5).takeWhileTo(d, { i -> i < 4 })
assertEquals(4, d.size())
}
test fun flatMapAndTakeExtractTheTransformedElements() {
@test fun flatMapAndTakeExtractTheTransformedElements() {
val expected = listOf(
'3', // fibonacci(4) = 3
'5', // fibonacci(5) = 5
@@ -276,51 +276,51 @@ public class SequenceTest {
assertEquals(expected, fibonacci().drop(4).flatMap { it.toString().asSequence() }.take(10).toList())
}
test fun flatMap() {
@test fun flatMap() {
val result = sequenceOf(1, 2).flatMap { sequenceOf(0..it) }
assertEquals(listOf(0, 1, 0, 1, 2), result.toList())
}
test fun flatMapOnEmpty() {
@test fun flatMapOnEmpty() {
val result = sequenceOf<Int>().flatMap { sequenceOf(0..it) }
assertTrue(result.none())
}
test fun flatMapWithEmptyItems() {
@test fun flatMapWithEmptyItems() {
val result = sequenceOf(1, 2, 4).flatMap { if (it == 2) sequenceOf<Int>() else sequenceOf(it - 1..it) }
assertEquals(listOf(0, 1, 3, 4), result.toList())
}
test fun flatten() {
@test fun flatten() {
val data = sequenceOf(1, 2).map { sequenceOf(0..it) }
assertEquals(listOf(0, 1, 0, 1, 2), data.flatten().toList())
}
test fun distinct() {
@test fun distinct() {
val sequence = fibonacci().dropWhile { it < 10 }.take(20)
assertEquals(listOf(1, 2, 3, 0), sequence.map { it % 4 }.distinct().toList())
}
test fun distinctBy() {
@test fun distinctBy() {
val sequence = fibonacci().dropWhile { it < 10 }.take(20)
assertEquals(listOf(13, 34, 55, 144), sequence.distinctBy { it % 4 }.toList())
}
test fun unzip() {
@test fun unzip() {
val seq = sequenceOf(1 to 'a', 2 to 'b', 3 to 'c')
val (ints, chars) = seq.unzip()
assertEquals(listOf(1, 2, 3), ints)
assertEquals(listOf('a', 'b', 'c'), chars)
}
test fun sorted() {
@test fun sorted() {
sequenceOf(3, 7, 5).let {
it.sorted().iterator().assertSorted { a, b -> a <= b }
it.sortedDescending().iterator().assertSorted { a, b -> a >= b }
}
}
test fun sortedBy() {
@test fun sortedBy() {
sequenceOf("it", "greater", "less").let {
it.sortedBy { it.length() }.iterator().assertSorted { a, b -> compareValuesBy(a, b) { it.length() } <= 0 }
it.sortedByDescending { it.length() }.iterator().assertSorted { a, b -> compareValuesBy(a, b) { it.length() } >= 0 }
@@ -332,7 +332,7 @@ public class SequenceTest {
}
}
test fun sortedWith() {
@test fun sortedWith() {
val comparator = compareBy { s: String -> s.reversed() }
assertEquals(listOf("act", "wast", "test"), sequenceOf("act", "test", "wast").sortedWith(comparator).toList())
}
@@ -4,29 +4,29 @@ import kotlin.test.*
import org.junit.Test as test
class SetOperationsTest {
test fun distinct() {
@test fun distinct() {
assertEquals(listOf(1, 3, 5), listOf(1, 3, 3, 1, 5, 1, 3).distinct())
assertTrue(listOf<Int>().distinct().isEmpty())
}
test fun distinctBy() {
@test fun distinctBy() {
assertEquals(listOf("some", "cat", "do"), arrayOf("some", "case", "cat", "do", "dog", "it").distinctBy { it.length() })
assertTrue(charArrayOf().distinctBy { it }.isEmpty())
}
test fun union() {
@test fun union() {
assertEquals(listOf(1, 3, 5), listOf(1, 3).union(listOf(5)).toList())
assertEquals(listOf(1), listOf<Int>().union(listOf(1)).toList())
}
test fun subtract() {
@test fun subtract() {
assertEquals(listOf(1, 3), listOf(1, 3).subtract(listOf(5)).toList())
assertEquals(listOf(1, 3), listOf(1, 3, 5).subtract(listOf(5)).toList())
assertTrue(listOf(1, 3, 5).subtract(listOf(1, 3, 5)).none())
assertTrue(listOf<Int>().subtract(listOf(1)).none())
}
test fun intersect() {
@test fun intersect() {
assertTrue(listOf(1, 3).intersect(listOf(5)).none())
assertEquals(listOf(5), listOf(1, 3, 5).intersect(listOf(5)).toList())
assertEquals(listOf(1, 3, 5), listOf(1, 3, 5).intersect(listOf(1, 3, 5)).toList())
@@ -40,12 +40,12 @@ class SetOperationsTest {
assertEquals(setOf("foo", "bar", "cheese", "wine"), set2)
}
test fun plusElement() = testPlus { it + "bar" + "cheese" + "wine" }
test fun plusCollection() = testPlus { it + listOf("bar", "cheese", "wine") }
test fun plusArray() = testPlus { it + arrayOf("bar", "cheese", "wine") }
test fun plusSequence() = testPlus { it + sequenceOf("bar", "cheese", "wine") }
@test fun plusElement() = testPlus { it + "bar" + "cheese" + "wine" }
@test fun plusCollection() = testPlus { it + listOf("bar", "cheese", "wine") }
@test fun plusArray() = testPlus { it + arrayOf("bar", "cheese", "wine") }
@test fun plusSequence() = testPlus { it + sequenceOf("bar", "cheese", "wine") }
test fun plusAssign() {
@test fun plusAssign() {
// lets use a mutable variable
var set = setOf("a")
val setOriginal = set
@@ -70,9 +70,9 @@ class SetOperationsTest {
assertEquals(setOf("foo"), b)
}
test fun minusElement() = testMinus { it - "bar" - "zoo" }
test fun minusCollection() = testMinus { it - listOf("bar", "zoo") }
test fun minusArray() = testMinus { it - arrayOf("bar", "zoo") }
test fun minusSequence() = testMinus { it - sequenceOf("bar", "zoo") }
@test fun minusElement() = testMinus { it - "bar" - "zoo" }
@test fun minusCollection() = testMinus { it - listOf("bar", "zoo") }
@test fun minusArray() = testMinus { it - arrayOf("bar", "zoo") }
@test fun minusSequence() = testMinus { it - sequenceOf("bar", "zoo") }
}
@@ -9,7 +9,7 @@ import java.util.concurrent.*
import java.util.concurrent.TimeUnit.*
class ThreadTest {
test fun scheduledTask() {
@test fun scheduledTask() {
val pool = Executors.newFixedThreadPool(1)
val countDown = CountDownLatch(1)
@@ -19,7 +19,7 @@ class ThreadTest {
assertTrue(countDown.await(2, SECONDS), "Count down is executed")
}
test fun callableInvoke() {
@test fun callableInvoke() {
val pool = Executors.newFixedThreadPool(1)
val future = pool.submit<String> { // type specification required here to choose overload for callable, see KT-7882
@@ -28,7 +28,7 @@ class ThreadTest {
assertEquals("Hello", future.get(2, SECONDS))
}
test fun threadLocalGetOrSet() {
@test fun threadLocalGetOrSet() {
val v = ThreadLocal<String>()
assertEquals("v1", v.getOrSet { "v1" })
@@ -9,7 +9,7 @@ import java.util.Timer
import org.junit.Test as test
class TimerTest {
test fun scheduledTask() {
@test fun scheduledTask() {
val counter = AtomicInteger(0)
val timer = Timer()
+1 -1
View File
@@ -7,7 +7,7 @@ import org.junit.Test as test
class DomBuilderTest() {
test fun buildDocument() {
@test fun buildDocument() {
var doc = createDocument()
assertTrue {
+2 -2
View File
@@ -8,7 +8,7 @@ import org.junit.Test as test
class DomTest {
test fun testCreateDocument() {
@test fun testCreateDocument() {
var doc = createDocument()
assertNotNull(doc, "Should have created a document")
@@ -27,7 +27,7 @@ class DomTest {
println("document ${doc.toXmlString()}")
}
test fun addText() {
@test fun addText() {
var doc = createDocument()
assertNotNull(doc, "Should have created a document")
+1 -1
View File
@@ -7,7 +7,7 @@ import org.junit.Test as test
class NextSiblingTest {
test fun nextSibling() {
@test fun nextSibling() {
val doc = createDocument()
doc.addElement("foo") {
+42 -42
View File
@@ -14,13 +14,13 @@ import kotlin.test.assertTrue
class FilesTest {
test fun testPath() {
@test fun testPath() {
val fileSuf = System.currentTimeMillis().toString()
val file1 = createTempFile("temp", fileSuf)
assertTrue(file1.path.endsWith(fileSuf), file1.path)
}
test fun testCreateTempDir() {
@test fun testCreateTempDir() {
val dirSuf = System.currentTimeMillis().toString()
val dir1 = createTempDir("temp", dirSuf)
assert(dir1.exists() && dir1.isDirectory() && dir1.name.startsWith("temp") && dir1.name.endsWith(dirSuf))
@@ -41,7 +41,7 @@ class FilesTest {
dir3.delete()
}
test fun testCreateTempFile() {
@test fun testCreateTempFile() {
val fileSuf = System.currentTimeMillis().toString()
val file1 = createTempFile("temp", fileSuf)
assert(file1.exists() && file1.name.startsWith("temp") && file1.name.endsWith(fileSuf))
@@ -79,7 +79,7 @@ class FilesTest {
}
}
test fun withSimple() {
@test fun withSimple() {
val basedir = createTestFiles()
try {
val referenceNames =
@@ -104,7 +104,7 @@ class FilesTest {
}
}
test fun withEnterLeave() {
@test fun withEnterLeave() {
val basedir = createTestFiles()
try {
val referenceNames =
@@ -163,7 +163,7 @@ class FilesTest {
}
}
test fun withFilterAndMap() {
@test fun withFilterAndMap() {
val basedir = createTestFiles()
try {
val referenceNames =
@@ -178,7 +178,7 @@ class FilesTest {
}
test fun withDeleteTxtTopDown() {
@test fun withDeleteTxtTopDown() {
val basedir = createTestFiles()
try {
val referenceNames =
@@ -203,7 +203,7 @@ class FilesTest {
}
}
test fun withDeleteTxtBottomUp() {
@test fun withDeleteTxtBottomUp() {
val basedir = createTestFiles()
try {
val referenceNames =
@@ -228,7 +228,7 @@ class FilesTest {
}
}
test fun withFilter() {
@test fun withFilter() {
val basedir = createTestFiles()
try {
fun filter(file: File): Boolean {
@@ -258,7 +258,7 @@ class FilesTest {
}
}
test fun withTotalFilter() {
@test fun withTotalFilter() {
val basedir = createTestFiles()
try {
val referenceNames: Set<String> = setOf()
@@ -283,7 +283,7 @@ class FilesTest {
}
}
test fun withForEach() {
@test fun withForEach() {
val basedir = createTestFiles()
try {
var i = 0
@@ -297,7 +297,7 @@ class FilesTest {
}
}
test fun withCount() {
@test fun withCount() {
val basedir = createTestFiles()
try {
assertEquals(10, basedir.walkTopDown().count());
@@ -307,7 +307,7 @@ class FilesTest {
}
}
test fun withReduce() {
@test fun withReduce() {
val basedir = createTestFiles()
try {
val res = basedir.walkTopDown().reduce { a, b -> if (a.canonicalPath > b.canonicalPath) a else b }
@@ -317,7 +317,7 @@ class FilesTest {
}
}
test fun withVisitorAndDepth() {
@test fun withVisitorAndDepth() {
val basedir = createTestFiles()
try {
val files = HashSet<String>()
@@ -394,7 +394,7 @@ class FilesTest {
}
}
test fun topDown() {
@test fun topDown() {
val basedir = createTestFiles()
try {
val visited = HashSet<File>()
@@ -411,7 +411,7 @@ class FilesTest {
}
}
test fun restrictedAccess() {
@test fun restrictedAccess() {
val basedir = createTestFiles()
val restricted = File(basedir, "1")
try {
@@ -431,7 +431,7 @@ class FilesTest {
}
}
test fun backup() {
@test fun backup() {
var count = 0
fun makeBackup(file: File) {
count++
@@ -465,7 +465,7 @@ class FilesTest {
}
}
test fun find() {
@test fun find() {
val basedir = createTestFiles()
try {
File(basedir, "8/4.txt".separatorsToSystem()).createNewFile()
@@ -481,7 +481,7 @@ class FilesTest {
}
}
test fun findGits() {
@test fun findGits() {
val basedir = createTestFiles()
try {
File(basedir, "1/3/.git").mkdir()
@@ -499,7 +499,7 @@ class FilesTest {
}
}
test fun streamFileTree() {
@test fun streamFileTree() {
val dir = createTempDir()
try {
val subDir1 = createTempDir(prefix = "d1_", directory = dir)
@@ -523,7 +523,7 @@ class FilesTest {
}
}
test fun recurse() {
@test fun recurse() {
val set: MutableSet<String> = HashSet()
val dir = createTestFiles()
dir.recurse { set.add(it.path) }
@@ -531,7 +531,7 @@ class FilesTest {
}
}
test fun listFilesWithFilter() {
@test fun listFilesWithFilter() {
val dir = createTempDir("temp")
createTempFile("temp1", ".kt", dir)
@@ -546,7 +546,7 @@ class FilesTest {
assertEquals(2, result2!!.size())
}
test fun relativeToTest() {
@test fun relativeToTest() {
val file1 = File("/foo/bar/baz")
val file2 = File("/foo/baa/ghoo")
assertEquals("../../bar/baz".separatorsToSystem(), file1.relativeTo(file2))
@@ -577,7 +577,7 @@ class FilesTest {
assertEquals("..", file11.relativeTo(file10))
}
test fun relativeTo() {
@test fun relativeTo() {
assertEquals("kotlin", File("src/kotlin".separatorsToSystem()).relativeTo(File("src")))
assertEquals("", File("dir").relativeTo(File("dir")))
assertEquals("..", File("dir").relativeTo(File("dir/subdir".separatorsToSystem())))
@@ -596,7 +596,7 @@ class FilesTest {
}
}
test fun relativePath() {
@test fun relativePath() {
val file1 = File("src")
val file2 = File(file1, "kotlin")
val file3 = File("test")
@@ -616,7 +616,7 @@ class FilesTest {
assertEquals(elements.size(), i)
}
test fun fileIterator() {
@test fun fileIterator() {
checkFileElements(File("/foo/bar"), File("/"), listOf("foo", "bar"))
checkFileElements(File("\\foo\\bar"), File("\\".separatorsToSystem()), listOf("foo", "bar"))
checkFileElements(File("/foo/bar/gav"), File("/"), listOf("foo", "bar", "gav"))
@@ -637,13 +637,13 @@ class FilesTest {
checkFileElements(File(".."), null, listOf(".."))
}
test fun startsWith() {
@test fun startsWith() {
assertTrue(File("C:\\Users\\Me\\Temp\\Game").startsWith("C:\\Users\\Me"))
assertFalse(File("C:\\Users\\Me\\Temp\\Game").startsWith("C:\\Users\\He"))
assertTrue(File("C:\\Users\\Me").startsWith("C:\\"))
}
test fun endsWith() {
@test fun endsWith() {
assertTrue(File("/foo/bar").endsWith("bar"))
assertTrue(File("/foo/bar").endsWith("/bar"))
assertTrue(File("/foo/bar/gav/bar").endsWith("/bar"))
@@ -652,7 +652,7 @@ class FilesTest {
assertFalse(File("foo/bar").endsWith("/bar"))
}
test fun subPath() {
@test fun subPath() {
if (File.separatorChar == '\\') {
// Check only in Windows
assertEquals(File("mike"), File("//my.host.net/home/mike/temp").subPath(0, 1))
@@ -663,7 +663,7 @@ class FilesTest {
assertEquals(File("gav/hi"), File("/foo/bar/gav/hi").subPath(2, 4))
}
test fun normalize() {
@test fun normalize() {
assertEquals(File("/foo/bar/baaz"), File("/foo/./bar/gav/../baaz").normalize())
assertEquals(File("/foo/bar/baaz"), File("/foo/bak/../bar/gav/../baaz").normalize())
assertEquals(File("../../bar"), File("../foo/../../bar").normalize())
@@ -674,7 +674,7 @@ class FilesTest {
assertEquals(File("foo"), File("gav/bar/../../foo").normalize())
}
test fun resolve() {
@test fun resolve() {
assertEquals(File("/foo/bar/gav"), File("/foo/bar").resolve("gav"))
assertEquals(File("/foo/bar/gav"), File("/foo/bar/").resolve("gav"))
assertEquals(File("/gav"), File("/foo/bar").resolve("/gav"))
@@ -685,7 +685,7 @@ class FilesTest {
File("C:/Users/Me").resolve("Documents/important.doc"))
}
test fun resolveSibling() {
@test fun resolveSibling() {
assertEquals(File("/foo/gav"), File("/foo/bar").resolveSibling("gav"))
assertEquals(File("/foo/gav"), File("/foo/bar/").resolveSibling("gav"))
assertEquals(File("/gav"), File("/foo/bar").resolveSibling("/gav"))
@@ -696,7 +696,7 @@ class FilesTest {
File("C:/Users/Me/profile.ini").resolveSibling("Documents/important.doc"))
}
test fun extension() {
@test fun extension() {
assertEquals("bbb", File("aaa.bbb").extension)
assertEquals("", File("aaa").extension)
assertEquals("", File("aaa.").extension)
@@ -705,7 +705,7 @@ class FilesTest {
assertEquals("", File("/my.dir/log").extension)
}
test fun nameWithoutExtension() {
@test fun nameWithoutExtension() {
assertEquals("aaa", File("aaa.bbb").nameWithoutExtension)
assertEquals("aaa", File("aaa").nameWithoutExtension)
assertEquals("aaa", File("aaa.").nameWithoutExtension)
@@ -713,7 +713,7 @@ class FilesTest {
assertEquals("log", File("/my.dir/log").nameWithoutExtension)
}
test fun separatorsToSystem() {
@test fun separatorsToSystem() {
var path = "/aaa/bbb/ccc"
assertEquals(path.replace("/", File.separator), File(path).separatorsToSystem())
@@ -733,7 +733,7 @@ class FilesTest {
assertEquals("test", "test".allSeparatorsToSystem())
}
test fun testCopyTo() {
@test fun testCopyTo() {
val srcFile = createTempFile()
val dstFile = createTempFile()
srcFile.writeText("Hello, World!", "UTF8")
@@ -780,7 +780,7 @@ class FilesTest {
srcFile.delete()
}
test fun copyToNameWithoutParent() {
@test fun copyToNameWithoutParent() {
val currentDir = File("").getAbsoluteFile()!!
val srcFile = createTempFile()
val dstFile = createTempFile(directory = currentDir)
@@ -800,7 +800,7 @@ class FilesTest {
}
}
test fun deleteRecursively() {
@test fun deleteRecursively() {
val dir = createTempDir()
dir.delete()
dir.mkdir()
@@ -814,7 +814,7 @@ class FilesTest {
assert(!dir.deleteRecursively())
}
test fun deleteRecursivelyWithFail() {
@test fun deleteRecursivelyWithFail() {
val basedir = Walks.createTestFiles()
val restricted = File(basedir, "1")
try {
@@ -837,7 +837,7 @@ class FilesTest {
}
}
test fun copyRecursively() {
@test fun copyRecursively() {
val src = createTempDir()
val dst = createTempDir()
dst.delete()
@@ -921,7 +921,7 @@ class FilesTest {
}
}
test fun helpers1() {
@test fun helpers1() {
val str = "123456789\n"
System.setIn(str.byteInputStream())
val reader = System.`in`.bufferedReader()
@@ -932,7 +932,7 @@ class FilesTest {
assertEquals('3', stringReader.read().toChar())
}
test fun helpers2() {
@test fun helpers2() {
val file = createTempFile()
val writer = file.printWriter()
val str1 = "Hello, world!"
+1 -1
View File
@@ -7,7 +7,7 @@ import java.io.BufferedReader
import java.io.File
class IOStreamsTest {
test fun testGetStreamOfFile() {
@test fun testGetStreamOfFile() {
val tmpFile = createTempFile()
var writer: Writer? = null
try {
+8 -8
View File
@@ -13,7 +13,7 @@ import kotlin.test.assertTrue
fun sample(): Reader = StringReader("Hello\nWorld");
class ReadWriteTest {
test fun testAppendText() {
@test fun testAppendText() {
val file = File.createTempFile("temp", System.nanoTime().toString())
file.writeText("Hello\n", "UTF8")
file.appendText("World\n", "UTF8")
@@ -24,7 +24,7 @@ class ReadWriteTest {
file.deleteOnExit()
}
test fun reader() {
@test fun reader() {
val list = ArrayList<String>()
/* TODO would be nicer maybe to write this as
@@ -63,7 +63,7 @@ class ReadWriteTest {
assertEquals(2, c)
}
test fun file() {
@test fun file() {
val file = File.createTempFile("temp", System.nanoTime().toString())
val writer = file.outputStream().writer().buffered()
@@ -109,7 +109,7 @@ class ReadWriteTest {
}
class LineIteratorTest {
test fun useLines() {
@test fun useLines() {
// TODO we should maybe zap the useLines approach as it encourages
// use of iterators which don't close the underlying stream
val list1 = sample().useLines { it.toArrayList() }
@@ -119,7 +119,7 @@ class ReadWriteTest {
assertEquals(arrayListOf("Hello", "World"), list2)
}
test fun manualClose() {
@test fun manualClose() {
val reader = sample().buffered()
try {
val list = reader.lineSequence().toArrayList()
@@ -129,7 +129,7 @@ class ReadWriteTest {
}
}
test fun boundaryConditions() {
@test fun boundaryConditions() {
var reader = StringReader("").buffered()
assertEquals(ArrayList<String>(), reader.lineSequence().toArrayList())
reader.close()
@@ -148,7 +148,7 @@ class ReadWriteTest {
}
}
test fun testUse() {
@test fun testUse() {
val list = ArrayList<String>()
val reader = sample().buffered()
@@ -165,7 +165,7 @@ class ReadWriteTest {
assertEquals(arrayListOf("Hello", "World"), list)
}
test fun testURL() {
@test fun testURL() {
val url = URL("http://kotlinlang.org")
val text = url.readText()
assertFalse(text.isEmpty())
@@ -7,7 +7,8 @@ import org.junit.Test
class FunctionIteratorTest {
Test fun iterateOverFunction() {
@Test
fun iterateOverFunction() {
var count = 3
val iter = sequence<Int> {
@@ -19,7 +20,8 @@ class FunctionIteratorTest {
assertEquals(arrayListOf(2, 1, 0), list)
}
Test fun iterateOverFunction2() {
@Test
fun iterateOverFunction2() {
val values = sequence<Int>(3) { n -> if (n > 0) n - 1 else null }
assertEquals(arrayListOf(3, 2, 1, 0), values.toList())
}
@@ -6,7 +6,7 @@ import org.junit.Test as test
class IteratorsJVMTest {
test fun flatMapAndTakeExtractTheTransformedElements() {
@test fun flatMapAndTakeExtractTheTransformedElements() {
fun intToBinaryDigits() = { i: Int ->
val binary = Integer.toBinaryString(i)!!
var index = 0
@@ -25,7 +25,7 @@ class IteratorsJVMTest {
assertEquals(expected, fibonacci().flatMap<Int, Char>(intToBinaryDigits()).take(10).toList())
}
test fun flatMapOnIterator() {
@test fun flatMapOnIterator() {
val result = sequenceOf(1, 2).flatMap { i -> (0..i).asSequence()}
assertEquals(listOf(0, 1, 0, 1, 2), result.toList())
}
@@ -13,32 +13,32 @@ fun fibonacci(): Sequence<Int> {
class IteratorsTest {
test fun filterAndTakeWhileExtractTheElementsWithinRange() {
@test fun filterAndTakeWhileExtractTheElementsWithinRange() {
assertEquals(arrayListOf(144, 233, 377, 610, 987), fibonacci().filter { it > 100 }.takeWhile { it < 1000 }.toList())
}
test fun foldReducesTheFirstNElements() {
@test fun foldReducesTheFirstNElements() {
val sum = { a: Int, b: Int -> a + b }
assertEquals(arrayListOf(13, 21, 34, 55, 89).fold(0, sum), fibonacci().filter { it > 10 }.take(5).fold(0, sum))
}
test fun takeExtractsTheFirstNElements() {
@test fun takeExtractsTheFirstNElements() {
assertEquals(arrayListOf(0, 1, 1, 2, 3, 5, 8, 13, 21, 34), fibonacci().take(10).toList())
}
test fun mapAndTakeWhileExtractTheTransformedElements() {
@test fun mapAndTakeWhileExtractTheTransformedElements() {
assertEquals(arrayListOf(0, 3, 3, 6, 9, 15), fibonacci().map { it * 3 }.takeWhile { i: Int -> i < 20 }.toList())
}
test fun mapIndexed() {
@test fun mapIndexed() {
assertEquals(arrayListOf(0, 1, 2, 6, 12), fibonacci().mapIndexed { index, value -> index * value }.takeWhile { i: Int -> i < 20 }.toList())
}
test fun joinConcatenatesTheFirstNElementsAboveAThreshold() {
@test fun joinConcatenatesTheFirstNElementsAboveAThreshold() {
assertEquals("13, 21, 34, 55, 89, ...", fibonacci().filter { it > 10 }.joinToString(separator = ", ", limit = 5))
}
test fun plus() {
@test fun plus() {
val iter = arrayListOf("foo", "bar").asSequence()
val iter2 = iter + "cheese"
assertEquals(arrayListOf("foo", "bar", "cheese"), iter2.toList())
@@ -49,7 +49,7 @@ class IteratorsTest {
assertEquals(arrayListOf("a", "b", "c"), mi.toList())
}
test fun plusCollection() {
@test fun plusCollection() {
val a = arrayListOf("foo", "bar")
val b = arrayListOf("cheese", "wine")
val iter = a.asSequence() + b.asSequence()
@@ -64,7 +64,7 @@ class IteratorsTest {
assertEquals(arrayListOf("a", "foo", "bar", "beer", "cheese", "wine", "z"), ml.toList())
}
test fun requireNoNulls() {
@test fun requireNoNulls() {
val iter = arrayListOf<String?>("foo", "bar").asSequence()
val notNull = iter.requireNoNulls()
assertEquals(arrayListOf("foo", "bar"), notNull.toList())
@@ -77,23 +77,23 @@ class IteratorsTest {
}
}
test fun toStringJoinsNoMoreThanTheFirstTenElements() {
@test fun toStringJoinsNoMoreThanTheFirstTenElements() {
assertEquals("0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...", fibonacci().joinToString(limit = 10))
assertEquals("13, 21, 34, 55, 89, 144, 233, 377, 610, 987, ...", fibonacci().filter { it > 10 }.joinToString(limit = 10))
assertEquals("144, 233, 377, 610, 987", fibonacci().filter { it > 100 }.takeWhile { it < 1000 }.joinToString())
}
test fun pairIterator() {
@test fun pairIterator() {
val pairStr = (fibonacci() zip fibonacci().map { i -> i*2 }).joinToString(limit = 10)
assertEquals("(0, 0), (1, 2), (1, 2), (2, 4), (3, 6), (5, 10), (8, 16), (13, 26), (21, 42), (34, 68), ...", pairStr)
}
test fun skippingIterator() {
@test fun skippingIterator() {
assertEquals("13, 21, 34, 55, 89, 144, 233, 377, 610, 987, ...", fibonacci().drop(7).joinToString(limit = 10))
assertEquals("13, 21, 34, 55, 89, 144, 233, 377, 610, 987, ...", fibonacci().drop(3).drop(4).joinToString(limit = 10))
}
test fun iterationOverIterator() {
@test fun iterationOverIterator() {
val c = arrayListOf(0, 1, 2, 3, 4, 5)
var s = ""
for (i in c.iterator()) {
@@ -107,7 +107,7 @@ class IteratorsTest {
return result
}
test fun iterableExtension() {
@test fun iterableExtension() {
val c = arrayListOf(0, 1, 2, 3, 4, 5)
val d = ArrayList<Int>()
c.iterator().takeWhileTo(d, {i -> i < 4 })
+2 -2
View File
@@ -6,7 +6,7 @@ import java.util.ArrayList;
class JsArrayTest {
test fun arraySizeAndToList() {
@test fun arraySizeAndToList() {
val a1 = arrayOf<String>()
val a2 = arrayOf("foo")
val a3 = arrayOf("foo", "bar")
@@ -21,7 +21,7 @@ class JsArrayTest {
}
test fun arrayListFromCollection() {
@test fun arrayListFromCollection() {
var c: Collection<String> = arrayOf("A", "B", "C").toList()
var a = ArrayList(c)
+12 -12
View File
@@ -9,7 +9,7 @@ import org.junit.Test as test
class JsDomTest {
test fun testCreateDocument() {
@test fun testCreateDocument() {
var doc = document
assertNotNull(doc, "Should have created a document")
@@ -25,7 +25,7 @@ class JsDomTest {
assertCssClass(e, "bar")
}
test fun addText() {
@test fun addText() {
var doc = document
assertNotNull(doc, "Should have created a document")
@@ -38,7 +38,7 @@ class JsDomTest {
assertEquals("hello", e.textContent)
}
test fun testAddClassMissing() {
@test fun testAddClassMissing() {
val e = document.createElement("e")!!
assertNotNull(e)
@@ -49,7 +49,7 @@ class JsDomTest {
assertEquals("class1 class2", e.classes)
}
test fun testAddClassPresent() {
@test fun testAddClassPresent() {
val e = document.createElement("e")!!
assertNotNull(e)
@@ -60,13 +60,13 @@ class JsDomTest {
assertEquals("class2 class1", e.classes)
}
test fun testAddClassUndefinedClasses() {
@test fun testAddClassUndefinedClasses() {
val e = document.createElement("e")!!
e.addClass("class1")
assertEquals("class1", e.classes)
}
test fun testRemoveClassMissing() {
@test fun testRemoveClassMissing() {
val e = document.createElement("e")!!
assertNotNull(e)
@@ -77,7 +77,7 @@ class JsDomTest {
assertEquals("class2 class1", e.classes)
}
test fun testRemoveClassPresent1() {
@test fun testRemoveClassPresent1() {
val e = document.createElement("e")!!
assertNotNull(e)
@@ -88,7 +88,7 @@ class JsDomTest {
assertEquals("class1", e.classes)
}
test fun testRemoveClassPresent2() {
@test fun testRemoveClassPresent2() {
val e = document.createElement("e")!!
assertNotNull(e)
@@ -99,7 +99,7 @@ class JsDomTest {
assertEquals("class2", e.classes)
}
test fun testRemoveClassPresent3() {
@test fun testRemoveClassPresent3() {
val e = document.createElement("e")!!
assertNotNull(e)
@@ -110,13 +110,13 @@ class JsDomTest {
assertEquals("class2 class3", e.classes)
}
test fun testRemoveClassUndefinedClasses() {
@test fun testRemoveClassUndefinedClasses() {
val e = document.createElement("e")!!
e.removeClass("class1")
assertEquals("", e.classes)
}
test fun testRemoveFromParent() {
@test fun testRemoveFromParent() {
val doc = document
val parent = doc.createElement("pp")
@@ -135,7 +135,7 @@ class JsDomTest {
assertNull(child.parentNode)
}
test fun testRemoveFromParentOrphanNode() {
@test fun testRemoveFromParentOrphanNode() {
val child = document.createElement("cc")
child.removeFromParent()
+31 -31
View File
@@ -17,7 +17,7 @@ class ComplexMapJsTest : MapJsTest() {
assertEquals(KEYS.toNormalizedList(), map.keySet().toNormalizedList())
assertEquals(VALUES.toNormalizedList(), map.values().toNormalizedList())
}
test override fun constructors() {
@test override fun constructors() {
doTest<String>()
}
@@ -28,7 +28,7 @@ class ComplexMapJsTest : MapJsTest() {
}
class PrimitiveMapJsTest : MapJsTest() {
test override fun constructors() {
@test override fun constructors() {
HashMap<String, Int>()
HashMap<String, Int>(3)
HashMap<String, Int>(3, 0.5f)
@@ -43,7 +43,7 @@ class PrimitiveMapJsTest : MapJsTest() {
override fun emptyMutableMap(): MutableMap<String, Int> = HashMap()
override fun emptyMutableMapWithNullableKeyValue(): MutableMap<String?, Int?> = HashMap()
test fun compareBehavior() {
@test fun compareBehavior() {
val specialJsStringMap = HashMap<String, Any>()
specialJsStringMap.put("k1", "v1")
compare(genericHashMapOf("k1" to "v1"), specialJsStringMap) { mapBehavior() }
@@ -55,7 +55,7 @@ class PrimitiveMapJsTest : MapJsTest() {
}
class LinkedHashMapTest : MapJsTest() {
test override fun constructors() {
@test override fun constructors() {
LinkedHashMap<String, Int>()
LinkedHashMap<String, Int>(3)
LinkedHashMap<String, Int>(3, 0.5f)
@@ -77,7 +77,7 @@ abstract class MapJsTest {
val SPECIAL_NAMES = arrayOf("__proto__", "constructor", "toString", "toLocaleString", "valueOf", "hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable")
test fun getOrElse() {
@test fun getOrElse() {
val data = emptyMap()
val a = data.getOrElse("foo"){2}
assertEquals(2, a)
@@ -87,7 +87,7 @@ abstract class MapJsTest {
assertEquals(0, data.size())
}
test fun getOrPut() {
@test fun getOrPut() {
val data = emptyMutableMap()
val a = data.getOrPut("foo"){2}
assertEquals(2, a)
@@ -98,13 +98,13 @@ abstract class MapJsTest {
assertEquals(1, data.size())
}
test fun emptyMapGet() {
@test fun emptyMapGet() {
val map = emptyMap()
assertEquals(null, map.get("foo"), """failed on map.get("foo")""")
assertEquals(null, map["bar"], """failed on map["bar"]""")
}
test fun mapGet() {
@test fun mapGet() {
val map = createTestMap()
for (i in KEYS.indices) {
assertEquals(VALUES[i], map.get(KEYS[i]), """failed on map.get(KEYS[$i])""")
@@ -114,7 +114,7 @@ abstract class MapJsTest {
assertEquals(null, map.get("foo"))
}
test fun mapPut() {
@test fun mapPut() {
val map = emptyMutableMap()
map.put("foo", 1)
@@ -130,7 +130,7 @@ abstract class MapJsTest {
assertEquals(2, map["bar"])
}
test fun sizeAndEmptyForEmptyMap() {
@test fun sizeAndEmptyForEmptyMap() {
val data = emptyMap()
assertTrue(data.isEmpty())
@@ -140,7 +140,7 @@ abstract class MapJsTest {
assertEquals(0, data.size())
}
test fun sizeAndEmpty() {
@test fun sizeAndEmpty() {
val data = createTestMap()
assertFalse(data.isEmpty())
@@ -150,22 +150,22 @@ abstract class MapJsTest {
}
// #KT-3035
test fun emptyMapValues() {
@test fun emptyMapValues() {
val emptyMap = emptyMap()
assertTrue(emptyMap.values().isEmpty())
}
test fun mapValues() {
@test fun mapValues() {
val map = createTestMap()
assertEquals(VALUES.toNormalizedList(), map.values().toNormalizedList())
}
test fun mapKeySet() {
@test fun mapKeySet() {
val map = createTestMap()
assertEquals(KEYS.toNormalizedList(), map.keySet().toNormalizedList())
}
test fun mapEntrySet() {
@test fun mapEntrySet() {
val map = createTestMap()
val actualKeys = ArrayList<String>()
@@ -179,7 +179,7 @@ abstract class MapJsTest {
assertEquals(VALUES.toNormalizedList(), actualValues.toNormalizedList())
}
test fun mapContainsKey() {
@test fun mapContainsKey() {
val map = createTestMap()
assertTrue(map.containsKey(KEYS[0]) &&
@@ -191,7 +191,7 @@ abstract class MapJsTest {
map.containsKey(1))
}
test fun mapContainsValue() {
@test fun mapContainsValue() {
val map = createTestMap()
assertTrue(map.containsValue(VALUES[0]) &&
@@ -203,14 +203,14 @@ abstract class MapJsTest {
map.containsValue(5))
}
test fun mapPutAll() {
@test fun mapPutAll() {
val map = createTestMap()
val newMap = emptyMutableMap()
newMap.putAll(map)
assertEquals(KEYS.size(), newMap.size())
}
test fun mapRemove() {
@test fun mapRemove() {
val map = createTestMutableMap()
val last = KEYS.size() - 1
val first = 0
@@ -227,14 +227,14 @@ abstract class MapJsTest {
assertEquals(KEYS.size() - 3, map.size())
}
test fun mapClear() {
@test fun mapClear() {
val map = createTestMutableMap()
assertFalse(map.isEmpty())
map.clear()
assertTrue(map.isEmpty())
}
test fun nullAsKey() {
@test fun nullAsKey() {
val map = emptyMutableMapWithNullableKeyValue()
assertTrue(map.isEmpty())
@@ -247,7 +247,7 @@ abstract class MapJsTest {
assertEquals(null, map[null])
}
test fun nullAsValue() {
@test fun nullAsValue() {
val map = emptyMutableMapWithNullableKeyValue()
val KEY = "Key"
@@ -260,7 +260,7 @@ abstract class MapJsTest {
assertTrue(map.isEmpty())
}
test fun setViaIndexOperators() {
@test fun setViaIndexOperators() {
val map = HashMap<String, String>()
assertTrue{ map.isEmpty() }
assertEquals(map.size(), 0)
@@ -272,21 +272,21 @@ abstract class MapJsTest {
assertEquals("James", map["name"])
}
test fun createUsingPairs() {
@test fun createUsingPairs() {
val map = mapOf(Pair("a", 1), Pair("b", 2))
assertEquals(2, map.size())
assertEquals(1, map.get("a"))
assertEquals(2, map.get("b"))
}
test fun createUsingTo() {
@test fun createUsingTo() {
val map = mapOf("a" to 1, "b" to 2)
assertEquals(2, map.size())
assertEquals(1, map.get("a"))
assertEquals(2, map.get("b"))
}
test fun mapIteratorImplicitly() {
@test fun mapIteratorImplicitly() {
val map = createTestMap()
val actualKeys = ArrayList<String>()
@@ -300,7 +300,7 @@ abstract class MapJsTest {
assertEquals(VALUES.toNormalizedList(), actualValues.toNormalizedList())
}
test fun mapIteratorExplicitly() {
@test fun mapIteratorExplicitly() {
val map = createTestMap()
val actualKeys = ArrayList<String>()
@@ -315,7 +315,7 @@ abstract class MapJsTest {
assertEquals(VALUES.toNormalizedList(), actualValues.toNormalizedList())
}
test fun specialNamesNotContainsInEmptyMap() {
@test fun specialNamesNotContainsInEmptyMap() {
val map = emptyMap()
for (key in SPECIAL_NAMES) {
@@ -323,7 +323,7 @@ abstract class MapJsTest {
}
}
test fun specialNamesNotContainsInNonEmptyMap() {
@test fun specialNamesNotContainsInNonEmptyMap() {
val map = createTestMap()
for (key in SPECIAL_NAMES) {
@@ -331,7 +331,7 @@ abstract class MapJsTest {
}
}
test fun putAndGetSpecialNamesToMap() {
@test fun putAndGetSpecialNamesToMap() {
val map = createTestMutableMap()
var value = 0
@@ -351,7 +351,7 @@ abstract class MapJsTest {
}
}
test abstract fun constructors()
@test abstract fun constructors()
/*
test fun createLinkedMap() {
+40 -20
View File
@@ -18,7 +18,8 @@ class ComplexSetJsTest : SetJsTest() {
assertEquals(data, set)
}
Test override fun constructors() {
@Test
override fun constructors() {
doTest<String>()
}
@@ -32,7 +33,8 @@ class ComplexSetJsTest : SetJsTest() {
class PrimitiveSetJsTest : SetJsTest() {
override fun createEmptyMutableSet(): MutableSet<String> = HashSet()
override fun createEmptyMutableSetWithNullableValues(): MutableSet<String?> = HashSet()
Test override fun constructors() {
@Test
override fun constructors() {
HashSet<String>()
HashSet<String>(3)
HashSet<String>(3, 0.5f)
@@ -42,7 +44,8 @@ class PrimitiveSetJsTest : SetJsTest() {
assertEquals(data, set)
}
Test fun compareBehavior() {
@Test
fun compareBehavior() {
val specialJsStringSet = HashSet<String>()
specialJsStringSet.add("kotlin")
compare(genericHashSetOf("kotlin"), specialJsStringSet) { setBehavior() }
@@ -57,7 +60,8 @@ class PrimitiveSetJsTest : SetJsTest() {
class LinkedHashSetJsTest : SetJsTest() {
override fun createEmptyMutableSet(): MutableSet<String> = LinkedHashSet()
override fun createEmptyMutableSetWithNullableValues(): MutableSet<String?> = LinkedHashSet()
Test override fun constructors() {
@Test
override fun constructors() {
LinkedHashSet<String>()
LinkedHashSet<String>(3)
LinkedHashSet<String>(3, 0.5f)
@@ -74,24 +78,28 @@ abstract class SetJsTest {
val SPECIAL_NAMES = arrayOf("__proto__", "constructor", "toString", "toLocaleString", "valueOf", "hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable")
Test fun size() {
@Test
fun size() {
assertEquals(2, data.size())
assertEquals(0, empty.size())
}
Test fun isEmpty() {
@Test
fun isEmpty() {
assertFalse(data.isEmpty())
assertTrue(empty.isEmpty())
}
Test fun equals() {
@Test
fun equals() {
assertNotEquals(createEmptyMutableSet(), data)
assertNotEquals(data, empty)
assertEquals(createEmptyMutableSet(), empty)
assertEquals(createTestMutableSetReversed(), data)
}
Test fun contains() {
@Test
fun contains() {
assertTrue(data.contains("foo"))
assertTrue(data.contains("bar"))
assertFalse(data.contains("baz"))
@@ -102,7 +110,8 @@ abstract class SetJsTest {
assertFalse(empty.contains(1))
}
Test fun iterator() {
@Test
fun iterator() {
var result = ""
for (e in data) {
result += e
@@ -111,14 +120,16 @@ abstract class SetJsTest {
assertTrue(result == "foobar" || result == "barfoo")
}
Test fun containsAll() {
@Test
fun containsAll() {
assertTrue(data.containsAll(arrayListOf("foo", "bar")))
assertTrue(data.containsAll(arrayListOf<String>()))
assertFalse(data.containsAll(arrayListOf("foo", "bar", "baz")))
assertFalse(data.containsAll(arrayListOf("baz")))
}
Test fun add() {
@Test
fun add() {
val data = createTestMutableSet()
assertTrue(data.add("baz"))
assertEquals(3, data.size())
@@ -127,7 +138,8 @@ abstract class SetJsTest {
assertTrue(data.containsAll(arrayListOf("foo", "bar", "baz")))
}
Test fun remove() {
@Test
fun remove() {
val data = createTestMutableSet()
assertTrue(data.remove("foo"))
assertEquals(1, data.size())
@@ -136,7 +148,8 @@ abstract class SetJsTest {
assertTrue(data.contains("bar"))
}
Test fun addAll() {
@Test
fun addAll() {
val data = createTestMutableSet()
assertTrue(data.addAll(arrayListOf("foo", "bar", "baz", "boo")))
assertEquals(4, data.size())
@@ -145,7 +158,8 @@ abstract class SetJsTest {
assertTrue(data.containsAll(arrayListOf("foo", "bar", "baz", "boo")))
}
Test fun removeAll() {
@Test
fun removeAll() {
val data = createTestMutableSet()
assertFalse(data.removeAll(arrayListOf("baz")))
assertTrue(data.containsAll(arrayListOf("foo", "bar")))
@@ -161,7 +175,8 @@ abstract class SetJsTest {
assertTrue(data.isEmpty())
}
Test fun retainAll() {
@Test
fun retainAll() {
val data1 = createTestMutableSet()
assertTrue(data1.retainAll(arrayListOf("baz")))
assertTrue(data1.isEmpty())
@@ -172,7 +187,8 @@ abstract class SetJsTest {
assertEquals(1, data2.size())
}
Test fun clear() {
@Test
fun clear() {
val data = createTestMutableSet()
data.clear()
assertTrue(data.isEmpty())
@@ -181,19 +197,22 @@ abstract class SetJsTest {
assertTrue(data.isEmpty())
}
Test fun specialNamesNotContainsInEmptySet() {
@Test
fun specialNamesNotContainsInEmptySet() {
for (element in SPECIAL_NAMES) {
assertFalse(empty.contains(element), "unexpected element: $element")
}
}
Test fun specialNamesNotContainsInNonEmptySet() {
@Test
fun specialNamesNotContainsInNonEmptySet() {
for (element in SPECIAL_NAMES) {
assertFalse(data.contains(element), "unexpected element: $element")
}
}
Test fun putAndGetSpecialNamesToSet() {
@Test
fun putAndGetSpecialNamesToSet() {
val s = createTestMutableSet()
for (element in SPECIAL_NAMES) {
@@ -209,7 +228,8 @@ abstract class SetJsTest {
abstract fun constructors()
Test fun nullAsValue() {
@Test
fun nullAsValue() {
val set = createEmptyMutableSetWithNullableValues()
assertTrue(set.isEmpty(), "Set should be empty")
+1 -1
View File
@@ -11,7 +11,7 @@ class SimpleTest {
assertEquals("hello world!", message)
}
test fun cheese() {
@test fun cheese() {
val name = "world"
val message = "bye $name!"
assertEquals("bye world!", message)
@@ -14,23 +14,23 @@ class JavautilCollectionsTest {
val MAX_ELEMENT = 9
val COMPARATOR = comparator { x: Int, y: Int -> if (x > y) 1 else if (x < y) -1 else 0 }
test fun maxWithComparator() {
@test fun maxWithComparator() {
assertEquals(MAX_ELEMENT, Collections.max(TEST_LIST, COMPARATOR))
}
test fun sort() {
@test fun sort() {
val list = TEST_LIST.toArrayList()
Collections.sort(list)
assertEquals(SORTED_TEST_LIST, list)
}
test fun sortWithComparator() {
@test fun sortWithComparator() {
val list = TEST_LIST.toArrayList()
Collections.sort(list, COMPARATOR)
assertEquals(SORTED_TEST_LIST, list)
}
test fun collectionToArray() {
@test fun collectionToArray() {
val array = TEST_LIST.toTypedArray()
assertEquals(array.toList(), TEST_LIST)
}
@@ -4,31 +4,31 @@ import kotlin.test.*
import org.junit.Test as test
class BitwiseOperationsTest {
test fun orForInt() {
@test fun orForInt() {
assertEquals(3, 2 or 1)
}
test fun andForInt() {
@test fun andForInt() {
assertEquals(0, 1 and 0)
}
test fun xorForInt() {
@test fun xorForInt() {
assertEquals(1, 2 xor 3)
}
test fun shlForInt() {
@test fun shlForInt() {
assertEquals(4, 1 shl 2)
}
test fun shrForInt() {
@test fun shrForInt() {
assertEquals(1, 2 shr 1)
}
test fun ushrForInt() {
@test fun ushrForInt() {
assertEquals(2147483647, -1 ushr 1)
}
test fun invForInt() {
@test fun invForInt() {
assertEquals(0, (-1).inv())
}
}
@@ -34,7 +34,7 @@ public class RangeIterationJVMTest {
assertEquals(expectedElements, sequence.toList())
}
test fun infiniteSteps() {
@test fun infiniteSteps() {
doTest(0.0..5.0 step j.Double.POSITIVE_INFINITY, 0.0, 5.0, j.Double.POSITIVE_INFINITY, listOf(0.0))
doTest(0.0.toFloat()..5.0.toFloat() step j.Float.POSITIVE_INFINITY, 0.0.toFloat(), 5.0.toFloat(), j.Float.POSITIVE_INFINITY,
listOf<Float>(0.0.toFloat()))
@@ -43,7 +43,7 @@ public class RangeIterationJVMTest {
listOf<Float>(5.0.toFloat()))
}
test fun nanEnds() {
@test fun nanEnds() {
doTest(j.Double.NaN..5.0, j.Double.NaN, 5.0, 1.0, listOf())
doTest(j.Float.NaN.toFloat()..5.0.toFloat(), j.Float.NaN, 5.0.toFloat(), 1.0.toFloat(), listOf())
doTest(j.Double.NaN downTo 0.0, j.Double.NaN, 0.0, -1.0, listOf())
@@ -60,7 +60,7 @@ public class RangeIterationJVMTest {
doTest(j.Float.NaN downTo j.Float.NaN, j.Float.NaN, j.Float.NaN, -1.0.toFloat(), listOf())
}
test fun maxValueToMaxValue() {
@test fun maxValueToMaxValue() {
doTest(MaxI..MaxI, MaxI, MaxI, 1, listOf(MaxI))
doTest(MaxB..MaxB, MaxB, MaxB, 1, listOf(MaxB))
doTest(MaxS..MaxS, MaxS, MaxS, 1, listOf(MaxS))
@@ -69,7 +69,7 @@ public class RangeIterationJVMTest {
doTest(MaxC..MaxC, MaxC, MaxC, 1, listOf(MaxC))
}
test fun maxValueMinusTwoToMaxValue() {
@test fun maxValueMinusTwoToMaxValue() {
doTest((MaxI - 2)..MaxI, MaxI - 2, MaxI, 1, listOf(MaxI - 2, MaxI - 1, MaxI))
doTest((MaxB - 2).toByte()..MaxB, (MaxB - 2).toByte(), MaxB, 1, listOf((MaxB - 2).toByte(), (MaxB - 1).toByte(), MaxB))
doTest((MaxS - 2).toShort()..MaxS, (MaxS - 2).toShort(), MaxS, 1, listOf((MaxS - 2).toShort(), (MaxS - 1).toShort(), MaxS))
@@ -78,7 +78,7 @@ public class RangeIterationJVMTest {
doTest((MaxC - 2)..MaxC, (MaxC - 2), MaxC, 1, listOf((MaxC - 2), (MaxC - 1), MaxC))
}
test fun maxValueToMinValue() {
@test fun maxValueToMinValue() {
doTest(MaxI..MinI, MaxI, MinI, 1, listOf())
doTest(MaxB..MinB, MaxB, MinB, 1, listOf())
doTest(MaxS..MinS, MaxS, MinS, 1, listOf())
@@ -87,7 +87,7 @@ public class RangeIterationJVMTest {
doTest(MaxC..MinC, MaxC, MinC, 1, listOf())
}
test fun progressionMaxValueToMaxValue() {
@test fun progressionMaxValueToMaxValue() {
doTest(MaxI..MaxI step 1, MaxI, MaxI, 1, listOf(MaxI))
doTest(MaxB..MaxB step 1, MaxB, MaxB, 1, listOf(MaxB))
doTest(MaxS..MaxS step 1, MaxS, MaxS, 1, listOf(MaxS))
@@ -96,7 +96,7 @@ public class RangeIterationJVMTest {
doTest(MaxC..MaxC step 1, MaxC, MaxC, 1, listOf(MaxC))
}
test fun progressionMaxValueMinusTwoToMaxValue() {
@test fun progressionMaxValueMinusTwoToMaxValue() {
doTest((MaxI - 2)..MaxI step 2, MaxI - 2, MaxI, 2, listOf(MaxI - 2, MaxI))
doTest((MaxB - 2).toByte()..MaxB step 2, (MaxB - 2).toByte(), MaxB, 2, listOf((MaxB - 2).toByte(), MaxB))
doTest((MaxS - 2).toShort()..MaxS step 2, (MaxS - 2).toShort(), MaxS, 2, listOf((MaxS - 2).toShort(), MaxS))
@@ -105,7 +105,7 @@ public class RangeIterationJVMTest {
doTest((MaxC - 2)..MaxC step 2, (MaxC - 2), MaxC, 2, listOf((MaxC - 2), MaxC))
}
test fun progressionMaxValueToMinValue() {
@test fun progressionMaxValueToMinValue() {
doTest(MaxI..MinI step 1, MaxI, MinI, 1, listOf())
doTest(MaxB..MinB step 1, MaxB, MinB, 1, listOf())
doTest(MaxS..MinS step 1, MaxS, MinS, 1, listOf())
@@ -114,7 +114,7 @@ public class RangeIterationJVMTest {
doTest(MaxC..MinC step 1, MaxC, MinC, 1, listOf())
}
test fun progressionMinValueToMinValue() {
@test fun progressionMinValueToMinValue() {
doTest(MinI..MinI step 1, MinI, MinI, 1, listOf(MinI))
doTest(MinB..MinB step 1, MinB, MinB, 1, listOf(MinB))
doTest(MinS..MinS step 1, MinS, MinS, 1, listOf(MinS))
@@ -123,7 +123,7 @@ public class RangeIterationJVMTest {
doTest(MinC..MinC step 1, MinC, MinC, 1, listOf(MinC))
}
test fun inexactToMaxValue() {
@test fun inexactToMaxValue() {
doTest((MaxI - 5)..MaxI step 3, MaxI - 5, MaxI, 3, listOf(MaxI - 5, MaxI - 2))
doTest((MaxB - 5).toByte()..MaxB step 3, (MaxB - 5).toByte(), MaxB, 3, listOf((MaxB - 5).toByte(), (MaxB - 2).toByte()))
doTest((MaxS - 5).toShort()..MaxS step 3, (MaxS - 5).toShort(), MaxS, 3, listOf((MaxS - 5).toShort(), (MaxS - 2).toShort()))
@@ -132,7 +132,7 @@ public class RangeIterationJVMTest {
doTest((MaxC - 5)..MaxC step 3, (MaxC - 5), MaxC, 3, listOf((MaxC - 5), (MaxC - 2)))
}
test fun progressionDownToMinValue() {
@test fun progressionDownToMinValue() {
doTest((MinI + 2) downTo MinI step 1, MinI + 2, MinI, -1, listOf(MinI + 2, MinI + 1, MinI))
doTest((MinB + 2).toByte() downTo MinB step 1, (MinB + 2).toByte(), MinB, -1, listOf((MinB + 2).toByte(), (MinB + 1).toByte(), MinB))
doTest((MinS + 2).toShort() downTo MinS step 1, (MinS + 2).toShort(), MinS, -1, listOf((MinS + 2).toShort(), (MinS + 1).toShort(), MinS))
@@ -141,7 +141,7 @@ public class RangeIterationJVMTest {
doTest((MinC + 2) downTo MinC step 1, (MinC + 2), MinC, -1, listOf((MinC + 2), (MinC + 1), MinC))
}
test fun inexactDownToMinValue() {
@test fun inexactDownToMinValue() {
doTest((MinI + 5) downTo MinI step 3, MinI + 5, MinI, -3, listOf(MinI + 5, MinI + 2))
doTest((MinB + 5).toByte() downTo MinB step 3, (MinB + 5).toByte(), MinB, -3, listOf((MinB + 5).toByte(), (MinB + 2).toByte()))
doTest((MinS + 5).toShort() downTo MinS step 3, (MinS + 5).toShort(), MinS, -3, listOf((MinS + 5).toShort(), (MinS + 2).toShort()))
@@ -22,7 +22,7 @@ public class RangeIterationTest {
assertEquals(expectedElements, sequence.toList())
}
test fun emptyConstant() {
@test fun emptyConstant() {
doTest(IntRange.EMPTY, 1, 0, 1, listOf())
doTest(ByteRange.EMPTY, 1.toByte(), 0.toByte(), 1, listOf())
doTest(ShortRange.EMPTY, 1.toShort(), 0.toShort(), 1, listOf())
@@ -34,7 +34,7 @@ public class RangeIterationTest {
doTest(FloatRange.EMPTY, 1.0.toFloat(), 0.0.toFloat(), 1.0.toFloat(), listOf())
}
test fun emptyRange() {
@test fun emptyRange() {
doTest(10..5, 10, 5, 1, listOf())
doTest(10.toByte()..(-5).toByte(), 10.toByte(), (-5).toByte(), 1, listOf())
doTest(10.toShort()..(-5).toShort(), 10.toShort(), (-5).toShort(), 1, listOf())
@@ -46,7 +46,7 @@ public class RangeIterationTest {
doTest(5.0.toFloat()..-1.0.toFloat(), 5.0.toFloat(), -1.0.toFloat(), 1.toFloat(), listOf())
}
test fun oneElementRange() {
@test fun oneElementRange() {
doTest(5..5, 5, 5, 1, listOf(5))
doTest(5.toByte()..5.toByte(), 5.toByte(), 5.toByte(), 1, listOf(5.toByte()))
doTest(5.toShort()..5.toShort(), 5.toShort(), 5.toShort(), 1, listOf(5.toShort()))
@@ -58,7 +58,7 @@ public class RangeIterationTest {
doTest(5.0.toFloat()..5.0.toFloat(), 5.0.toFloat(), 5.0.toFloat(), 1.toFloat(), listOf(5.0.toFloat()))
}
test fun simpleRange() {
@test fun simpleRange() {
doTest(3..9, 3, 9, 1, listOf(3, 4, 5, 6, 7, 8, 9))
doTest(3.toByte()..9.toByte(), 3.toByte(), 9.toByte(), 1, listOf<Byte>(3, 4, 5, 6, 7, 8, 9))
doTest(3.toShort()..9.toShort(), 3.toShort(), 9.toShort(), 1, listOf<Short>(3, 4, 5, 6, 7, 8, 9))
@@ -72,7 +72,7 @@ public class RangeIterationTest {
}
test fun simpleRangeWithNonConstantEnds() {
@test fun simpleRangeWithNonConstantEnds() {
doTest((1 + 2)..(10 - 1), 3, 9, 1, listOf(3, 4, 5, 6, 7, 8, 9))
doTest((1.toByte() + 2.toByte()).toByte()..(10.toByte() - 1.toByte()).toByte(), 3.toByte(), 9.toByte(), 1, listOf<Byte>(3, 4, 5, 6, 7, 8, 9))
doTest((1.toShort() + 2.toShort()).toShort()..(10.toShort() - 1.toShort()).toShort(), 3.toShort(), 9.toShort(), 1, listOf<Short>(3, 4, 5, 6, 7, 8, 9))
@@ -85,7 +85,7 @@ public class RangeIterationTest {
listOf<Float>(3.0.toFloat(), 4.0.toFloat(), 5.0.toFloat(), 6.0.toFloat(), 7.0.toFloat(), 8.0.toFloat(), 9.0.toFloat()))
}
test fun openRange() {
@test fun openRange() {
doTest(1 until 5, 1, 4, 1, listOf(1, 2, 3, 4))
doTest(1.toByte() until 5.toByte(), 1.toByte(), 4.toByte(), 1, listOf<Byte>(1, 2, 3, 4))
doTest(1.toShort() until 5.toShort(), 1.toShort(), 4.toShort(), 1, listOf<Short>(1, 2, 3, 4))
@@ -94,7 +94,7 @@ public class RangeIterationTest {
}
test fun emptyDownto() {
@test fun emptyDownto() {
doTest(5 downTo 10, 5, 10, -1, listOf())
doTest(5.toByte() downTo 10.toByte(), 5.toByte(), 10.toByte(), -1, listOf())
doTest(5.toShort() downTo 10.toShort(), 5.toShort(), 10.toShort(), -1, listOf())
@@ -106,7 +106,7 @@ public class RangeIterationTest {
doTest(-1.0.toFloat() downTo 5.0.toFloat(), -1.0.toFloat(), 5.0.toFloat(), -1.0.toFloat(), listOf())
}
test fun oneElementDownTo() {
@test fun oneElementDownTo() {
doTest(5 downTo 5, 5, 5, -1, listOf(5))
doTest(5.toByte() downTo 5.toByte(), 5.toByte(), 5.toByte(), -1, listOf(5.toByte()))
doTest(5.toShort() downTo 5.toShort(), 5.toShort(), 5.toShort(), -1, listOf(5.toShort()))
@@ -118,7 +118,7 @@ public class RangeIterationTest {
doTest(5.0.toFloat() downTo 5.0.toFloat(), 5.0.toFloat(), 5.0.toFloat(), -1.0.toFloat(), listOf(5.0.toFloat()))
}
test fun simpleDownTo() {
@test fun simpleDownTo() {
doTest(9 downTo 3, 9, 3, -1, listOf(9, 8, 7, 6, 5, 4, 3))
doTest(9.toByte() downTo 3.toByte(), 9.toByte(), 3.toByte(), -1, listOf<Byte>(9, 8, 7, 6, 5, 4, 3))
doTest(9.toShort() downTo 3.toShort(), 9.toShort(), 3.toShort(), -1, listOf<Short>(9, 8, 7, 6, 5, 4, 3))
@@ -132,7 +132,7 @@ public class RangeIterationTest {
}
test fun simpleSteppedRange() {
@test fun simpleSteppedRange() {
doTest(3..9 step 2, 3, 9, 2, listOf(3, 5, 7, 9))
doTest(3.toByte()..9.toByte() step 2, 3.toByte(), 9.toByte(), 2, listOf<Byte>(3, 5, 7, 9))
doTest(3.toShort()..9.toShort() step 2, 3.toShort(), 9.toShort(), 2, listOf<Short>(3, 5, 7, 9))
@@ -145,7 +145,7 @@ public class RangeIterationTest {
listOf<Float>(4.0.toFloat(), 4.5.toFloat(), 5.0.toFloat(), 5.5.toFloat(), 6.0.toFloat()))
}
test fun simpleSteppedDownTo() {
@test fun simpleSteppedDownTo() {
doTest(9 downTo 3 step 2, 9, 3, -2, listOf(9, 7, 5, 3))
doTest(9.toByte() downTo 3.toByte() step 2, 9.toByte(), 3.toByte(), -2, listOf<Byte>(9, 7, 5, 3))
doTest(9.toShort() downTo 3.toShort() step 2, 9.toShort(), 3.toShort(), -2, listOf<Short>(9, 7, 5, 3))
@@ -160,7 +160,7 @@ public class RangeIterationTest {
// 'inexact' means last element is not equal to sequence end
test fun inexactSteppedRange() {
@test fun inexactSteppedRange() {
doTest(3..8 step 2, 3, 8, 2, listOf(3, 5, 7))
doTest(3.toByte()..8.toByte() step 2, 3.toByte(), 8.toByte(), 2, listOf<Byte>(3, 5, 7))
doTest(3.toShort()..8.toShort() step 2, 3.toShort(), 8.toShort(), 2, listOf<Short>(3, 5, 7))
@@ -174,7 +174,7 @@ public class RangeIterationTest {
}
// 'inexact' means last element is not equal to sequence end
test fun inexactSteppedDownTo() {
@test fun inexactSteppedDownTo() {
doTest(8 downTo 3 step 2, 8, 3, -2, listOf(8, 6, 4))
doTest(8.toByte() downTo 3.toByte() step 2, 8.toByte(), 3.toByte(), -2, listOf<Byte>(8, 6, 4))
doTest(8.toShort() downTo 3.toShort() step 2, 8.toShort(), 3.toShort(), -2, listOf<Short>(8, 6, 4))
@@ -188,7 +188,7 @@ public class RangeIterationTest {
}
test fun reversedEmptyRange() {
@test fun reversedEmptyRange() {
doTest((5..3).reversed(), 3, 5, -1, listOf())
doTest((5.toByte()..3.toByte()).reversed(), 3.toByte(), 5.toByte(), -1, listOf())
doTest((5.toShort()..3.toShort()).reversed(), 3.toShort(), 5.toShort(), -1, listOf())
@@ -200,7 +200,7 @@ public class RangeIterationTest {
doTest((5.0.toFloat()..3.0.toFloat()).reversed(), 3.0.toFloat(), 5.0.toFloat(), -1.toFloat(), listOf())
}
test fun reversedEmptyBackSequence() {
@test fun reversedEmptyBackSequence() {
doTest((3 downTo 5).reversed(), 5, 3, 1, listOf())
doTest((3.toByte() downTo 5.toByte()).reversed(), 5.toByte(), 3.toByte(), 1, listOf())
doTest((3.toShort() downTo 5.toShort()).reversed(), 5.toShort(), 3.toShort(), 1, listOf())
@@ -212,7 +212,7 @@ public class RangeIterationTest {
doTest((3.0.toFloat() downTo 5.0.toFloat()).reversed(), 5.0.toFloat(), 3.0.toFloat(), 1.toFloat(), listOf())
}
test fun reversedRange() {
@test fun reversedRange() {
doTest((3..5).reversed(), 5, 3, -1, listOf(5, 4, 3))
doTest((3.toByte()..5.toByte()).reversed(), 5.toByte(), 3.toByte(), -1, listOf<Byte>(5, 4, 3))
doTest((3.toShort()..5.toShort()).reversed(), 5.toShort(), 3.toShort(), -1, listOf<Short>(5, 4, 3))
@@ -225,7 +225,7 @@ public class RangeIterationTest {
listOf<Float>(5.0.toFloat(), 4.0.toFloat(), 3.0.toFloat()))
}
test fun reversedBackSequence() {
@test fun reversedBackSequence() {
doTest((5 downTo 3).reversed(), 3, 5, 1, listOf(3, 4, 5))
doTest((5.toByte() downTo 3.toByte()).reversed(), 3.toByte(), 5.toByte(), 1, listOf<Byte>(3, 4, 5))
doTest((5.toShort() downTo 3.toShort()).reversed(), 3.toShort(), 5.toShort(), 1, listOf<Short>(3, 4, 5))
@@ -238,7 +238,7 @@ public class RangeIterationTest {
listOf<Float>(3.0.toFloat(), 4.0.toFloat(), 5.0.toFloat()))
}
test fun reversedSimpleSteppedRange() {
@test fun reversedSimpleSteppedRange() {
doTest((3..9 step 2).reversed(), 9, 3, -2, listOf(9, 7, 5, 3))
doTest((3.toByte()..9.toByte() step 2).reversed(), 9.toByte(), 3.toByte(), -2, listOf<Byte>(9, 7, 5, 3))
doTest((3.toShort()..9.toShort() step 2).reversed(), 9.toShort(), 3.toShort(), -2, listOf<Short>(9, 7, 5, 3))
@@ -252,7 +252,7 @@ public class RangeIterationTest {
}
// 'inexact' means last element is not equal to sequence end
test fun reversedInexactSteppedDownTo() {
@test fun reversedInexactSteppedDownTo() {
doTest((8 downTo 3 step 2).reversed(), 3, 8, 2, listOf(3, 5, 7))
doTest((8.toByte() downTo 3.toByte() step 2).reversed(), 3.toByte(), 8.toByte(), 2, listOf<Byte>(3, 5, 7))
doTest((8.toShort() downTo 3.toShort() step 2).reversed(), 3.toShort(), 8.toShort(), 2, listOf<Short>(3, 5, 7))
@@ -7,14 +7,14 @@ import kotlin.test.*
public class RangeJVMTest {
test fun doubleRange() {
@test fun doubleRange() {
val range = -1.0..3.14159265358979
assertFalse(jDouble.NEGATIVE_INFINITY in range)
assertFalse(jDouble.POSITIVE_INFINITY in range)
assertFalse(jDouble.NaN in range)
}
test fun floatRange() {
@test fun floatRange() {
val range = -1.0f..3.14159f
assertFalse(jFloat.NEGATIVE_INFINITY in range)
assertFalse(jFloat.POSITIVE_INFINITY in range)
@@ -22,7 +22,7 @@ public class RangeJVMTest {
assertFalse(jFloat.NaN in range)
}
test fun illegalProgressionCreation() {
@test fun illegalProgressionCreation() {
fun assertFailsWithIllegalArgument(f: () -> Unit) = assertFailsWith(IllegalArgumentException::class, block = f)
// create Progression explicitly with increment = 0
assertFailsWithIllegalArgument { IntProgression(0, 5, 0) }
+11 -11
View File
@@ -4,7 +4,7 @@ import kotlin.test.*
import org.junit.Test as test
public class RangeTest {
test fun intRange() {
@test fun intRange() {
val range = -5..9
assertFalse(-1000 in range)
assertFalse(-6 in range)
@@ -36,7 +36,7 @@ public class RangeTest {
assertTrue(fails { 1 until Int.MIN_VALUE } is IllegalArgumentException)
}
test fun byteRange() {
@test fun byteRange() {
val range = (-5).toByte()..9.toByte()
assertFalse((-100).toByte() in range)
assertFalse((-6).toByte() in range)
@@ -70,7 +70,7 @@ public class RangeTest {
}
test fun shortRange() {
@test fun shortRange() {
val range = (-5).toShort()..9.toShort()
assertFalse((-1000).toShort() in range)
assertFalse((-6).toShort() in range)
@@ -102,7 +102,7 @@ public class RangeTest {
assertTrue(fails { 0.toShort() until Short.MIN_VALUE } is IllegalArgumentException)
}
test fun longRange() {
@test fun longRange() {
val range = -5L..9L
assertFalse(-10000000L in range)
assertFalse(-6L in range)
@@ -135,7 +135,7 @@ public class RangeTest {
}
test fun charRange() {
@test fun charRange() {
val range = 'c'..'w'
assertFalse('0' in range)
assertFalse('b' in range)
@@ -159,7 +159,7 @@ public class RangeTest {
assertTrue(fails { 'A' until '\u0000' } is IllegalArgumentException)
}
test fun doubleRange() {
@test fun doubleRange() {
val range = -1.0..3.14159265358979
assertFalse(-1e200 in range)
assertFalse(-100.0 in range)
@@ -185,7 +185,7 @@ public class RangeTest {
assertTrue(1.toFloat() in range)
}
test fun floatRange() {
@test fun floatRange() {
val range = -1.0f..3.14159f
assertFalse(-1e30f in range)
assertFalse(-100.0f in range)
@@ -213,7 +213,7 @@ public class RangeTest {
assertFalse(Double.MAX_VALUE in range)
}
test fun isEmpty() {
@test fun isEmpty() {
assertTrue((2..1).isEmpty())
assertTrue((2L..0L).isEmpty())
assertTrue((1.toShort()..-1.toShort()).isEmpty())
@@ -232,7 +232,7 @@ public class RangeTest {
assertTrue(("range".."progression").isEmpty())
}
test fun emptyEquals() {
@test fun emptyEquals() {
assertTrue(IntRange.EMPTY == IntRange.EMPTY)
assertEquals(IntRange.EMPTY, IntRange.EMPTY)
assertEquals(0L..42L, 0L..42L)
@@ -259,7 +259,7 @@ public class RangeTest {
assertFalse(("aa".."bb") == ("aaa".."bbb"))
}
test fun emptyHashCode() {
@test fun emptyHashCode() {
assertEquals((0..42).hashCode(), (0..42).hashCode())
assertEquals((1.23..4.56).hashCode(), (1.23..4.56).hashCode())
@@ -279,7 +279,7 @@ public class RangeTest {
assertEquals(("range".."progression").hashCode(), ("hashcode".."equals").hashCode())
}
test fun comparableRange() {
@test fun comparableRange() {
val range = "island".."isle"
assertFalse("apple" in range)
assertFalse("icicle" in range)
@@ -41,7 +41,7 @@ val EXPECTED = """
class StringExpressionExampleTest {
val customer = Customer("James", arrayListOf(Product("Beer", 1.99), Product("Wine", 5.99)))
test fun testExpressions(): Unit {
@test fun testExpressions(): Unit {
assertEquals(EXPECTED, customerTemplate(customer))
}
}
@@ -17,7 +17,8 @@ class CoercionTest {
val n3 = n coerceIn 2..5
}
Test fun coercionsInt() {
@Test
fun coercionsInt() {
expect(5) { 5.coerceAtLeast(1) }
expect(5) { 1.coerceAtLeast(5) }
expect(1) { 5.coerceAtMost(1) }
@@ -39,7 +40,8 @@ class CoercionTest {
fails { 1.coerceIn(1..0) }
}
Test fun coercionsLong() {
@Test
fun coercionsLong() {
expect(5L) { 5L.coerceAtLeast(1L) }
expect(5L) { 1L.coerceAtLeast(5L) }
expect(1L) { 5L.coerceAtMost(1L) }
@@ -62,7 +64,8 @@ class CoercionTest {
}
Test fun coercionsDouble() {
@Test
fun coercionsDouble() {
expect(5.0) { 5.0.coerceAtLeast(1.0) }
expect(5.0) { 1.0.coerceAtLeast(5.0) }
expect(1.0) { 5.0.coerceAtMost(1.0) }
@@ -84,7 +87,8 @@ class CoercionTest {
fails { 1.0.coerceIn(1.0..0.0) }
}
Test fun coercionsComparable() {
@Test
fun coercionsComparable() {
val v = 0..10 map { ComparableNumber(it) }
expect(5) { v[5].coerceAtLeast(v[1]).value }
+8 -8
View File
@@ -6,7 +6,7 @@ import kotlin.test.*
class NumbersTest {
test fun intMinMaxValues() {
@test fun intMinMaxValues() {
assertTrue(Int.MIN_VALUE < 0)
assertTrue(Int.MAX_VALUE > 0)
@@ -16,7 +16,7 @@ class NumbersTest {
// expect(Int.MAX_VALUE) { Int.MIN_VALUE - 1 }
}
test fun longMinMaxValues() {
@test fun longMinMaxValues() {
assertTrue(Long.MIN_VALUE < 0)
assertTrue(Long.MAX_VALUE > 0)
// overflow behavior
@@ -24,7 +24,7 @@ class NumbersTest {
expect(Long.MAX_VALUE) { Long.MIN_VALUE - 1 }
}
test fun shortMinMaxValues() {
@test fun shortMinMaxValues() {
assertTrue(Short.MIN_VALUE < 0)
assertTrue(Short.MAX_VALUE > 0)
// overflow behavior
@@ -32,7 +32,7 @@ class NumbersTest {
expect(Short.MAX_VALUE) { (Short.MIN_VALUE - 1).toShort() }
}
test fun byteMinMaxValues() {
@test fun byteMinMaxValues() {
assertTrue(Byte.MIN_VALUE < 0)
assertTrue(Byte.MAX_VALUE > 0)
// overflow behavior
@@ -40,7 +40,7 @@ class NumbersTest {
expect(Byte.MAX_VALUE) { (Byte.MIN_VALUE - 1).toByte() }
}
test fun doubleMinMaxValues() {
@test fun doubleMinMaxValues() {
assertTrue(Double.MIN_VALUE > 0)
assertTrue(Double.MAX_VALUE > 0)
// overflow behavior
@@ -49,7 +49,7 @@ class NumbersTest {
expect(0.0) { Double.MIN_VALUE / 2 }
}
test fun floatMinMaxValues() {
@test fun floatMinMaxValues() {
assertTrue(Float.MIN_VALUE > 0)
assertTrue(Float.MAX_VALUE > 0)
// overflow behavior
@@ -58,7 +58,7 @@ class NumbersTest {
expect(0.0F) { Float.MIN_VALUE / 2.0F }
}
test fun doubleProperties() {
@test fun doubleProperties() {
for (value in listOf(1.0, 0.0, Double.MIN_VALUE, Double.MAX_VALUE))
doTestNumber(value)
for (value in listOf(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY))
@@ -66,7 +66,7 @@ class NumbersTest {
doTestNumber(Double.NaN, isNaN = true)
}
test fun floatProperties() {
@test fun floatProperties() {
for (value in listOf(1.0F, 0.0F, Float.MAX_VALUE, Float.MIN_VALUE))
doTestNumber(value)
for (value in listOf(Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY))
@@ -35,7 +35,7 @@ class MyChangeListener : ChangeListener {
class PropertiesTest {
test fun testModel() {
@test fun testModel() {
val c = Customer()
c.name = "James"
c.city = "Mells"
@@ -5,7 +5,7 @@ import kotlin.test.*
import kotlin.properties.*
class NotNullVarTest() {
test fun doTest() {
@test fun doTest() {
NotNullVarTestGeneric("a", "b").doTest()
}
}
@@ -27,7 +27,7 @@ class ObservablePropertyInChangeSupportTest: ChangeSupport() {
var b by property(init = 2)
var c by property(3)
test fun doTest() {
@test fun doTest() {
var result = false
addChangeListener("b", object: ChangeListener {
public override fun onPropertyChange(event: ChangeEvent) {
@@ -54,7 +54,7 @@ class ObservablePropertyTest {
assertEquals(new, b, "New value has already been set")
})
test fun doTest() {
@test fun doTest() {
b = 4
assertTrue(b == 4, "fail: b != 4")
assertTrue(result, "fail: result should be true")
@@ -72,7 +72,7 @@ class VetoablePropertyTest {
result
})
test fun doTest() {
@test fun doTest() {
val firstValue = A(true)
b = firstValue
assertTrue(b == firstValue, "fail1: b should be firstValue = A(true)")
@@ -18,7 +18,7 @@ class ValByMapExtensionsTest {
val x: Double by genericMap
test fun doTest() {
@test fun doTest() {
assertEquals("all", a)
assertEquals("bar", b)
assertEquals("code", c)
@@ -42,7 +42,7 @@ class VarByMapExtensionsTest {
var a2: String by map2.withDefault { "empty" }
//var x: Int by map2 // prohibited by type system
test fun doTest() {
@test fun doTest() {
assertEquals("all", a)
assertEquals(null, b)
assertEquals(1, c)
@@ -14,7 +14,7 @@ class MapValWithDifferentTypesTest() {
val c by Delegates.mapVal<Any>(map)
val d by Delegates.mapVal<Int?>(map)
test fun doTest() {
@test fun doTest() {
assertTrue(a == "a", "fail at 'a'")
assertTrue(b == 1, "fail at 'b'")
assertTrue(c == B(1), "fail at 'c'")
@@ -29,7 +29,7 @@ class MapVarWithDifferentTypesTest() {
var c by Delegates.mapVar<Any>(map)
var d by Delegates.mapVar<String?>(map)
test fun doTest() {
@test fun doTest() {
a = "aa"
b = 11
c = B(11)
@@ -48,7 +48,7 @@ class MapNullableKeyTest {
val map = hashMapOf<Any?, Any?>(null to "null")
var a by FixedMapVar<Any?, Any?, Any?>(map, key = { desc -> null }, default = {ref, desc -> null})
test fun doTest() {
@test fun doTest() {
assertTrue(a == "null", "fail at 'a'")
a = "foo"
assertTrue(a == "foo", "fail at 'a' after set")
@@ -61,7 +61,7 @@ class MapPropertyStringTest() {
var b by Delegates.mapVar<String>(map)
val c by Delegates.mapVal<String>(map)
test fun doTest() {
@test fun doTest() {
b = "newB"
assertTrue(a == "a", "fail at 'a'")
assertTrue(b == "newB", "fail at 'b'")
@@ -75,7 +75,7 @@ class MapValWithDefaultTest() {
val b: String by FixedMapVal(map, default = { ref: MapValWithDefaultTest, desc: String -> "bDefault" }, key = {"b"})
val c: String by FixedMapVal(map, default = { ref: MapValWithDefaultTest, desc: String -> "cDefault" }, key = { desc -> desc.name })
test fun doTest() {
@test fun doTest() {
assertTrue(a == "aDefault", "fail at 'a'")
assertTrue(b == "bDefault", "fail at 'b'")
assertTrue(c == "cDefault", "fail at 'c'")
@@ -88,7 +88,7 @@ class MapVarWithDefaultTest() {
var b: String by FixedMapVar(map, default = {ref: Any?, desc: String -> "bDefault" }, key = {"b"})
var c: String by FixedMapVar(map, default = {ref: Any?, desc: String -> "cDefault" }, key = { desc -> desc.name })
test fun doTest() {
@test fun doTest() {
assertTrue(a == "aDefault", "fail at 'a'")
assertTrue(b == "bDefault", "fail at 'b'")
assertTrue(c == "cDefault", "fail at 'c'")
@@ -106,7 +106,7 @@ class MapPropertyKeyTest() {
val a by FixedMapVal<Any?, String, String>(map, key = {"a"})
var b by FixedMapVar<Any?, String, String>(map, key = {"b"})
test fun doTest() {
@test fun doTest() {
b = "c"
assertTrue(a == "a", "fail at 'a'")
assertTrue(b == "c", "fail at 'b'")
@@ -118,7 +118,7 @@ class MapPropertyFunctionTest() {
val a by FixedMapVal<Any?, String, String>(map, { desc -> "${desc.name}Desc" })
var b by FixedMapVar<Any?, String, String>(map, { desc -> "${desc.name}Desc" })
test fun doTest() {
@test fun doTest() {
b = "c"
assertTrue(a == "a", "fail at 'a'")
assertTrue(b == "c", "fail at 'b' after set")
@@ -141,7 +141,7 @@ class MapPropertyCustomTest() {
val a by mapVal
var b by mapVar
test fun doTest() {
@test fun doTest() {
b = "newB"
assertTrue(a == "a", "fail at 'a'")
assertTrue(b == "newB", "fail at 'b' after set")
@@ -167,7 +167,7 @@ class MapPropertyCustomWithDefaultTest() {
val a by mapValWithDefault
var b by mapVarWithDefault
test fun doTest() {
@test fun doTest() {
assertTrue(a == "default", "fail at 'a'")
assertTrue(b == "default", "fail at 'b'")
b = "c"
@@ -11,19 +11,19 @@ class LazyValTest {
++result
}
test fun doTest() {
@test fun doTest() {
a
assertTrue(a == 1, "fail: initializer should be invoked only once")
}
}
class SynchronizedLazyValTest {
volatile var result = 0
@Volatile var result = 0
val a by lazy(this) {
++result
}
test fun doTest() {
@test fun doTest() {
synchronized(this) {
// thread { a } // not available in js // TODO: Make this test JVM-only
result = 1
@@ -40,7 +40,7 @@ class UnsafeLazyValTest {
++result
}
test fun doTest() {
@test fun doTest() {
a
assertTrue(a == 1, "fail: initializer should be invoked only once")
}
@@ -53,7 +53,7 @@ class NullableLazyValTest {
val a: Int? by lazy { resultA++; null}
val b by lazy { foo() }
test fun doTest() {
@test fun doTest() {
a
b
@@ -76,7 +76,7 @@ class UnsafeNullableLazyValTest {
val a: Int? by lazy(LazyThreadSafetyMode.NONE) { resultA++; null}
val b by lazy(LazyThreadSafetyMode.NONE) { foo() }
test fun doTest() {
@test fun doTest() {
a
b
@@ -98,7 +98,7 @@ class UnsafeLazyValDeprecatedTest {
++result
}
test fun doTest() {
@test fun doTest() {
a
assertTrue(a == 1, "fail: initializer should be invoked only once")
}
@@ -110,7 +110,7 @@ class BlockingLazyValDeprecatedTest {
++result
}
test fun doTest() {
@test fun doTest() {
a
assertTrue(a == 1, "fail: initializer should be invoked only once")
}
@@ -123,7 +123,7 @@ class UnsafeNullableLazyValDeprecatedTest {
val a: Int? by Delegates.lazy { resultA++; null}
val b by Delegates.lazy { foo() }
test fun doTest() {
@test fun doTest() {
a
b
@@ -146,7 +146,7 @@ class BlockingNullableLazyValDeprecatedTest {
val a: Int? by Delegates.blockingLazy { resultA++; null}
val b by Delegates.blockingLazy { foo() }
test fun doTest() {
@test fun doTest() {
a
b
@@ -166,7 +166,7 @@ class IdentityEqualsIsUsedToUnescapeLazyValTest {
var equalsCalled = 0
val a by lazy { ClassWithCustomEquality { equalsCalled++ } }
test fun doTest() {
@test fun doTest() {
a
a
assertTrue(equalsCalled == 0, "fail: equals called $equalsCalled times.")
+12 -6
View File
@@ -25,7 +25,8 @@ class TestJVMTest {
override fun toString() = "actual"
}
Test fun assertEqualsMessage() {
@Test
fun assertEqualsMessage() {
expectAssertion( { msg ->
assertNotNull(msg); msg!!
assertTrue { msg.contains(expected.toString()) }
@@ -41,7 +42,8 @@ class TestJVMTest {
} , { assertEquals(expected, actual, message) })
}
Test fun assertNotEqualsMessage() {
@Test
fun assertNotEqualsMessage() {
expectAssertion( { msg ->
assertNotNull(msg); msg!!
assertTrue { msg.contains(actual.toString()) }
@@ -56,7 +58,8 @@ class TestJVMTest {
}
Test fun assertTrueMessage() {
@Test
fun assertTrueMessage() {
expectAssertion( { msg -> assertNotNull(msg) }, { assertTrue(false) })
expectAssertion( { msg -> assertNotNull(msg) }, { assertTrue { false } })
expectAssertion( { msg -> assertNotNull(msg) }, { assertTrue(null) { false } })
@@ -64,7 +67,8 @@ class TestJVMTest {
expectAssertion( { msg -> msg!!.contains(message)}, { assertTrue(message) { false }})
}
Test fun assertFalseMessage() {
@Test
fun assertFalseMessage() {
expectAssertion( { msg -> assertNotNull(msg) }, { assertFalse(true) })
expectAssertion( { msg -> assertNotNull(msg) }, { assertFalse { true } })
expectAssertion( { msg -> assertNotNull(msg) }, { assertFalse(null) { true } })
@@ -72,12 +76,14 @@ class TestJVMTest {
expectAssertion( { msg -> assertTrue(msg!!.contains(message)) }, { assertFalse(message) { true }})
}
Test fun assertNotNullMessage() {
@Test
fun assertNotNullMessage() {
expectAssertion( { msg -> msg!! }, { assertNotNull(null) })
expectAssertion( { msg -> assertTrue(msg!!.contains(message)) }, { assertNotNull(null, message)})
}
Test fun assertNullMessage() {
@Test
fun assertNullMessage() {
expectAssertion( { msg -> msg!! }, { assertNull(actual) })
expectAssertion( { msg -> msg!!
assertTrue(msg.contains(message))
+1 -1
View File
@@ -5,7 +5,7 @@ import org.junit.Test as test
class CharJVMTest {
test fun getCategory() {
@test fun getCategory() {
assertEquals(CharCategory.DECIMAL_DIGIT_NUMBER, '7'.category())
assertEquals(CharCategory.CURRENCY_SYMBOL, '$'.category())
assertEquals(CharCategory.LOWERCASE_LETTER, 'a'.category())
+1 -1
View File
@@ -7,7 +7,7 @@ import org.junit.Test as test
class RegexJVMTest {
test fun matchGroups() {
@test fun matchGroups() {
val input = "1a 2b 3c"
val regex = "(\\d)(\\w)".toRegex()
+11 -11
View File
@@ -7,7 +7,7 @@ import org.junit.Test as test
class RegexTest {
test fun matchResult() {
@test fun matchResult() {
val p = "\\d+".toRegex()
val input = "123 456 789"
@@ -35,12 +35,12 @@ class RegexTest {
assertEquals(null, noMatch)
}
test fun matchIgnoreCase() {
@test fun matchIgnoreCase() {
for (input in listOf("ascii", "shrödinger"))
assertTrue(input.toUpperCase().matches(input.toLowerCase().toRegex(RegexOption.IGNORE_CASE)))
}
test fun matchSequence() {
@test fun matchSequence() {
val input = "123 456 789"
val pattern = "\\d+".toRegex()
@@ -54,7 +54,7 @@ class RegexTest {
assertEquals(listOf(0..2, 4..6, 8..10), matches.map { it.range }.toList())
}
test fun matchAllSequence() {
@test fun matchAllSequence() {
val input = "test"
val pattern = ".*".toRegex()
val matches = pattern.matchAll(input).toList()
@@ -63,7 +63,7 @@ class RegexTest {
assertEquals(2, matches.size())
}
test fun matchGroups() {
@test fun matchGroups() {
val input = "1a 2b 3c"
val pattern = "(\\d)(\\w)".toRegex()
@@ -79,7 +79,7 @@ class RegexTest {
assertEquals("b", m2.groups[2]?.value)
}
test fun matchOptionalGroup() {
@test fun matchOptionalGroup() {
val pattern = "(hi)|(bye)".toRegex(RegexOption.IGNORE_CASE)
val m1 = pattern.match("Hi!")!!
@@ -93,19 +93,19 @@ class RegexTest {
assertEquals("bye", m2.groups[2]?.value)
}
test fun matchMultiline() {
@test fun matchMultiline() {
val regex = "^[a-z]*$".toRegex(setOf(RegexOption.IGNORE_CASE, RegexOption.MULTILINE))
val matchedValues = regex.matchAll("test\n\nLine").map { it.value }.toList()
assertEquals(listOf("test", "", "Line"), matchedValues)
}
test fun escapeLiteral() {
@test fun escapeLiteral() {
val literal = """[-\/\\^$*+?.()|[\]{}]"""
assertTrue(Regex.fromLiteral(literal).matches(literal))
assertTrue(Regex.escape(literal).toRegex().matches(literal))
}
test fun replace() {
@test fun replace() {
val input = "123-456"
val pattern = "(\\d+)".toRegex()
assertEquals("(123)-(456)", pattern.replace(input, "($1)"))
@@ -114,14 +114,14 @@ class RegexTest {
assertEquals("X-456", pattern.replaceFirst(input, "X"))
}
test fun replaceEvaluator() {
@test fun replaceEvaluator() {
val input = "/12/456/7890/"
val pattern = "\\d+".toRegex()
assertEquals("/2/3/4/", pattern.replace(input, { it.value.length().toString() } ))
}
test fun split() {
@test fun split() {
val input = """
some ${"\t"} word
split
@@ -5,7 +5,7 @@ import org.junit.Test as test
class StringBuilderTest {
test fun stringBuild() {
@test fun stringBuild() {
val s = StringBuilder {
append("a")
append(true)
@@ -13,13 +13,13 @@ class StringBuilderTest {
assertEquals("atrue", s)
}
test fun appendMany() {
@test fun appendMany() {
assertEquals("a1", StringBuilder().append("a", "1").toString())
assertEquals("a1", StringBuilder().append("a", 1).toString())
assertEquals("a1", StringBuilder().append("a", StringBuilder().append("1")).toString())
}
test fun append() {
@test fun append() {
// this test is needed for JS implementation
assertEquals("em", StringBuilder {
append("element", 2, 4)
+40 -40
View File
@@ -6,7 +6,7 @@ import kotlin.test.*
import org.junit.Test as test
class StringJVMTest {
test fun stringBuilderIterator() {
@test fun stringBuilderIterator() {
var sum = 0
val sb = StringBuilder()
for(c in "239")
@@ -19,7 +19,7 @@ class StringJVMTest {
assertTrue(sum == 14)
}
test fun orEmpty() {
@test fun orEmpty() {
val s: String? = "hey"
val ns: String? = null
@@ -27,25 +27,25 @@ class StringJVMTest {
assertEquals("", ns.orEmpty())
}
test fun toShort() {
@test fun toShort() {
assertEquals(77.toShort(), "77".toShort())
}
test fun toInt() {
@test fun toInt() {
assertEquals(77, "77".toInt())
}
test fun toLong() {
@test fun toLong() {
assertEquals(77.toLong(), "77".toLong())
}
test fun count() {
@test fun count() {
val text = "hello there\tfoo\nbar"
val whitespaceCount = text.count { it.isWhitespace() }
assertEquals(3, whitespaceCount)
}
test fun testSplitByChar() {
@test fun testSplitByChar() {
val s = "ab\n[|^$&\\]^cd"
var list = s.split('b');
assertEquals(2, list.size())
@@ -59,7 +59,7 @@ class StringJVMTest {
assertEquals(s, list[0])
}
test fun testSplitByPattern() {
@test fun testSplitByPattern() {
val s = "ab1cd2def3"
val isDigit = "\\d".toRegex()
assertEquals(listOf("ab", "cd", "def", ""), s.split(isDigit))
@@ -73,7 +73,7 @@ class StringJVMTest {
}
}
test fun repeat() {
@test fun repeat() {
fails{ "foo".repeat(-1) }
assertEquals("", "foo".repeat(0))
assertEquals("foo", "foo".repeat(1))
@@ -81,24 +81,24 @@ class StringJVMTest {
assertEquals("foofoofoo", "foo".repeat(3))
}
test fun filter() {
@test fun filter() {
assertEquals("acdca", "abcdcba".filter { !it.equals('b') })
assertEquals("1234", "a1b2c3d4".filter { it.isDigit() })
}
test fun filterNot() {
@test fun filterNot() {
assertEquals("acdca", "abcdcba".filterNot { it.equals('b') })
assertEquals("abcd", "a1b2c3d4".filterNot { it.isDigit() })
}
test fun forEach() {
@test fun forEach() {
val data = "abcd1234"
var count = 0
data.forEach{ count++ }
assertEquals(data.length(), count)
}
test fun all() {
@test fun all() {
val data = "AbCd"
assertTrue {
data.all { it.isJavaLetter() }
@@ -108,7 +108,7 @@ class StringJVMTest {
}
}
test fun any() {
@test fun any() {
val data = "a1bc"
assertTrue {
data.any() { it.isDigit() }
@@ -118,33 +118,33 @@ class StringJVMTest {
}
}
test fun joinTo() {
@test fun joinTo() {
val data = "kotlin".toList()
val sb = StringBuilder()
data.joinTo(sb, "^", "<", ">")
assertEquals("<k^o^t^l^i^n>", sb.toString())
}
test fun find() {
@test fun find() {
val data = "a1b2c3"
assertEquals('1', data.first { it.isDigit() })
assertNull(data.firstOrNull { it.isUpperCase() })
}
test fun findNot() {
@test fun findNot() {
val data = "1a2b3c"
assertEquals('a', data.filterNot { it.isDigit() }.firstOrNull())
assertNull(data.filterNot { it.isJavaLetterOrDigit() }.firstOrNull())
}
test fun partition() {
@test fun partition() {
val data = "a1b2c3"
val pair = data.partition { it.isDigit() }
assertEquals("123", pair.first, "pair.first")
assertEquals("abc", pair.second, "pair.second")
}
test fun map() {
@test fun map() {
assertEquals(arrayListOf('a', 'b', 'c'), "abc".map({ it }))
assertEquals(arrayListOf(true, false, true), "AbC".map({ it.isUpperCase() }))
@@ -154,7 +154,7 @@ class StringJVMTest {
assertEquals(arrayListOf(97, 98, 99), "abc".map({ it.toInt() }))
}
test fun mapTo() {
@test fun mapTo() {
val result1 = arrayListOf<Char>()
val return1 = "abc".mapTo(result1, { it })
assertEquals(result1, return1)
@@ -176,14 +176,14 @@ class StringJVMTest {
assertEquals(arrayListOf(97, 98, 99), result4)
}
test fun flatMap() {
@test fun flatMap() {
val data = "abcd"
val result = data.flatMap { listOf(it) }
assertEquals(data.length(), result.count())
assertEquals(data.toCharList(), result)
}
test fun fold() {
@test fun fold() {
// calculate number of digits in the string
val data = "a1b2c3def"
val result = data.fold(0, { digits, c -> if(c.isDigit()) digits + 1 else digits } )
@@ -196,7 +196,7 @@ class StringJVMTest {
assertEquals(data, data.fold("", { s, c -> s + c }))
}
test fun foldRight() {
@test fun foldRight() {
// calculate number of digits in the string
val data = "a1b2c3def"
val result = data.foldRight(0, { c, digits -> if(c.isDigit()) digits + 1 else digits })
@@ -209,7 +209,7 @@ class StringJVMTest {
assertEquals(data, data.foldRight("", { s, c -> "" + s + c }))
}
test fun reduce() {
@test fun reduce() {
// get the smallest character(by char value)
assertEquals('a', "bacfd".reduce { v, c -> if (v > c) c else v })
@@ -218,7 +218,7 @@ class StringJVMTest {
}
}
test fun reduceRight() {
@test fun reduceRight() {
// get the smallest character(by char value)
assertEquals('a', "bacfd".reduceRight { c, v -> if (v > c) c else v })
@@ -227,7 +227,7 @@ class StringJVMTest {
}
}
test fun groupBy() {
@test fun groupBy() {
// group characters by their case
val data = "abAbaABcD"
val result = data.groupBy { it.isLowerCase() }
@@ -235,7 +235,7 @@ class StringJVMTest {
assertEquals(listOf('a','b','b','a','c'), result.get(true))
}
test fun joinToString() {
@test fun joinToString() {
val data = "abcd".toList()
val result = data.joinToString("_", "(", ")")
assertEquals("(a_b_c_d)", result)
@@ -249,7 +249,7 @@ class StringJVMTest {
assertEquals("A, 1, /, B", result3)
}
test fun join() {
@test fun join() {
val data = "abcd".map { it.toString() }
val result = data.join("_", "(", ")")
assertEquals("(a_b_c_d)", result)
@@ -259,14 +259,14 @@ class StringJVMTest {
assertEquals("[v-e-r-y-l-o-n-g-s-t-r-oops]", result2)
}
test fun dropWhile() {
@test fun dropWhile() {
val data = "ab1cd2"
assertEquals("1cd2", data.dropWhile { it.isJavaLetter() })
assertEquals("", data.dropWhile { true })
assertEquals("ab1cd2", data.dropWhile { false })
}
test fun drop() {
@test fun drop() {
val data = "abcd1234"
assertEquals("d1234", data.drop(3))
fails {
@@ -275,14 +275,14 @@ class StringJVMTest {
assertEquals("", data.drop(data.length() + 5))
}
test fun takeWhile() {
@test fun takeWhile() {
val data = "ab1cd2"
assertEquals("ab", data.takeWhile { it.isJavaLetter() })
assertEquals("", data.takeWhile { false })
assertEquals("ab1cd2", data.takeWhile { true })
}
test fun take() {
@test fun take() {
val data = "abcd1234"
assertEquals("abc", data.take(3))
fails {
@@ -291,7 +291,7 @@ class StringJVMTest {
assertEquals(data, data.take(data.length() + 42))
}
test fun formatter() {
@test fun formatter() {
assertEquals("12", "%d%d".format(1, 2))
assertEquals("1,234,567.890", "%,.3f".format(Locale.ENGLISH, 1234567.890))
@@ -299,14 +299,14 @@ class StringJVMTest {
assertEquals("1 234 567,890", "%,.3f".format(Locale("fr"), 1234567.890))
}
test fun toByteArrayEncodings() {
@test fun toByteArrayEncodings() {
val s = "hello"
val defaultCharset = java.nio.charset.Charset.defaultCharset()!!
assertEquals(String(s.toByteArray()), String(s.toByteArray(defaultCharset)))
assertEquals(String(s.toByteArray()), String(s.toByteArray(defaultCharset.name())))
}
test fun testReplaceAllClosure() {
@test fun testReplaceAllClosure() {
val s = "test123zzz"
val result = s.replace("\\d+".toRegex()) { mr ->
"[" + mr.value + "]"
@@ -314,7 +314,7 @@ class StringJVMTest {
assertEquals("test[123]zzz", result)
}
test fun testReplaceAllClosureAtStart() {
@test fun testReplaceAllClosureAtStart() {
val s = "123zzz"
val result = s.replace("\\d+".toRegex()) { mr ->
"[" + mr.value + "]"
@@ -322,7 +322,7 @@ class StringJVMTest {
assertEquals("[123]zzz", result)
}
test fun testReplaceAllClosureAtEnd() {
@test fun testReplaceAllClosureAtEnd() {
val s = "test123"
val result = s.replace("\\d+".toRegex()) { mr ->
"[" + mr.value + "]"
@@ -330,7 +330,7 @@ class StringJVMTest {
assertEquals("test[123]", result)
}
test fun testReplaceAllClosureEmpty() {
@test fun testReplaceAllClosureEmpty() {
val s = ""
val result = s.replace("\\d+".toRegex()) { mr ->
"x"
@@ -339,7 +339,7 @@ class StringJVMTest {
}
test fun slice() {
@test fun slice() {
val iter = listOf(4, 3, 0, 1)
val builder = StringBuilder()
@@ -360,7 +360,7 @@ class StringJVMTest {
}
test fun orderIgnoringCase() {
@test fun orderIgnoringCase() {
val list = listOf("Beast", "Ast", "asterisk")
assertEquals(listOf("Ast", "Beast", "asterisk"), list.sort())
assertEquals(listOf("Ast", "asterisk", "Beast"), list.sortBy(String.CASE_INSENSITIVE_ORDER))
+44 -44
View File
@@ -11,7 +11,7 @@ class IsEmptyCase(val value: String?, val isNull: Boolean = false, val isEmpty:
class StringTest {
test fun isEmptyAndBlank() {
@test fun isEmptyAndBlank() {
val cases = listOf(
IsEmptyCase(null, isNull = true),
@@ -32,7 +32,7 @@ class StringTest {
}
}
test fun startsWithString() {
@test fun startsWithString() {
assertTrue("abcd".startsWith("ab"))
assertTrue("abcd".startsWith("abcd"))
assertTrue("abcd".startsWith("a"))
@@ -46,7 +46,7 @@ class StringTest {
assertTrue("abcd".startsWith("aB", ignoreCase = true))
}
test fun endsWithString() {
@test fun endsWithString() {
assertTrue("abcd".endsWith("d"))
assertTrue("abcd".endsWith("abcd"))
assertFalse("abcd".endsWith("b"))
@@ -57,7 +57,7 @@ class StringTest {
assertTrue("".endsWith(""))
}
test fun startsWithChar() {
@test fun startsWithChar() {
assertTrue("abcd".startsWith('a'))
assertFalse("abcd".startsWith('b'))
assertFalse("abcd".startsWith('A', ignoreCase = false))
@@ -65,7 +65,7 @@ class StringTest {
assertFalse("".startsWith('a'))
}
test fun endsWithChar() {
@test fun endsWithChar() {
assertTrue("abcd".endsWith('d'))
assertFalse("abcd".endsWith('b'))
assertFalse("strö".endsWith('Ö', ignoreCase = false))
@@ -73,7 +73,7 @@ class StringTest {
assertFalse("".endsWith('a'))
}
test fun commonPrefix() {
@test fun commonPrefix() {
assertEquals("", "".commonPrefixWith(""))
assertEquals("", "any".commonPrefixWith(""))
assertEquals("", "".commonPrefixWith("any"))
@@ -90,7 +90,7 @@ class StringTest {
}
test fun commonSuffix() {
@test fun commonSuffix() {
assertEquals("", "".commonSuffixWith(""))
assertEquals("", "any".commonSuffixWith(""))
assertEquals("", "".commonSuffixWith("any"))
@@ -106,14 +106,14 @@ class StringTest {
assertEquals("$dth54", "d$dth54".commonSuffixWith("s$dth54"))
}
test fun capitalize() {
@test fun capitalize() {
assertEquals("A", "A".capitalize())
assertEquals("A", "a".capitalize())
assertEquals("Abcd", "abcd".capitalize())
assertEquals("Abcd", "Abcd".capitalize())
}
test fun decapitalize() {
@test fun decapitalize() {
assertEquals("a", "A".decapitalize())
assertEquals("a", "a".decapitalize())
assertEquals("abcd", "abcd".decapitalize())
@@ -121,7 +121,7 @@ class StringTest {
assertEquals("uRL", "URL".decapitalize())
}
test fun slice() {
@test fun slice() {
val iter = listOf(4, 3, 0, 1)
// abcde
// 01234
@@ -130,19 +130,19 @@ class StringTest {
assertEquals("edab", "abcde".slice(iter))
}
test fun reverse() {
@test fun reverse() {
assertEquals("dcba", "abcd".reversed())
assertEquals("4321", "1234".reversed())
assertEquals("", "".reversed())
}
test fun indices() {
@test fun indices() {
assertEquals(0..4, "abcde".indices)
assertEquals(0..0, "a".indices)
assertTrue("".indices.isEmpty())
}
test fun replaceRange() {
@test fun replaceRange() {
val s = "sample text"
assertEquals("sa??e text", s.replaceRange(2, 5, "??"))
assertEquals("sa?? text", s.replaceRange(2..5, "??"))
@@ -157,7 +157,7 @@ class StringTest {
assertEquals("??", s.replaceRange(s.indices, "??"))
}
test fun removeRange() {
@test fun removeRange() {
val s = "sample text"
assertEquals("sae text", s.removeRange(2, 5))
assertEquals("sa text", s.removeRange(2..5))
@@ -172,7 +172,7 @@ class StringTest {
assertEquals(s.replaceRange(2..5, ""), s.removeRange(2..5))
}
test fun substringDelimited() {
@test fun substringDelimited() {
val s = "-1,22,3+"
// chars
assertEquals("22,3+", s.substringAfter(','))
@@ -196,7 +196,7 @@ class StringTest {
}
test fun replaceDelimited() {
@test fun replaceDelimited() {
val s = "/user/folder/file.extension"
// chars
assertEquals("/user/folder/file.doc", s.replaceAfter('.', "doc"))
@@ -219,14 +219,14 @@ class StringTest {
assertEquals("xxx", s.replaceBeforeLast("=", "/new/path", "xxx"))
}
test fun stringIterator() {
@test fun stringIterator() {
var sum = 0
for(c in "239")
sum += (c.toInt() - '0'.toInt())
assertTrue(sum == 14)
}
test fun trimStart() {
@test fun trimStart() {
assertEquals("", "".trimStart())
assertEquals("a", "a".trimStart())
assertEquals("a", " a".trimStart())
@@ -245,7 +245,7 @@ class StringTest {
assertEquals("123a", "ab123a".trimStart { it < '0' || it > '9' }) // TODO: Use !it.isDigit when available in JS
}
test fun trimEnd() {
@test fun trimEnd() {
assertEquals("", "".trimEnd())
assertEquals("a", "a".trimEnd())
assertEquals("a", "a ".trimEnd())
@@ -264,7 +264,7 @@ class StringTest {
assertEquals("ab123", "ab123a".trimEnd { it < '0' || it > '9' }) // TODO: Use !it.isDigit when available in JS
}
test fun trimStartAndEnd() {
@test fun trimStartAndEnd() {
val examples = arrayOf("a",
" a ",
" a ",
@@ -293,7 +293,7 @@ class StringTest {
}
}
test fun padStart() {
@test fun padStart() {
assertEquals("s", "s".padStart(0))
assertEquals("s", "s".padStart(1))
assertEquals(" ", "".padStart(2))
@@ -303,7 +303,7 @@ class StringTest {
}
}
test fun padEnd() {
@test fun padEnd() {
assertEquals("s", "s".padEnd(0))
assertEquals("s", "s".padEnd(1))
assertEquals(" ", "".padEnd(2))
@@ -313,21 +313,21 @@ class StringTest {
}
}
test fun removePrefix() {
@test fun removePrefix() {
assertEquals("fix", "prefix".removePrefix("pre"), "Removes prefix")
assertEquals("prefix", "preprefix".removePrefix("pre"), "Removes prefix once")
assertEquals("sample", "sample".removePrefix("value"))
assertEquals("sample", "sample".removePrefix(""))
}
test fun removeSuffix() {
@test fun removeSuffix() {
assertEquals("suf", "suffix".removeSuffix("fix"), "Removes suffix")
assertEquals("suffix", "suffixfix".removeSuffix("fix"), "Removes suffix once")
assertEquals("sample", "sample".removeSuffix("value"))
assertEquals("sample", "sample".removeSuffix(""))
}
test fun removeSurrounding() {
@test fun removeSurrounding() {
assertEquals("value", "<value>".removeSurrounding("<", ">"))
assertEquals("<value>", "<<value>>".removeSurrounding("<", ">"), "Removes surrounding once")
assertEquals("<value", "<value".removeSurrounding("<", ">"), "Only removes surrounding when both prefix and suffix present")
@@ -353,7 +353,7 @@ class StringTest {
*/
test fun split() {
@test fun split() {
assertEquals(listOf(""), "".split(";"))
assertEquals(listOf("test"), "test".split(*charArrayOf()), "empty list of delimiters, none matched -> entire string returned")
assertEquals(listOf("test"), "test".split(*arrayOf<String>()), "empty list of delimiters, none matched -> entire string returned")
@@ -368,7 +368,7 @@ class StringTest {
assertEquals(listOf("", "", "b", "b", "", ""), "abba".split("a", ""))
}
test fun splitToLines() {
@test fun splitToLines() {
val string = "first line\rsecond line\nthird line\r\nlast line"
assertEquals(listOf("first line", "second line", "third line", "last line"), string.lines())
@@ -378,7 +378,7 @@ class StringTest {
}
test fun indexOfAnyChar() {
@test fun indexOfAnyChar() {
val string = "abracadabra"
val chars = charArrayOf('d', 'b')
assertEquals(1, string.indexOfAny(chars))
@@ -392,7 +392,7 @@ class StringTest {
assertEquals(-1, string.indexOfAny(charArrayOf()))
}
test fun indexOfAnyCharIgnoreCase() {
@test fun indexOfAnyCharIgnoreCase() {
val string = "abraCadabra"
val chars = charArrayOf('B', 'c')
assertEquals(1, string.indexOfAny(chars, ignoreCase = true))
@@ -404,7 +404,7 @@ class StringTest {
assertEquals(-1, string.lastIndexOfAny(chars, startIndex = 0, ignoreCase = true))
}
test fun indexOfAnyString() {
@test fun indexOfAnyString() {
val string = "abracadabra"
val substrings = listOf("rac", "ra")
assertEquals(2, string.indexOfAny(substrings))
@@ -421,7 +421,7 @@ class StringTest {
assertEquals(-1, string.indexOfAny(listOf()))
}
test fun indexOfAnyStringIgnoreCase() {
@test fun indexOfAnyStringIgnoreCase() {
val string = "aBraCadaBrA"
val substrings = listOf("rAc", "Ra")
@@ -434,7 +434,7 @@ class StringTest {
assertEquals(-1, string.lastIndexOfAny(substrings, startIndex = 1, ignoreCase = true))
}
test fun findAnyOfStrings() {
@test fun findAnyOfStrings() {
val string = "abracadabra"
val substrings = listOf("rac", "ra")
assertEquals(2 to "rac", string.findAnyOf(substrings))
@@ -451,7 +451,7 @@ class StringTest {
assertEquals(null, string.findAnyOf(listOf()))
}
test fun findAnyOfStringsIgnoreCase() {
@test fun findAnyOfStringsIgnoreCase() {
val string = "aBraCadaBrA"
val substrings = listOf("rAc", "Ra")
@@ -464,7 +464,7 @@ class StringTest {
assertEquals(null, string.findLastAnyOf(substrings, startIndex = 1, ignoreCase = true))
}
test fun indexOfChar() {
@test fun indexOfChar() {
val string = "bcedef"
assertEquals(-1, string.indexOf('a'))
assertEquals(2, string.indexOf('e'))
@@ -480,7 +480,7 @@ class StringTest {
}
test fun indexOfCharIgnoreCase() {
@test fun indexOfCharIgnoreCase() {
val string = "bCEdef"
assertEquals(-1, string.indexOf('a', ignoreCase = true))
assertEquals(2, string.indexOf('E', ignoreCase = true))
@@ -496,7 +496,7 @@ class StringTest {
}
}
test fun indexOfString() {
@test fun indexOfString() {
val string = "bceded"
for (index in string.indices)
assertEquals(index, string.indexOf("", index))
@@ -505,7 +505,7 @@ class StringTest {
assertEquals(-1, string.indexOf("abcdefgh"))
}
test fun indexOfStringIgnoreCase() {
@test fun indexOfStringIgnoreCase() {
val string = "bceded"
for (index in string.indices)
assertEquals(index, string.indexOf("", index, ignoreCase = true))
@@ -515,7 +515,7 @@ class StringTest {
}
test fun contains() {
@test fun contains() {
assertTrue("pl" in "sample")
assertFalse("PL" in "sample")
assertTrue("sömple".contains("Ö", ignoreCase = true))
@@ -528,13 +528,13 @@ class StringTest {
assertTrue("sömple".contains('Ö', ignoreCase = true))
}
test fun equalsIgnoreCase() {
@test fun equalsIgnoreCase() {
assertFalse("sample".equals("Sample", ignoreCase = false))
assertTrue("sample".equals("Sample", ignoreCase = true))
}
test fun replace() {
@test fun replace() {
val input = "abbAb"
assertEquals("abb${'$'}b", input.replace('A', '$'))
assertEquals("/bb/b", input.replace('A', '/', ignoreCase = true))
@@ -545,7 +545,7 @@ class StringTest {
assertEquals("-a-b-b-A-b-", input.replace("", "-"))
}
test fun replaceFirst() {
@test fun replaceFirst() {
val input = "AbbabA"
assertEquals("Abb${'$'}bA", input.replaceFirst('a','$'))
assertEquals("${'$'}bbabA", input.replaceFirst('a','$', ignoreCase = true))
@@ -558,7 +558,7 @@ class StringTest {
assertEquals("-test", "test".replaceFirst("", "-"))
}
test fun trimMargin() {
@test fun trimMargin() {
// WARNING
// DO NOT REFORMAT AS TESTS MAY FAIL DUE TO INDENTATION CHANGE
@@ -605,7 +605,7 @@ class StringTest {
assertEquals("\u0000|ABC", "${"\u0000"}|ABC".trimMargin())
}
test fun trimIndent() {
@test fun trimIndent() {
// WARNING
// DO NOT REFORMAT AS TESTS MAY FAIL DUE TO INDENTATION CHANGE
@@ -669,7 +669,7 @@ ${" "}
assertEquals(1, deindented.lines().count { it.isEmpty() })
}
test fun testIndent() {
@test fun testIndent() {
assertEquals(" ABC\n 123", "ABC\n123".prependIndent(" "))
assertEquals(" ABC\n \n 123", "ABC\n\n123".prependIndent(" "))
assertEquals(" ABC\n \n 123", "ABC\n \n123".prependIndent(" "))
+1 -1
View File
@@ -5,7 +5,7 @@ import kotlin.test.*
import org.junit.Test as test
class StringUtilTest() {
test fun toPattern() {
@test fun toPattern() {
val re = """foo""".toPattern()
val list = re.split("hellofoobar").toList()
assertEquals(listOf("hello", "bar"), list)
+1 -1
View File
@@ -8,7 +8,7 @@ import org.junit.Test as test
class LazyJVMTest {
test fun lazyInitializationForcedOnSerialization() {
@test fun lazyInitializationForcedOnSerialization() {
for(mode in listOf(LazyThreadSafetyMode.SYNCHRONIZED, LazyThreadSafetyMode.NONE)) {
val lazy = lazy(mode) { "initialized" }
assertFalse(lazy.isInitialized())
+3 -3
View File
@@ -6,7 +6,7 @@ import org.junit.Test as test
class LazyTest {
test fun initializationCalledOnce() {
@test fun initializationCalledOnce() {
var callCount = 0
val lazyInt = lazy { ++callCount }
@@ -20,7 +20,7 @@ class LazyTest {
assertEquals(1, callCount)
}
test fun alreadyInitialized() {
@test fun alreadyInitialized() {
val lazyInt = lazyOf(1)
assertTrue(lazyInt.isInitialized())
@@ -28,7 +28,7 @@ class LazyTest {
}
test fun lazyToString() {
@test fun lazyToString() {
var callCount = 0
val lazyInt = lazy { ++callCount }
+1 -1
View File
@@ -37,7 +37,7 @@ class TODOTest {
}
test fun usage() {
@test fun usage() {
val inst = PartiallyImplementedClass()
assertNotImplemented { inst.prop }