Created
July 11, 2018 13:07
-
-
Save yaraki/dc9eab9031884c1c6b648fd05556c7ff to your computer and use it in GitHub Desktop.
Fluent testing for Kotlin in Japanese
This file contains hidden or 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
package io.github.yaraki.superfluent | |
import org.hamcrest.CoreMatchers.`is` | |
import org.hamcrest.CoreMatchers.equalTo | |
import org.hamcrest.MatcherAssert.assertThat | |
import org.hamcrest.Matchers.greaterThan | |
import org.junit.Test | |
class Sample { | |
@Test | |
fun a() { | |
assertThat(2 * 3, `is`(6)) | |
6 と (2 * 3) が 等しい | |
assertThat("abc", `is`(equalTo("abc"))) | |
"abc" と "abc" が 等しい | |
assertThat(2, `is`(greaterThan(1))) | |
1 より 2 が 大きい | |
} | |
} | |
inline infix fun <reified E> E.と(other: E) = Pair(this, other) | |
inline infix fun <reified E> Pair<E, E>.が(predicate: (Pair<E, E>) -> Unit) { | |
predicate(this) | |
} | |
val 等しい = fun(params: Pair<Any, Any>) { | |
assertThat(params.first, `is`(equalTo(params.second))) | |
} | |
class Comparison<E : Comparable<E>>(val a: E, val b: E) | |
inline infix fun <reified E : Comparable<E>> E.より(other: E) = Comparison(this, other) | |
inline infix fun <reified E : Comparable<E>> Comparison<E>.が(predicate: (Comparison<E>) -> Unit) { | |
predicate(this) | |
} | |
val 大きい = fun(params: Comparison<Int>) { | |
assertThat(params.b, `is`(greaterThan(params.a))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment