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:
@@ -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)
|
||||
},
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user