bbaldino
03/21/2019, 11:33 PMval result = func(): String?
result shouldNotBe null
result as String
result.startsWith("...") shouldBe true
bbaldino
03/21/2019, 11:34 PMshouldNotBe null
so wouldn't have to explicitly castbbaldino
03/21/2019, 11:38 PM?.
there, but, given i've asserted it's already not null it'd be a nice-to-havesam
03/21/2019, 11:48 PMsam
03/21/2019, 11:48 PMLeoColman
03/21/2019, 11:55 PMLeoColman
03/21/2019, 11:56 PMLeoColman
03/21/2019, 11:56 PMLeoColman
03/21/2019, 11:56 PMLeoColman
03/21/2019, 11:57 PMshouldBeInstanceOf
sam
03/22/2019, 12:05 AMLeoColman
03/22/2019, 12:07 AMfoo shouldNotBe bar
bbaldino
03/22/2019, 12:07 AM@ExperimentalContracts
fun foo(x: Any?) {
contract {
returns() implies (x != null)
}
if (x == null) {
throw Exception()
}
}
LeoColman
03/22/2019, 12:07 AMbbaldino
03/22/2019, 12:07 AMval x: String? = null
foo(x)
x.startsWith("asdsd")
bbaldino
03/22/2019, 12:08 AMshouldNotBe
bbaldino
03/22/2019, 12:08 AMLeoColman
03/22/2019, 12:08 AMLeoColman
03/22/2019, 12:58 AMLeoColman
03/22/2019, 12:58 AMa shouldNotBe b
if b was nullLeoColman
03/22/2019, 12:59 AMa shouldNotBe b
will always fail if b is null and a is null, so that's okLeoColman
03/22/2019, 12:59 AMLeoColman
03/22/2019, 12:59 AMLeoColman
03/22/2019, 1:13 AMLeoColman
03/22/2019, 1:13 AMLeoColman
03/22/2019, 1:13 AMval a: String? = "foo" // A is not guaranteed to not be null
a shouldNotBe "Bar"
a.length shouldBe 125
LeoColman
03/22/2019, 1:13 AMa
is not null"LeoColman
03/22/2019, 1:27 AMa.shouldNotBeNull()
LeoColman
03/22/2019, 1:28 AMLeoColman
03/22/2019, 1:28 AMfun Any?.shouldNotBeNull() {
contract {
returns() implies (this@shouldNotBeNull != null)
}
this shouldNot beNull()
}
LeoColman
03/22/2019, 1:28 AMLeoColman
03/22/2019, 1:46 AMbbaldino
03/22/2019, 4:17 AMshouldNotBeNull
, is it in a recent update?bbaldino
03/22/2019, 4:17 AMLeoColman
03/22/2019, 4:59 PMLeoColman
03/22/2019, 4:59 PMbbaldino
03/22/2019, 5:01 PMbbaldino
03/22/2019, 5:02 PMbbaldino
03/22/2019, 5:02 PMbbaldino
03/22/2019, 5:02 PM