forked from JetBrains/kotlin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6655d34
commit 8ebf479
Showing
2 changed files
with
25 additions
and
10 deletions.
There are no files selected for viewing
32 changes: 24 additions & 8 deletions
32
plugins/formal-verification/testData/diagnostics/good_contracts/stdlib_replacement_tests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,33 @@ | ||
// REPLACE_STDLIB_EXTENSIONS | ||
// ALWAYS_VALIDATE | ||
|
||
import kotlin.contracts.contract | ||
import kotlin.contracts.ExperimentalContracts | ||
import org.jetbrains.kotlin.formver.plugin.verify | ||
|
||
@OptIn(ExperimentalContracts::class) | ||
fun <!VIPER_TEXT!>useRepeat<!>(): Unit { | ||
contract { | ||
returns() | ||
} | ||
fun <!VIPER_TEXT!>useChecks<!>(): Unit { | ||
check(true) | ||
check(true) { "Lazy message" } | ||
} | ||
|
||
// TODO: add test for `repeat` (we actually have a bug there because we require unsatisfied precondition in loops) | ||
|
||
// TODO: add tests for `let`, `apply`, `with`, `run`, `also` | ||
fun <!VIPER_TEXT!>useRuns<!>(x: Int): Unit { | ||
verify(run { x + 1 } == 1 + x) | ||
verify(x.run { plus(1) } == 1 + x) | ||
} | ||
|
||
fun <!VIPER_TEXT!>useAlso<!>(x: Int): Unit { | ||
(x + 1).also { verify(it == 1 + x) } | ||
} | ||
|
||
fun <!VIPER_TEXT!>useLet<!>(x: Int): Unit { | ||
verify(x.let { it + 1 } == 1 + x) | ||
} | ||
|
||
fun <!VIPER_TEXT!>useWith<!>(x: Int): Unit { | ||
with(x + 1) { verify(this == 1 + x) } | ||
} | ||
|
||
fun <!VIPER_TEXT!>useApply<!>(x: Int): Unit { | ||
(x + 1).apply { verify(this == 1 + x) } | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters