Clean warnings and refactor stdlib tests.

Merge RangeJVMTest into RangeTest.
This commit is contained in:
Ilya Gorbunov
2017-04-12 09:23:57 +03:00
parent ac46f1e23d
commit 6ae19e03d5
32 changed files with 133 additions and 124 deletions
+1 -2
View File
@@ -17,8 +17,7 @@
package kotlin.test
public fun assertTypeEquals(expected: Any?, actual: Any?) {
//TODO: find analogue
//assertEquals(expected?.javaClass, actual?.javaClass)
assertEquals(expected?.let { it::class.js }, actual?.let { it::class.js })
}
internal inline fun String.removeLeadingPlusOnJava6(): String = this
@@ -61,6 +61,7 @@ public abstract class JsUnitTestBase extends MultipleFilesTranslationTest {
protected List<String> additionalKotlinFiles() {
List<String> result = StdLibTestBase.removeAdHocAssertions(super.additionalKotlinFiles());
result.add(JS_TESTS_KT);
result.add("libraries/stdlib/test/testUtils.kt");
return result;
}
@@ -31,6 +31,7 @@ public class StdLibTestToJSTest extends StdLibQUnitTestSupport {
"collections/IteratorsTest.kt",
"collections/CollectionBehaviors.kt",
"collections/ComparisonDSL.kt",
"testUtils.kt",
"../../../js/js.libraries/test/core/testUtils.kt",
"text/StringTest.kt",
"OrderingTest.kt",
@@ -55,8 +55,8 @@ class TryWithResourcesAutoCloseableTest {
@Test fun opFailsCloseFailsTwice() {
val e = assertFails {
Resource(faultyClose = true).use { res1 ->
Resource(faultyClose = true).use { res2 ->
Resource(faultyClose = true).use { _ ->
Resource(faultyClose = true).use { _ ->
error("op fail")
}
}
@@ -56,8 +56,8 @@ class TryWithResourcesCloseableTest {
@Ignore
@Test fun opFailsCloseFailsTwice() {
val e = assertFails {
Resource(faultyClose = true).use { res1 ->
Resource(faultyClose = true).use { res2 ->
Resource(faultyClose = true).use { _ ->
Resource(faultyClose = true).use { _ ->
error("op fail")
}
}
@@ -89,27 +89,27 @@ class MapTest {
val map = mutableMapOf(2 to "x")
assertEquals("2x", map.computeIfPresent(2) { k, v -> k.toString() + v })
assertEquals(null, map.computeIfPresent(3) { k, v -> k.toString() + v })
assertEquals(null, map.computeIfPresent(2) { k, v -> null })
assertEquals(null, map.computeIfPresent(2) { _, _ -> null })
assertFalse(2 in map)
val map2 = mutableMapOf<Int, String?>(2 to "x")
assertEquals("2x", map2.computeIfPresent(2) { k, v -> k.toString() + v })
assertEquals(null, map2.computeIfPresent(3) { k, v -> k.toString() + v })
assertEquals(null, map2.computeIfPresent(2) { k, v -> null })
assertEquals(null, map2.computeIfPresent(2) { _, _ -> null })
assertFalse(2 in map2)
}
@Test fun compute() {
val map = mutableMapOf(2 to "x")
assertEquals("2x", map.compute(2) { k, v -> k.toString() + v })
assertEquals(null, map.compute(2) { k, v -> null })
assertEquals(null, map.compute(2) { _, _ -> null })
assertFalse { 2 in map }
assertEquals("1null", map.compute(1) { k, v -> k.toString() + v })
}
@Test fun merge() {
val map = mutableMapOf(2 to "x")
assertEquals("y", map.merge(3, "y") { old, new -> null })
assertEquals("y", map.merge(3, "y") { _, _ -> null })
assertEquals(null, map.merge(3, "z") { old, new ->
assertEquals("y", old)
assertEquals("z", new)
@@ -122,7 +122,7 @@ class MapTest {
// new value must be V&Any
assertEquals("e", map2.merge(1, "e") { old, new -> (old.length + new.length).toString() ?: null })
assertEquals("3", map2.merge(1, "fg") { old, new -> (old.length + new.length).toString() ?: null })
assertEquals(null, map2.merge(1, "3") { old, new -> null })
assertEquals(null, map2.merge(1, "3") { _, _ -> null })
assertFalse(1 in map)
}
}
@@ -760,7 +760,7 @@ class ArraysTest {
expect(1.toShort()) { shortArrayOf(3, 2, 1).reduceIndexed { index, a, b -> if (index != 2) (a - b).toShort() else a.toShort() } }
assertFailsWith<UnsupportedOperationException> {
intArrayOf().reduceIndexed { index, a, b -> a + b }
intArrayOf().reduceIndexed { index, a, b -> index + a + b }
}
}
@@ -776,7 +776,7 @@ class ArraysTest {
expect(1.toShort()) { shortArrayOf(3, 2, 1).reduceRightIndexed { index, a, b -> if (index != 1) (a - b).toShort() else a.toShort() } }
assertFailsWith<UnsupportedOperationException> {
intArrayOf().reduceRightIndexed { index, a, b -> a + b }
intArrayOf().reduceRightIndexed { index, a, b -> index + a + b }
}
}
@@ -1056,6 +1056,7 @@ class ArraysTest {
val arr1: Array<Array<Int>> = arrayOf(arrayOf(1, 2, 3), arrayOf(4, 5, 6))
val arr2: Array<out Array<Int>> = arr1
val arr3: Array<out Array<out Int>> = arr1
@Suppress("UNCHECKED_CAST")
val arr4: Array<Array<out Int>> = arr1 as Array<Array<out Int>>
val expected = listOf(1, 2, 3, 4, 5, 6)
@@ -215,8 +215,3 @@ class CollectionJVMTest {
assertEquals(expected, actual)
}
}
public fun assertTypeEquals(expected: Any?, actual: Any?) {
assertEquals(expected?.javaClass, actual?.javaClass)
}
@@ -295,7 +295,7 @@ class CollectionTest {
}
assertFailsWith<UnsupportedOperationException> {
arrayListOf<Int>().reduceIndexed { index, a, b -> a + b }
arrayListOf<Int>().reduceIndexed { index, a, b -> index + a + b }
}
}
@@ -315,7 +315,7 @@ class CollectionTest {
}
assertFailsWith<UnsupportedOperationException> {
arrayListOf<Int>().reduceRightIndexed { index, a, b -> a + b }
arrayListOf<Int>().reduceRightIndexed { index, a, b -> index + a + b }
}
}
@@ -626,6 +626,7 @@ class CollectionTest {
// lists throw an exception if out of range
assertFails {
@Suppress("UNUSED_VARIABLE")
val outOfBounds = list[2]
}
@@ -1,5 +1,6 @@
package test.collections
import test.*
import kotlin.test.*
public fun <T> compare(expected: T, actual: T, block:CompareContext<T>.() -> Unit) {
@@ -54,7 +54,7 @@ class GroupingTest {
val elements = listOf("foo", "bar", "flea", "zoo", "biscuit")
val result = elements.groupingBy { it.first() }
.fold({ k, e -> Collector<Char, String>(k)}, { k, acc, e -> acc.accumulateIfEven(e) })
.fold({ k, _ -> Collector<Char, String>(k)}, { _, acc, e -> acc.accumulateIfEven(e) })
val ordered = result.values.sortedBy { it.key }.map { it.toPair() }
assertEquals(listOf('b' to emptyList(), 'f' to listOf("flea"), 'z' to emptyList()), ordered)
@@ -62,8 +62,8 @@ class GroupingTest {
val moreElements = listOf("fire", "zero")
val result2 = moreElements.groupingBy { it.first() }
.foldTo(HashMap(result),
{ k, e -> error("should not be called for $k") },
{ k, acc, e -> acc.accumulateIfEven(e) })
{ k, _ -> error("should not be called for $k") },
{ _, acc, e -> acc.accumulateIfEven(e) })
val ordered2 = result2.values.sortedBy { it.key }.map { it.toPair() }
assertEquals(listOf('b' to emptyList(), 'f' to listOf("flea", "fire"), 'z' to listOf("zero")), ordered2)
@@ -75,12 +75,12 @@ class GroupingTest {
val elements = listOf("foo", "bar", "flea", "zoo", "biscuit")
fun Char.isVowel() = this in "aeiou"
fun String.countVowels() = count(Char::isVowel)
val maxVowels = elements.groupingBy { it.first() }.reduce { k, a, b -> maxOfBy(a, b, String::countVowels) }
val maxVowels = elements.groupingBy { it.first() }.reduce { _, a, b -> maxOfBy(a, b, String::countVowels) }
assertEquals(mapOf('f' to "foo", 'b' to "biscuit", 'z' to "zoo"), maxVowels)
val elements2 = listOf("bar", "z", "fork")
val concats = elements2.groupingBy { it.first() }.reduceTo(HashMap(maxVowels)) { k, acc, e -> acc + e }
val concats = elements2.groupingBy { it.first() }.reduceTo(HashMap(maxVowels)) { _, acc, e -> acc + e }
assertEquals(mapOf('f' to "foofork", 'b' to "biscuitbar", 'z' to "zooz"), concats)
}
@@ -17,6 +17,7 @@
package test.collections
import org.junit.Test
import test.*
import kotlin.test.*
fun <T> iterableOf(vararg items: T): Iterable<T> = Iterable { items.iterator() }
@@ -200,7 +201,7 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
assertTrue(data === newData)
// static types test
val list: ArrayList<Int> = arrayListOf(1, 2, 3).onEach { }
assertStaticTypeIs<ArrayList<Int>>(arrayListOf(1, 2, 3).onEach { })
}
@Test
+4 -4
View File
@@ -1,13 +1,11 @@
package test.collections
import kotlin.test.*
import test.*
import org.junit.Test
class MapTest {
// just a static type check
fun <T> assertStaticTypeIs(value: T) {}
@Test fun getOrElse() {
val data = mapOf<String, Int>()
val a = data.getOrElse("foo") { 2 }
@@ -109,7 +107,9 @@ class MapTest {
assertTrue(map === newMap)
// static types test
val m: HashMap<String, String> = hashMapOf("a" to "b").onEach { }
assertStaticTypeIs<HashMap<String, String>>(
hashMapOf("a" to "b").onEach { }
)
}
@Test fun stream() {
@@ -39,7 +39,7 @@ public class SequenceTest {
}
@Test fun filterIndexed() {
assertEquals(listOf(1, 2, 5, 13, 34), fibonacci().filterIndexed { index, value -> index % 2 == 1 }.take(5).toList())
assertEquals(listOf(1, 2, 5, 13, 34), fibonacci().filterIndexed { index, _ -> index % 2 == 1 }.take(5).toList())
}
@Test fun filterNullable() {
@@ -16,7 +16,7 @@ class TimerTest {
val task = timer.scheduleAtFixedRate(1000, 100) {
val current = counter.incrementAndGet()
// println("Timer fired at $current")
if (false) println("Timer fired at $current")
}
Thread.sleep(1500)
task.cancel()
+4 -4
View File
@@ -229,10 +229,10 @@ class FileTreeWalkTest {
val basedir = createTestFiles()
try {
var i = 0
basedir.walkTopDown().forEach { it -> i++ }
basedir.walkTopDown().forEach { _ -> i++ }
assertEquals(10, i);
i = 0
basedir.walkBottomUp().forEach { it -> i++ }
basedir.walkBottomUp().forEach { _ -> i++ }
assertEquals(10, i);
} finally {
basedir.deleteRecursively()
@@ -282,7 +282,7 @@ class FileTreeWalkTest {
files.add(file.relativeToOrSelf(basedir))
}
fun visitDirectoryFailed(dir: File, e: IOException) {
fun visitDirectoryFailed(dir: File, @Suppress("UNUSED_PARAMETER") e: IOException) {
assertEquals(stack.last(), dir)
//stack.removeAt(stack.lastIndex)
failed.add(dir.name)
@@ -405,7 +405,7 @@ class FileTreeWalkTest {
try {
File(basedir, "8/4.txt").createNewFile()
var count = 0
basedir.walkTopDown().takeWhile { it -> count == 0 }.forEach {
basedir.walkTopDown().takeWhile { _ -> count == 0 }.forEach {
if (it.name == "4.txt") {
count++
}
+8 -8
View File
@@ -141,6 +141,7 @@ class FilesTest {
assertEquals("", file.toRelativeString(file), "file should have empty path relative to itself: $file")
for (file in files) {
@Suppress("NAME_SHADOWING")
for (base in bases) {
val rootedFile = root.resolve(file)
val rootedBase = root.resolve(base)
@@ -158,7 +159,9 @@ class FilesTest {
fun assertFailsRelativeTo(file: File, base: File) {
val e = assertFailsWith<IllegalArgumentException>("file: $file, base: $base") { file.relativeTo(base) }
// println(e.message)
val message = assertNotNull(e.message)
assert(file.toString() in message)
assert(base.toString() in message)
}
val allFiles = listOf(absolute, relative) + if (isBackslashSeparator) listOf(networkShare1, networkShare2) else emptyList()
@@ -220,7 +223,7 @@ class FilesTest {
if (isBackslashSeparator) {
val diskRooted = File("""C:\foo\bar""")
assertTrue(rooted.isRooted)
assertTrue(diskRooted.isRooted)
// assertEquals("""C:\""", diskRooted.rootName)
val networkRooted = File("""\\network\share\""")
@@ -516,7 +519,7 @@ class FilesTest {
var conflicts = 0
src.copyRecursively(dst) {
file: File, e: IOException ->
_: File, e: IOException ->
if (e is FileAlreadyExistsException) {
conflicts++
OnErrorAction.SKIP
@@ -531,7 +534,7 @@ class FilesTest {
dst.deleteRecursively()
var caught = false
assertTrue(src.copyRecursively(dst) {
file: File, e: IOException ->
_: File, e: IOException ->
if (e is AccessDeniedException) {
caught = true
OnErrorAction.SKIP
@@ -552,10 +555,7 @@ class FilesTest {
src.copyRecursively(dst)
}
assertFalse(src.copyRecursively(dst) {
file: File, e: IOException ->
OnErrorAction.TERMINATE
})
assertFalse(src.copyRecursively(dst) { _, _ -> OnErrorAction.TERMINATE })
} finally {
src.deleteRecursively()
dst.deleteRecursively()
+1 -1
View File
@@ -143,7 +143,7 @@ class ReadWriteTest {
}
@Test fun testPlatformNullUse() {
fun <T> platformNull() = java.util.Collections.singleton(null as T).first()
fun <T> platformNull() = @Suppress("UNCHECKED_CAST") java.util.Collections.singleton(null as T).first()
val resource = platformNull<java.io.Closeable>()
val result = resource.use {
"ok"
+1
View File
@@ -11,6 +11,7 @@ class ComplexMapJsTest : MapJsTest() {
HashMap<K, Int>()
HashMap<K, Int>(3)
HashMap<K, Int>(3, 0.5f)
@Suppress("UNCHECKED_CAST")
val map = HashMap<K, Int>(createTestMap() as HashMap<K, Int>)
assertEquals(KEYS.toNormalizedList(), map.keys.toNormalizedList() as List<Any>)
+1
View File
@@ -12,6 +12,7 @@ class ComplexSetJsTest : SetJsTest() {
HashSet<T>(3)
HashSet<T>(3, 0.5f)
@Suppress("UNCHECKED_CAST")
val set = HashSet<T>(data as HashSet<T>)
assertEquals(data, set)
@@ -24,6 +24,7 @@ import org.junit.Test
class CompanionIntrinsicObjectsJVMTest {
@Test fun intTest() {
val i = Int
i.MAX_VALUE
assertEquals(java.lang.Integer.MAX_VALUE, Int.MAX_VALUE)
assertEquals(java.lang.Integer.MIN_VALUE, Int.MIN_VALUE)
@@ -31,6 +32,7 @@ class CompanionIntrinsicObjectsJVMTest {
@Test fun doubleTest() {
val d = Double
d.NaN
assertEquals(java.lang.Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY)
assertEquals(java.lang.Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY)
@@ -42,6 +44,7 @@ class CompanionIntrinsicObjectsJVMTest {
@Test fun floatTest() {
val f = Float
f.NEGATIVE_INFINITY
assertEquals(java.lang.Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY)
assertEquals(java.lang.Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY)
@@ -53,6 +56,7 @@ class CompanionIntrinsicObjectsJVMTest {
@Test fun longTest() {
val l = Long
l.MAX_VALUE
assertEquals(java.lang.Long.MAX_VALUE, Long.MAX_VALUE)
assertEquals(java.lang.Long.MIN_VALUE, Long.MIN_VALUE)
@@ -60,6 +64,7 @@ class CompanionIntrinsicObjectsJVMTest {
@Test fun shortTest() {
val s = Short
s.MIN_VALUE
assertEquals(java.lang.Short.MAX_VALUE, Short.MAX_VALUE)
assertEquals(java.lang.Short.MIN_VALUE, Short.MIN_VALUE)
@@ -67,6 +72,7 @@ class CompanionIntrinsicObjectsJVMTest {
@Test fun byteTest() {
val b = Byte
b.MAX_VALUE
assertEquals(java.lang.Byte.MAX_VALUE, Byte.MAX_VALUE)
assertEquals(java.lang.Byte.MIN_VALUE, Byte.MIN_VALUE)
@@ -74,12 +80,14 @@ class CompanionIntrinsicObjectsJVMTest {
@Test fun charTest() {
val ch = Char
ch.MIN_SURROGATE
assertEquals(ch, Char)
}
@Test fun stringTest() {
val s = String
s.CASE_INSENSITIVE_ORDER
assertEquals(s, String)
}
@@ -27,6 +27,7 @@ class ObservablePropertyTest {
var b: Int by Delegates.observable(1, { property, old, new ->
assertEquals("b", property.name)
if (!result) assertEquals(1, old)
result = true
assertEquals(new, b, "New value has already been set")
})
@@ -5,17 +5,6 @@ import kotlin.test.*
class CoercionTest {
fun usage() {
val n = 1
// infix usage
val n1 = n.coerceAtLeast(2)
// function usage
val n2 = n.coerceAtLeast(2)
// infix with range
val n3 = n.coerceIn(2..5)
}
@Test
fun coercionsInt() {
expect(5) { 5.coerceAtLeast(1) }
@@ -1,60 +0,0 @@
@file:kotlin.jvm.JvmVersion
package test.ranges
import java.lang.Double as jDouble
import java.lang.Float as jFloat
import org.junit.Test
import kotlin.test.*
public class RangeJVMTest {
@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() {
val range = -1.0f..3.14159f
assertFalse(jFloat.NEGATIVE_INFINITY in range)
assertFalse(jFloat.POSITIVE_INFINITY in range)
assertFalse(jFloat.NaN in range)
}
@Test fun illegalProgressionCreation() {
fun assertFailsWithIllegalArgument(f: () -> Unit) = assertFailsWith(IllegalArgumentException::class, block = f)
// create Progression explicitly with increment = 0
assertFailsWithIllegalArgument { IntProgression.fromClosedRange(0, 5, 0) }
assertFailsWithIllegalArgument { LongProgression.fromClosedRange(0, 5, 0) }
assertFailsWithIllegalArgument { CharProgression.fromClosedRange('a', 'z', 0) }
assertFailsWithIllegalArgument { 0..5 step 0 }
assertFailsWithIllegalArgument { 0.toByte()..5.toByte() step 0 }
assertFailsWithIllegalArgument { 0.toShort()..5.toShort() step 0 }
assertFailsWithIllegalArgument { 0L..5L step 0L }
assertFailsWithIllegalArgument { 'a'..'z' step 0 }
assertFailsWithIllegalArgument { 0 downTo -5 step 0 }
assertFailsWithIllegalArgument { 0.toByte() downTo -5.toByte() step 0 }
assertFailsWithIllegalArgument { 0.toShort() downTo -5.toShort() step 0 }
assertFailsWithIllegalArgument { 0L downTo -5L step 0L }
assertFailsWithIllegalArgument { 'z' downTo 'a' step 0 }
assertFailsWithIllegalArgument { 0..5 step -2 }
assertFailsWithIllegalArgument { 0.toByte()..5.toByte() step -2 }
assertFailsWithIllegalArgument { 0.toShort()..5.toShort() step -2 }
assertFailsWithIllegalArgument { 0L..5L step -2L }
assertFailsWithIllegalArgument { 'a'..'z' step -2 }
assertFailsWithIllegalArgument { 0 downTo -5 step -2 }
assertFailsWithIllegalArgument { 0.toByte() downTo -5.toByte() step -2 }
assertFailsWithIllegalArgument { 0.toShort() downTo -5.toShort() step -2 }
assertFailsWithIllegalArgument { 0L downTo -5L step -2L }
assertFailsWithIllegalArgument { 'z' downTo 'a' step -2 }
}
}
+35
View File
@@ -341,4 +341,39 @@ public class RangeTest {
assertFalse(range.isEmpty())
}
private fun assertFailsWithIllegalArgument(f: () -> Unit) = assertFailsWith<IllegalArgumentException> { f() }
@Test fun illegalProgressionCreation() {
// create Progression explicitly with increment = 0
assertFailsWithIllegalArgument { IntProgression.fromClosedRange(0, 5, 0) }
assertFailsWithIllegalArgument { LongProgression.fromClosedRange(0, 5, 0) }
assertFailsWithIllegalArgument { CharProgression.fromClosedRange('a', 'z', 0) }
assertFailsWithIllegalArgument { 0..5 step 0 }
assertFailsWithIllegalArgument { 0.toByte()..5.toByte() step 0 }
assertFailsWithIllegalArgument { 0.toShort()..5.toShort() step 0 }
assertFailsWithIllegalArgument { 0L..5L step 0L }
assertFailsWithIllegalArgument { 'a'..'z' step 0 }
assertFailsWithIllegalArgument { 0 downTo -5 step 0 }
assertFailsWithIllegalArgument { 0.toByte() downTo -5.toByte() step 0 }
assertFailsWithIllegalArgument { 0.toShort() downTo -5.toShort() step 0 }
assertFailsWithIllegalArgument { 0L downTo -5L step 0L }
assertFailsWithIllegalArgument { 'z' downTo 'a' step 0 }
assertFailsWithIllegalArgument { 0..5 step -2 }
assertFailsWithIllegalArgument { 0.toByte()..5.toByte() step -2 }
assertFailsWithIllegalArgument { 0.toShort()..5.toShort() step -2 }
assertFailsWithIllegalArgument { 0L..5L step -2L }
assertFailsWithIllegalArgument { 'a'..'z' step -2 }
assertFailsWithIllegalArgument { 0 downTo -5 step -2 }
assertFailsWithIllegalArgument { 0.toByte() downTo -5.toByte() step -2 }
assertFailsWithIllegalArgument { 0.toShort() downTo -5.toShort() step -2 }
assertFailsWithIllegalArgument { 0L downTo -5L step -2L }
assertFailsWithIllegalArgument { 'z' downTo 'a' step -2 }
}
}
@@ -1,4 +1,5 @@
@file:kotlin.jvm.JvmVersion
@file:Suppress("DEPRECATION", "DEPRECATED_JAVA_ANNOTATION")
package test.reflection
import kotlin.test.*
+4
View File
@@ -0,0 +1,4 @@
package test
// just a static type check
fun <T> assertStaticTypeIs(@Suppress("UNUSED_PARAMETER") value: T) {}
+24
View File
@@ -0,0 +1,24 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package test
import kotlin.test.assertEquals
@JvmVersion
public fun assertTypeEquals(expected: Any?, actual: Any?) {
assertEquals(expected?.javaClass, actual?.javaClass)
}
@@ -10,6 +10,7 @@ class StringBuilderJVMTest() {
val s = buildString(123) {
assertEquals(123, capacity())
}
assertEquals("", s)
}
@Test fun getAndSetChar() {
+8 -7
View File
@@ -17,6 +17,7 @@
package test.text
import kotlin.test.*
import test.*
import org.junit.Test
@@ -761,8 +762,8 @@ class StringTest {
assertTrue(data === newData)
// static types test
val s: String = "x".onEach { }
val sb: StringBuilder = result.onEach { }
assertStaticTypeIs<String>("x".onEach { })
assertStaticTypeIs<StringBuilder>(result.onEach { })
}
@@ -913,7 +914,7 @@ class StringTest {
}
assertFailsWith<UnsupportedOperationException> {
arg1("").reduceIndexed { index, a, b -> '\n' }
arg1("").reduceIndexed { _, _, _ -> '\n' }
}
}
@@ -931,7 +932,7 @@ class StringTest {
}
assertFailsWith<UnsupportedOperationException> {
arg1("").reduceRightIndexed { index, a, b -> '\n' }
arg1("").reduceRightIndexed { _, _, _ -> '\n' }
}
}
@@ -940,7 +941,7 @@ class StringTest {
assertEquals('a', arg1("bacfd").reduce { v, c -> if (v > c) c else v })
assertFailsWith<UnsupportedOperationException> {
arg1("").reduce { a, b -> '\n' }
arg1("").reduce { _, _ -> '\n' }
}
}
@@ -949,7 +950,7 @@ class StringTest {
assertEquals('a', arg1("bacfd").reduceRight { c, v -> if (v > c) c else v })
assertFailsWith<UnsupportedOperationException> {
arg1("").reduceRight { a, b -> '\n' }
arg1("").reduceRight { _, _ -> '\n' }
}
}
@@ -1067,7 +1068,7 @@ class StringTest {
}
@Test fun testReplaceAllClosureEmpty() = withOneCharSequenceArg("") { s ->
val result = s.replace("\\d+".toRegex()) { mr ->
val result = s.replace("\\d+".toRegex()) { _ ->
"x"
}
assertEquals("", result)
+3 -1
View File
@@ -47,6 +47,7 @@ class LazyJVMTest {
accessThreads.forEach { it.join() }
assertEquals(2, counter.get())
@Suppress("NAME_SHADOWING")
for ((counter, initialized) in runs) {
assertEquals(initialized, counter == 2, "Expected uninitialized on first, initialized on second call: initialized=$initialized, counter=$counter")
}
@@ -71,7 +72,8 @@ class LazyJVMTest {
assertEquals(2, counter.get())
assertEquals(2, lazy.value)
for ((counter, initialized) in runs) {
@Suppress("NAME_SHADOWING")
for ((_, initialized) in runs) {
assertFalse(initialized, "Expected uninitialized on first and second run")
}
}
+1
View File
@@ -23,6 +23,7 @@ import org.junit.Test
class TODOTest {
private class PartiallyImplementedClass {
public val prop: String get() = TODO()
@Suppress("UNREACHABLE_CODE", "CAST_NEVER_SUCCEEDS")
fun method1() = TODO() as String
public fun method2(): Int = TODO()