Skip to content

Commit

Permalink
Add Getter test for optic conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
nomisRev committed Feb 2, 2018
1 parent e1ae53b commit 911a128
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions arrow-optics/src/test/kotlin/arrow/optics/GetterTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ import io.kotlintest.KTestJUnitRunner
import io.kotlintest.properties.Gen
import io.kotlintest.properties.forAll
import arrow.core.Tuple2
import arrow.core.getOrElse
import arrow.test.UnitSpec
import arrow.syntax.either.left
import arrow.syntax.either.right
import arrow.core.toT
import arrow.data.k
import arrow.syntax.collections.firstOption
import arrow.syntax.foldable.combineAll
import arrow.syntax.option.some
import org.junit.runner.RunWith

@RunWith(KTestJUnitRunner::class)
Expand All @@ -20,6 +25,54 @@ class GetterTest : UnitSpec() {
val length = Getter<String, Int> { it.length }
val upper = Getter<String, String> { it.toUpperCase() }

"asFold should behave as valid Fold: size" {
forAll(TokenGen) { token ->
tokenGetter.asFold().size(token) == 1
}
}

"asFold should behave as valid Fold: nonEmpty" {
forAll(TokenGen) { token ->
tokenGetter.asFold().nonEmpty(token)
}
}

"asFold should behave as valid Fold: isEmpty" {
forAll(TokenGen) { token ->
!tokenGetter.asFold().isEmpty(token)
}
}

"asFold should behave as valid Fold: getAll" {
forAll(TokenGen) { token ->
tokenGetter.asFold().getAll(token) == listOf(token.value).k()
}
}

"asFold should behave as valid Fold: combineAll" {
forAll(TokenGen) { token ->
tokenGetter.asFold().combineAll(token) == token.value
}
}

"asFold should behave as valid Fold: fold" {
forAll(TokenGen) { token ->
tokenGetter.asFold().fold(token) == token.value
}
}

"asFold should behave as valid Fold: headOption" {
forAll(TokenGen) { token ->
tokenGetter.asFold().headOption(token) == token.value.some()
}
}

"asFold should behave as valid Fold: lastOption" {
forAll(TokenGen) { token ->
tokenGetter.asFold().lastOption(token) == token.value.some()
}
}

"Getting the target should always yield the exact result" {
forAll({ value: String ->
tokenGetter.get(Token(value)) == value
Expand Down

0 comments on commit 911a128

Please sign in to comment.