Skip to content

Commit

Permalink
FragmentTest
Browse files Browse the repository at this point in the history
  • Loading branch information
tpolecat committed Jul 8, 2020
1 parent 6ddea7d commit 61fc612
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions modules/tests/src/test/scala/FragmentTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright (c) 2018-2020 by Rob Norris
// This software is licensed under the MIT License (MIT).
// For more information see LICENSE or https://opensource.org/licenses/MIT

package tests

import cats._
import cats.implicits._
import skunk._
import skunk.codec.all._
import skunk.implicits._

case object FragmentTest extends SkunkTest {

sessionTest("contramap") { s =>
val f = sql"select $int4".contramap[String](_.toInt)
s.prepare(f.query(int4)).use { ps =>
for {
n <- ps.unique("123")
_ <- assertEqual("123", n, 123)
} yield "ok"
}
}

sessionTest("product") { s =>
val f = sql"select $int4" product sql", $varchar"
s.prepare(f.query(int4 ~ varchar)).use { ps =>
for {
n <- ps.unique(123 ~ "456")
_ <- assertEqual("123 ~ \"456\"", n, 123 ~ "456")
} yield "ok"
}
}

sessionTest("~") { s =>
val f = sql"select $int4" ~ sql", $varchar"
s.prepare(f.query(int4 ~ varchar)).use { ps =>
for {
n <- ps.unique(123 ~ "456")
_ <- assertEqual("123 ~ \"456\"", n, 123 ~ "456")
} yield "ok"
}
}

sessionTest("contramap via ContravariantSemigroupal") { s =>
val f = ContravariantSemigroupal[Fragment].contramap[Int, String](sql"select $int4")(_.toInt)
s.prepare(f.query(int4)).use { ps =>
for {
n <- ps.unique("123")
_ <- assertEqual("123", n, 123)
} yield "ok"
}
}

sessionTest("product via ContravariantSemigroupal") { s =>
val f = ContravariantSemigroupal[Fragment].product(sql"select $int4", sql", $varchar")
s.prepare(f.query(int4 ~ varchar)).use { ps =>
for {
n <- ps.unique(123 ~ "456")
_ <- assertEqual("123 ~ \"456\"", n, 123 ~ "456")
} yield "ok"
}
}
}

0 comments on commit 61fc612

Please sign in to comment.