Merge pull request #9546 from alimate/BAEL-4309
BAEL-4309: Invoke Operator Function
This commit is contained in:
commit
b28a4dac7e
|
@ -6,6 +6,7 @@ interface Page<T> {
|
|||
fun elements(): MutableList<T>
|
||||
}
|
||||
|
||||
operator fun <T> Page<T>.invoke(index: Int): T = elements()[index]
|
||||
operator fun <T> Page<T>.get(index: Int): T = elements()[index]
|
||||
operator fun <T> Page<T>.get(start: Int, endExclusive: Int): List<T> = elements().subList(start, endExclusive)
|
||||
operator fun <T> Page<T>.set(index: Int, value: T) {
|
||||
|
|
|
@ -14,6 +14,11 @@ class PageTest {
|
|||
assertEquals(page[1, 3], listOf("Kotlin", "Scala"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Invoke convention should work as expected`() {
|
||||
assertEquals(page(1), "Kotlin")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `In convention should work on a page as expected`() {
|
||||
assertTrue("Kotlin" in page)
|
||||
|
|
Loading…
Reference in New Issue