Skip to content

Commit

Permalink
#679 Clean up FunctionDefSpec (#687)
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahotoole committed May 26, 2022
1 parent 61dc2e8 commit be1f30a
Showing 1 changed file with 16 additions and 66 deletions.
82 changes: 16 additions & 66 deletions mysql/src/test/scala/zio/sql/mysql/FunctionDefSpec.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package zio.sql.mysql

import zio.Cause
import zio.test._
import zio.test.Assertion._
import java.time.LocalDate

import java.time.{ LocalTime, ZoneId }
import java.time.{ LocalDate, LocalTime, ZoneId }
import java.time.format.DateTimeFormatter

object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema {
Expand All @@ -22,11 +20,7 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema {

val testResult = execute(query)

val assertion = for {
r <- testResult.runCollect
} yield assert(r.head)(equalTo(expected))

assertion.mapErrorCause(cause => Cause.stackless(cause.untraced))
assertZIO(testResult.runHead.some)(equalTo(expected))
},
// FIXME: lower with string literal should not refer to a column name
// See: https://www.w3schools.com/sql/trymysql.asp?filename=trysql_func_mysql_lower
Expand All @@ -51,11 +45,7 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema {

val testResult = execute(query)

val assertion = for {
r <- testResult.runCollect
} yield assert(r.head)(equalTo(expected))

assertion.mapErrorCause(cause => Cause.stackless(cause.untraced))
assertZIO(testResult.runHead.some)(equalTo(expected))
},
test("abs") {
val query = select(Abs(-32.0))
Expand All @@ -64,11 +54,7 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema {

val testResult = execute(query)

val assertion = for {
r <- testResult.runCollect
} yield assert(r.head)(equalTo(expected))

assertion.mapErrorCause(cause => Cause.stackless(cause.untraced))
assertZIO(testResult.runHead.some)(equalTo(expected))
},
test("crc32") {
val query = select(Crc32("MySQL")) from customers
Expand All @@ -77,11 +63,7 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema {

val testResult = execute(query)

val assertion = for {
r <- testResult.runCollect
} yield assert(r.head)(equalTo(expected))

assertion.mapErrorCause(cause => Cause.stackless(cause.untraced))
assertZIO(testResult.runHead.some)(equalTo(expected))
},
test("degrees") {
val query = select(Degrees(Math.PI)) from customers
Expand All @@ -90,11 +72,7 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema {

val testResult = execute(query)

val assertion = for {
r <- testResult.runCollect
} yield assert(r.head)(equalTo(expected))

assertion.mapErrorCause(cause => Cause.stackless(cause.untraced))
assertZIO(testResult.runHead.some)(equalTo(expected))
},
test("hex") {
val query = select(Hex(255L)) from customers
Expand All @@ -110,11 +88,7 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema {

val testResult = execute(query)

val assertion = for {
r <- testResult.runCollect
} yield assert(r.head)(equalTo(expected))

assertion.mapErrorCause(cause => Cause.stackless(cause.untraced))
assertZIO(testResult.runHead.some)(equalTo(expected))
},
test("log10") {
val query = select(Log10(1000000d)) from customers
Expand All @@ -123,11 +97,7 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema {

val testResult = execute(query)

val assertion = for {
r <- testResult.runCollect
} yield assert(r.head)(equalTo(expected))

assertion.mapErrorCause(cause => Cause.stackless(cause.untraced))
assertZIO(testResult.runHead.some)(equalTo(expected))
},
test("now") {
val timestampFormatter =
Expand All @@ -137,14 +107,10 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema {

val testResult = execute(query)

val assertion =
for {
r <- testResult.runCollect
} yield assert(timestampFormatter.format(r.head))(
Assertion.matchesRegex("[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}")
)

assertion.mapErrorCause(cause => Cause.stackless(cause.untraced))
assertZIO(
testResult.runHead.some
.map(t => timestampFormatter.format(t))
)(matchesRegex("[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}"))
},
test("bit_length") {
val query = select(BitLength("hello"))
Expand All @@ -153,11 +119,7 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema {

val testResult = execute(query)

val assertion = for {
r <- testResult.runCollect
} yield assert(r.head)(equalTo(expected))

assertion.mapErrorCause(cause => Cause.stackless(cause.untraced))
assertZIO(testResult.runHead.some)(equalTo(expected))
},
test("current_date") {
val query = select(CurrentDate)
Expand All @@ -166,11 +128,7 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema {

val testResult = execute(query)

val assertion = for {
r <- testResult.runCollect
} yield assert(r.head)(equalTo(expected))

assertion.mapErrorCause(cause => Cause.stackless(cause.untraced))
assertZIO(testResult.runHead.some)(equalTo(expected))
},
test("maketime") {
val query = select(MakeTime(12, 15, 30.5)) from customers
Expand All @@ -179,11 +137,7 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema {

val testResult = execute(query)

val assertion = for {
r <- testResult.runCollect
} yield assert(r.head)(equalTo(expected))

assertion.mapErrorCause(cause => Cause.stackless(cause.untraced))
assertZIO(testResult.runHead.some)(equalTo(expected))
},
test("pi") {
val query = select(Pi) from customers
Expand All @@ -192,11 +146,7 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema {

val testResult = execute(query)

val assertion = for {
r <- testResult.runCollect
} yield assert(r.head)(equalTo(expected))

assertion.mapErrorCause(cause => Cause.stackless(cause.untraced))
assertZIO(testResult.runHead.some)(equalTo(expected))
},
test("rpad") {
val cases = Seq(("hi", 5, "?", "hi???"), ("hi", 1, "?", "h"))
Expand Down

0 comments on commit be1f30a

Please sign in to comment.