Fix warnings in stdlib samples and test modules
This commit is contained in:
@@ -33,7 +33,7 @@ class UseAutoCloseableResourceTest {
|
|||||||
|
|
||||||
@Test fun closeFails() {
|
@Test fun closeFails() {
|
||||||
val e = assertFails {
|
val e = assertFails {
|
||||||
Resource(faultyClose = true).use { "" }
|
Resource(faultyClose = true).use { it.isClosed }
|
||||||
}
|
}
|
||||||
assertTrue(e is IOException)
|
assertTrue(e is IOException)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class UseCloseableResourceTest {
|
|||||||
|
|
||||||
@Test fun closeFails() {
|
@Test fun closeFails() {
|
||||||
val e = assertFails {
|
val e = assertFails {
|
||||||
Resource(faultyClose = true).use { "" }
|
Resource(faultyClose = true).use { it.isClosed }
|
||||||
}
|
}
|
||||||
assertTrue(e is IOException)
|
assertTrue(e is IOException)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,6 +123,7 @@ class MapTest {
|
|||||||
assertEquals("1null", map.compute(1) { k, v -> k.toString() + v })
|
assertEquals("1null", map.compute(1) { k, v -> k.toString() + v })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("USELESS_CAST")
|
||||||
@Test fun merge() {
|
@Test fun merge() {
|
||||||
val map = mutableMapOf(2 to "x")
|
val map = mutableMapOf(2 to "x")
|
||||||
assertEquals("y", map.merge(3, "y") { _, _ -> null })
|
assertEquals("y", map.merge(3, "y") { _, _ -> null })
|
||||||
@@ -136,8 +137,8 @@ class MapTest {
|
|||||||
// fails due to KT-12144
|
// fails due to KT-12144
|
||||||
val map2 = mutableMapOf<Int, String?>(1 to null)
|
val map2 = mutableMapOf<Int, String?>(1 to null)
|
||||||
// new value must be V&Any
|
// new value must be V&Any
|
||||||
assertEquals("e", map2.merge(1, "e") { old, new -> (old.length + new.length).toString() ?: null })
|
assertEquals("e", map2.merge(1, "e") { old, new -> (old.length + new.length).toString() as String? })
|
||||||
assertEquals("3", map2.merge(1, "fg") { old, new -> (old.length + new.length).toString() ?: null })
|
assertEquals("3", map2.merge(1, "fg") { old, new -> (old.length + new.length).toString() as String? })
|
||||||
assertEquals(null, map2.merge(1, "3") { _, _ -> null })
|
assertEquals(null, map2.merge(1, "3") { _, _ -> null })
|
||||||
assertFalse(1 in map)
|
assertFalse(1 in map)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class DurationConversionTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun javaToKotlinRounding() {
|
fun javaToKotlinRounding() {
|
||||||
val jtDuration1 = JTDuration.ofDays(365 * 150)
|
val jtDuration1 = JTDuration.ofDays(365L * 150)
|
||||||
val jtDuration2 = jtDuration1.plusNanos(1)
|
val jtDuration2 = jtDuration1.plusNanos(1)
|
||||||
assertNotEquals(jtDuration1, jtDuration2)
|
assertNotEquals(jtDuration1, jtDuration2)
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ class DurationConversionTest {
|
|||||||
@Test
|
@Test
|
||||||
fun randomIsoConversionEquivalence() {
|
fun randomIsoConversionEquivalence() {
|
||||||
repeat(100) {
|
repeat(100) {
|
||||||
val duration = Duration.nanoseconds(Random.nextLong(-(1 shl 53) + 1, 1 shl 53))
|
val duration = Duration.nanoseconds(Random.nextLong(-(1L shl 53) + 1, 1L shl 53))
|
||||||
val fromString = JTDuration.parse(duration.toIsoString())
|
val fromString = JTDuration.parse(duration.toIsoString())
|
||||||
val fromDuration = duration.toJavaDuration()
|
val fromDuration = duration.toJavaDuration()
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class UseCloseableResourceTest {
|
|||||||
|
|
||||||
@Test fun closeFails() {
|
@Test fun closeFails() {
|
||||||
val e = assertFails {
|
val e = assertFails {
|
||||||
Resource(faultyClose = true).use { "" }
|
Resource(faultyClose = true).use { it.isClosed }
|
||||||
}
|
}
|
||||||
assertTrue(e is IOException)
|
assertTrue(e is IOException)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -599,6 +599,7 @@ class Collections {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Sample
|
@Sample
|
||||||
|
@Suppress("UNUSED_VARIABLE")
|
||||||
fun firstNotNullOf() {
|
fun firstNotNullOf() {
|
||||||
data class Rectangle(val height: Int, val width: Int) {
|
data class Rectangle(val height: Int, val width: Int) {
|
||||||
val area: Int get() = height * width
|
val area: Int get() = height * width
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@file:Suppress("UNUSED_ANONYMOUS_PARAMETER")
|
||||||
|
|
||||||
package samples.properties
|
package samples.properties
|
||||||
|
|
||||||
import kotlin.properties.Delegates
|
import kotlin.properties.Delegates
|
||||||
|
|||||||
@@ -1470,7 +1470,8 @@ class ArraysTest {
|
|||||||
doTest(build = { map {'a' + it}.toCharArray() }, reverse = { reverse() }, snapshot = { toList() })
|
doTest(build = { map {'a' + it}.toCharArray() }, reverse = { reverse() }, snapshot = { toList() })
|
||||||
doTest(build = { map {it % 2 == 0}.toBooleanArray() }, reverse = { reverse() }, snapshot = { toList() })
|
doTest(build = { map {it % 2 == 0}.toBooleanArray() }, reverse = { reverse() }, snapshot = { toList() })
|
||||||
doTest(build = { map {it.toString()}.toTypedArray() }, reverse = { reverse() }, snapshot = { toList() })
|
doTest(build = { map {it.toString()}.toTypedArray() }, reverse = { reverse() }, snapshot = { toList() })
|
||||||
doTest(build = { map {it.toString()}.toTypedArray() as Array<out String> }, reverse = { reverse() }, snapshot = { toList() })
|
@Suppress("USELESS_CAST")
|
||||||
|
doTest(build = { map {it.toString()}.toTypedArray() as Array<out String> }, reverse = { reverse() }, snapshot = { toList() })
|
||||||
doTest(build = { map {it.toUInt()}.toUIntArray() }, reverse = { reverse() }, snapshot = { toList() })
|
doTest(build = { map {it.toUInt()}.toUIntArray() }, reverse = { reverse() }, snapshot = { toList() })
|
||||||
doTest(build = { map {it.toULong()}.toULongArray() }, reverse = { reverse() }, snapshot = { toList() })
|
doTest(build = { map {it.toULong()}.toULongArray() }, reverse = { reverse() }, snapshot = { toList() })
|
||||||
doTest(build = { map {it.toUByte()}.toUByteArray() }, reverse = { reverse() }, snapshot = { toList() })
|
doTest(build = { map {it.toUByte()}.toUByteArray() }, reverse = { reverse() }, snapshot = { toList() })
|
||||||
@@ -1503,6 +1504,7 @@ class ArraysTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
doTest(build = { map {it.toString()}.toTypedArray() }, reverse = { from, to -> reverse(from, to) }, snapshot = { toList() })
|
doTest(build = { map {it.toString()}.toTypedArray() }, reverse = { from, to -> reverse(from, to) }, snapshot = { toList() })
|
||||||
|
@Suppress("USELESS_CAST")
|
||||||
doTest(build = { map {it.toString()}.toTypedArray() as Array<out String> }, reverse = { from, to -> reverse(from, to) }, snapshot = { toList() })
|
doTest(build = { map {it.toString()}.toTypedArray() as Array<out String> }, reverse = { from, to -> reverse(from, to) }, snapshot = { toList() })
|
||||||
|
|
||||||
doTest(build = { map {it}.toIntArray() }, reverse = { from, to -> reverse(from, to) }, snapshot = { toList() })
|
doTest(build = { map {it}.toIntArray() }, reverse = { from, to -> reverse(from, to) }, snapshot = { toList() })
|
||||||
@@ -1928,6 +1930,7 @@ class ArraysTest {
|
|||||||
testStableSort({ sort(1, 5) }, { sort(1, 5) })
|
testStableSort({ sort(1, 5) }, { sort(1, 5) })
|
||||||
testStableSort({ sort(0, 6) }, { sort(0, 6) })
|
testStableSort({ sort(0, 6) }, { sort(0, 6) })
|
||||||
doTest(build = { map {it.toString()}.toTypedArray() }, sort = { from, to -> sort(from, to) }, snapshot = { toList() })
|
doTest(build = { map {it.toString()}.toTypedArray() }, sort = { from, to -> sort(from, to) }, snapshot = { toList() })
|
||||||
|
@Suppress("USELESS_CAST")
|
||||||
doTest(build = { map {it.toString()}.toTypedArray() as Array<out String> }, sort = { from, to -> sort(from, to) }, snapshot = { toList() })
|
doTest(build = { map {it.toString()}.toTypedArray() as Array<out String> }, sort = { from, to -> sort(from, to) }, snapshot = { toList() })
|
||||||
|
|
||||||
doTest(build = { map {it}.toIntArray() }, sort = { from, to -> sort(from, to) }, snapshot = { toList() })
|
doTest(build = { map {it}.toIntArray() }, sort = { from, to -> sort(from, to) }, snapshot = { toList() })
|
||||||
@@ -1971,6 +1974,7 @@ class ArraysTest {
|
|||||||
testStableSort({ sortDescending(1, 5) }, { sortDescending(1, 5) })
|
testStableSort({ sortDescending(1, 5) }, { sortDescending(1, 5) })
|
||||||
testStableSort({ sortDescending(0, 6) }, { sortDescending(0, 6) })
|
testStableSort({ sortDescending(0, 6) }, { sortDescending(0, 6) })
|
||||||
doTest(build = { map {it.toString()}.toTypedArray() }, sortDescending = { from, to -> sortDescending(from, to) }, snapshot = { toList() })
|
doTest(build = { map {it.toString()}.toTypedArray() }, sortDescending = { from, to -> sortDescending(from, to) }, snapshot = { toList() })
|
||||||
|
@Suppress("USELESS_CAST")
|
||||||
doTest(build = { map {it.toString()}.toTypedArray() as Array<out String> }, sortDescending = { from, to -> sortDescending(from, to) }, snapshot = { toList() })
|
doTest(build = { map {it.toString()}.toTypedArray() as Array<out String> }, sortDescending = { from, to -> sortDescending(from, to) }, snapshot = { toList() })
|
||||||
|
|
||||||
doTest(build = { map {it}.toIntArray() }, sortDescending = { from, to -> sortDescending(from, to) }, snapshot = { toList() })
|
doTest(build = { map {it}.toIntArray() }, sortDescending = { from, to -> sortDescending(from, to) }, snapshot = { toList() })
|
||||||
@@ -1997,6 +2001,7 @@ class ArraysTest {
|
|||||||
checkSorted<Array<String>>({ sortedArray() }, { sortedArrayDescending()}, { iterator() } )
|
checkSorted<Array<String>>({ sortedArray() }, { sortedArrayDescending()}, { iterator() } )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("USELESS_CAST")
|
||||||
with (arrayData("ac", "aD", "aba") { toList().toTypedArray() as Array<out String> }) {
|
with (arrayData("ac", "aD", "aba") { toList().toTypedArray() as Array<out String> }) {
|
||||||
checkSorted<List<String>>({ sorted() }, { sortedDescending() }, { iterator() })
|
checkSorted<List<String>>({ sorted() }, { sortedDescending() }, { iterator() })
|
||||||
checkSorted<Array<out String>>({ sortedArray() }, { sortedArrayDescending()}, { iterator() } )
|
checkSorted<Array<out String>>({ sortedArray() }, { sortedArrayDescending()}, { iterator() } )
|
||||||
|
|||||||
@@ -463,7 +463,7 @@ class MapTest {
|
|||||||
doTest("HashMap", mapLetterToIndex.toMap(HashMap()), "c", 2)
|
doTest("HashMap", mapLetterToIndex.toMap(HashMap()), "c", 2)
|
||||||
doTest("LinkedHashMap", mapLetterToIndex.toMap(LinkedHashMap()), "d", 3)
|
doTest("LinkedHashMap", mapLetterToIndex.toMap(LinkedHashMap()), "d", 3)
|
||||||
|
|
||||||
val builtMap = buildMap {
|
buildMap {
|
||||||
putAll(mapLetterToIndex)
|
putAll(mapLetterToIndex)
|
||||||
doTest("MapBuilder", this, "z", 25)
|
doTest("MapBuilder", this, "z", 25)
|
||||||
}
|
}
|
||||||
@@ -479,6 +479,7 @@ class MapTest {
|
|||||||
assertEquals("Alice", firstAdult)
|
assertEquals("Alice", firstAdult)
|
||||||
assertEquals("Alice", firstAdultOrNull)
|
assertEquals("Alice", firstAdultOrNull)
|
||||||
|
|
||||||
|
@Suppress("UNUSED_VARIABLE")
|
||||||
assertFailsWith<NoSuchElementException> { val firstChild = map.firstNotNullOf { (name, age) -> name.takeIf { age <= 11 } } }
|
assertFailsWith<NoSuchElementException> { val firstChild = map.firstNotNullOf { (name, age) -> name.takeIf { age <= 11 } } }
|
||||||
val firstChildOrNull = map.firstNotNullOfOrNull { (name, age) -> name.takeIf { age <= 11 } }
|
val firstChildOrNull = map.firstNotNullOfOrNull { (name, age) -> name.takeIf { age <= 11 } }
|
||||||
|
|
||||||
|
|||||||
@@ -171,7 +171,9 @@ class FloorDivModTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
check(Long.MAX_VALUE, 2, Long.MAX_VALUE / 2, 1)
|
check(Long.MAX_VALUE, 2, Long.MAX_VALUE / 2, 1)
|
||||||
|
@Suppress("INTEGER_OPERATOR_RESOLVE_WILL_CHANGE") // KT-47729
|
||||||
check(Long.MAX_VALUE, 1.shl(30), expectedMod = 1.shl(30) - 1)
|
check(Long.MAX_VALUE, 1.shl(30), expectedMod = 1.shl(30) - 1)
|
||||||
|
@Suppress("INTEGER_OPERATOR_RESOLVE_WILL_CHANGE") // KT-47729
|
||||||
check(-1L, 1.shl(30), expectedMod = 1.shl(30) - 1)
|
check(-1L, 1.shl(30), expectedMod = 1.shl(30) - 1)
|
||||||
check(Long.MAX_VALUE, Int.MAX_VALUE, expectedMod = 1)
|
check(Long.MAX_VALUE, Int.MAX_VALUE, expectedMod = 1)
|
||||||
check(Long.MAX_VALUE, Int.MIN_VALUE, expectedMod = -1)
|
check(Long.MAX_VALUE, Int.MIN_VALUE, expectedMod = -1)
|
||||||
@@ -197,6 +199,7 @@ class FloorDivModTest {
|
|||||||
|
|
||||||
check(Short.MAX_VALUE, Int.MAX_VALUE, 0, Short.MAX_VALUE.toInt())
|
check(Short.MAX_VALUE, Int.MAX_VALUE, 0, Short.MAX_VALUE.toInt())
|
||||||
check(Short.MAX_VALUE, Int.MIN_VALUE, -1, Int.MIN_VALUE + Short.MAX_VALUE)
|
check(Short.MAX_VALUE, Int.MIN_VALUE, -1, Int.MIN_VALUE + Short.MAX_VALUE)
|
||||||
|
@Suppress("INTEGER_OPERATOR_RESOLVE_WILL_CHANGE") // KT-47729
|
||||||
check((-1).toShort(), 1.shl(30), -1, 1.shl(30) - 1)
|
check((-1).toShort(), 1.shl(30), -1, 1.shl(30) - 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ class NumbersTest {
|
|||||||
// overflow behavior
|
// overflow behavior
|
||||||
expect(Int.MIN_VALUE) { Int.MAX_VALUE + one }
|
expect(Int.MIN_VALUE) { Int.MAX_VALUE + one }
|
||||||
expect(Int.MAX_VALUE) { Int.MIN_VALUE - one }
|
expect(Int.MAX_VALUE) { Int.MIN_VALUE - one }
|
||||||
expect(Int.MIN_VALUE) { Int.MIN_VALUE / -1 }
|
expect(Int.MIN_VALUE) { Int.MIN_VALUE / -one }
|
||||||
expect(0) { (Int.MIN_VALUE % -1) + 0 } // +0 is a workaround for KT-45620
|
expect(0) { (Int.MIN_VALUE % -1) + 0 } // +0 is a workaround for KT-45620
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ class NumbersTest {
|
|||||||
// overflow behavior
|
// overflow behavior
|
||||||
expect(Long.MIN_VALUE) { Long.MAX_VALUE + one }
|
expect(Long.MIN_VALUE) { Long.MAX_VALUE + one }
|
||||||
expect(Long.MAX_VALUE) { Long.MIN_VALUE - one }
|
expect(Long.MAX_VALUE) { Long.MIN_VALUE - one }
|
||||||
expect(Long.MIN_VALUE) { Long.MIN_VALUE / -1L }
|
expect(Long.MIN_VALUE) { Long.MIN_VALUE / -one }
|
||||||
expect(0L) { Long.MIN_VALUE % -1L }
|
expect(0L) { Long.MIN_VALUE % -1L }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import kotlin.test.*
|
|||||||
class TODOTest {
|
class TODOTest {
|
||||||
private class PartiallyImplementedClass {
|
private class PartiallyImplementedClass {
|
||||||
public val prop: String get() = TODO()
|
public val prop: String get() = TODO()
|
||||||
|
|
||||||
@Suppress("UNREACHABLE_CODE", "CAST_NEVER_SUCCEEDS")
|
@Suppress("UNREACHABLE_CODE", "CAST_NEVER_SUCCEEDS")
|
||||||
fun method1() = TODO() as String
|
fun method1() = TODO() as String
|
||||||
|
|
||||||
@@ -20,6 +21,7 @@ class TODOTest {
|
|||||||
TODO("what if false")
|
TODO("what if false")
|
||||||
else {
|
else {
|
||||||
if (value.length < 3)
|
if (value.length < 3)
|
||||||
|
@Suppress("UNREACHABLE_CODE")
|
||||||
throw TODO("write message")
|
throw TODO("write message")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user