-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests for QuicklensMapAtFunctor implicits
- Loading branch information
yu.badalyants
committed
Dec 10, 2021
1 parent
c84d471
commit 63a1fc4
Showing
3 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
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
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
28 changes: 28 additions & 0 deletions
28
quicklens/src/test/scala-2/com.softwaremill.quicklens/QuicklensMapAtFunctorTest.scala
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.softwaremill.quicklens | ||
|
||
import com.softwaremill.quicklens.TestData._ | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class QuicklensMapAtFunctorTest extends AnyFlatSpec with Matchers { | ||
|
||
"QuicklensMapAtFunctor" should "work for types which is not a subtype of Map" in { | ||
case class MapLike[K, V](underlying: Map[K, V]) | ||
|
||
implicit def instance[K, T]: QuicklensMapAtFunctor[MapLike, K, T] = new QuicklensMapAtFunctor[MapLike, K, T] { | ||
private val mapInstance: QuicklensMapAtFunctor[Map, K, T] = | ||
implicitly[QuicklensMapAtFunctor[Map, K, T]] | ||
|
||
def at(fa: MapLike[K, T], idx: K)(f: T => T): MapLike[K, T] = | ||
MapLike(mapInstance.at(fa.underlying, idx)(f)) | ||
def atOrElse(fa: MapLike[K, T], idx: K, default: => T)(f: T => T): MapLike[K, T] = | ||
MapLike(mapInstance.atOrElse(fa.underlying, idx, default)(f)) | ||
def index(fa: MapLike[K, T], idx: K)(f: T => T): MapLike[K, T] = | ||
MapLike(mapInstance.index(fa.underlying, idx)(f)) | ||
def each(fa: MapLike[K, T])(f: T => T): MapLike[K, T] = | ||
MapLike(mapInstance.each(fa.underlying)(f)) | ||
} | ||
|
||
modify(MapLike(m1))(_.at("K1").a5.name).using(duplicate) should be(MapLike(m1dup)) | ||
} | ||
} |