Tests: use helper function to assert compile-time and run-time type check

To cleanup warnings about useless cast or type check that is always true.
This commit is contained in:
Ilya Gorbunov
2017-12-25 21:07:20 +03:00
parent ecd42f14b3
commit 053f3b6ac0
7 changed files with 79 additions and 55 deletions
+30 -26
View File
@@ -16,58 +16,62 @@
package core
import test.assertStaticAndRuntimeTypeIs
import test.assertStaticTypeIs
import kotlin.js.Promise
import kotlin.test.*
class PromiseTest {
// To be sure that some base cases can be written in Kotlin
fun smokeTest(p: Promise<Int>, ps: Promise<String>) {
var _p: Promise<Int>
_p = p.then {
1
}
assertStaticTypeIs<Promise<Int>>(p.then { 1 })
_p = p.then({
1
})
assertStaticTypeIs<Promise<Int>>(p.then({ 1 }))
val f: (Int) -> Int = { 1 };
val ft: (Throwable) -> Int = { 1 };
val f: (Int) -> Int = { 1 }
val ft: (Throwable) -> Int = { 1 }
_p = p.then(f, ft);
assertStaticTypeIs<Promise<Int>>(p.then(f, ft))
_p = p.then({
assertStaticTypeIs<Promise<Int>>(
p.then({
1
} , {
1
})
)
_p = p.then({
assertStaticTypeIs<Promise<Int>>(
p.then({
1
}) {
1
}
1
}
)
_p = p.then(onFulfilled = {
1
})
assertStaticTypeIs<Promise<Int>>(
p.then(onFulfilled = {
1
})
)
_p = p.then(onFulfilled = {
1
}) {
1
}
assertStaticTypeIs<Promise<Int>>(
p.then(onFulfilled = {
1
}) {
1
}
)
p.then {
ps
}.then {
var s: String = it
assertTrue((s as Any) is String)
assertStaticAndRuntimeTypeIs<String>(it)
ps
}.then(
{
var s: String = it
assertTrue((s as Any) is String)
assertStaticAndRuntimeTypeIs<String>(it)
},
{