Skip to content

Instantly share code, notes, and snippets.

@occar421
Created April 1, 2016 12:09
Show Gist options
  • Save occar421/46b1c22abcceff8e6176ceef89e3a326 to your computer and use it in GitHub Desktop.
Save occar421/46b1c22abcceff8e6176ceef89e3a326 to your computer and use it in GitHub Desktop.
actual should be { expected } and actual should not be { expected }
class SN<T>(val value: T)
class B<T>(val value: T)
infix fun <T> T.should(right: B<T>): Unit {
println("$this is ${right.value}")
}
fun <T> be(value: () -> T): B<T> {
return B(value())
}
infix fun <T> T.should(right: not): SN<T> = SN(this)
object not
infix fun <T> SN<T>.be(value: () -> T): Unit {
println("${this.value} isn't ${value()}")
}
fun main(args: Array<String>) {
(1) should be { 1 }
(1) should not be { 2 }
(1) should be { 1 }
(1 + 1) should be { 2 }
1 should be { 1 }
(2) should not be { 1 }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment