mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-04 14:15:59 +00:00
Move to munit in query module
This commit is contained in:
parent
9013d9264e
commit
d737da768e
@ -51,6 +51,11 @@ val testSettings = Seq(
|
||||
Test / fork := true
|
||||
)
|
||||
|
||||
val testSettingsMUnit = Seq(
|
||||
libraryDependencies ++= Dependencies.munit.map(_ % Test),
|
||||
testFrameworks += new TestFramework("munit.Framework")
|
||||
)
|
||||
|
||||
lazy val noPublish = Seq(
|
||||
publish := {},
|
||||
publishLocal := {},
|
||||
@ -267,11 +272,12 @@ ${lines.map(_._1).mkString(",\n")}
|
||||
|
||||
val query =
|
||||
crossProject(JSPlatform, JVMPlatform)
|
||||
.withoutSuffixFor(JVMPlatform)
|
||||
.crossType(CrossType.Pure)
|
||||
.in(file("modules/query"))
|
||||
.disablePlugins(RevolverPlugin)
|
||||
.settings(sharedSettings)
|
||||
.settings(testSettings)
|
||||
.settings(testSettingsMUnit)
|
||||
.settings(
|
||||
name := "docspell-query",
|
||||
libraryDependencies +=
|
||||
|
@ -2,9 +2,9 @@ package docspell.query.internal
|
||||
|
||||
import docspell.query.ItemQuery.Attr
|
||||
import docspell.query.internal.AttrParser
|
||||
import minitest._
|
||||
import munit._
|
||||
|
||||
object AttrParserTest extends SimpleTestSuite {
|
||||
class AttrParserTest extends FunSuite {
|
||||
|
||||
test("string attributes") {
|
||||
val p = AttrParser.stringAttr
|
||||
|
@ -1,10 +1,10 @@
|
||||
package docspell.query.internal
|
||||
|
||||
import minitest._
|
||||
import munit._
|
||||
import cats.data.{NonEmptyList => Nel}
|
||||
import docspell.query.internal.BasicParser
|
||||
|
||||
object BasicParserTest extends SimpleTestSuite {
|
||||
class BasicParserTest extends FunSuite {
|
||||
test("single string values") {
|
||||
val p = BasicParser.singleString
|
||||
assertEquals(p.parseAll("abcde"), Right("abcde"))
|
||||
|
@ -1,19 +1,10 @@
|
||||
package docspell.query.internal
|
||||
|
||||
import minitest._
|
||||
import munit._
|
||||
import docspell.query.Date
|
||||
import java.time.Period
|
||||
|
||||
object DateParserTest extends SimpleTestSuite {
|
||||
|
||||
def ld(year: Int, m: Int, d: Int): Date.DateLiteral =
|
||||
Date(year, m, d).fold(throw _, identity)
|
||||
|
||||
def ldPlus(year: Int, m: Int, d: Int, p: Period): Date.Calc =
|
||||
Date.Calc(ld(year, m, d), Date.CalcDirection.Plus, p)
|
||||
|
||||
def ldMinus(year: Int, m: Int, d: Int, p: Period): Date.Calc =
|
||||
Date.Calc(ld(year, m, d), Date.CalcDirection.Minus, p)
|
||||
class DateParserTest extends FunSuite with ValueHelper {
|
||||
|
||||
test("local date string") {
|
||||
val p = DateParser.dateFromString
|
||||
|
@ -1,11 +1,10 @@
|
||||
package docspell.query.internal
|
||||
|
||||
import docspell.query.ItemQuery._
|
||||
import docspell.query.internal.SimpleExprParserTest.stringExpr
|
||||
import minitest._
|
||||
import munit._
|
||||
import cats.data.{NonEmptyList => Nel}
|
||||
|
||||
object ExprParserTest extends SimpleTestSuite {
|
||||
class ExprParserTest extends FunSuite with ValueHelper {
|
||||
|
||||
test("simple expr") {
|
||||
val p = ExprParser.exprParser
|
||||
|
@ -1,10 +1,10 @@
|
||||
package docspell.query.internal
|
||||
|
||||
import minitest._
|
||||
import munit._
|
||||
import docspell.query.ItemQueryParser
|
||||
import docspell.query.ItemQuery
|
||||
|
||||
object ItemQueryParserTest extends SimpleTestSuite {
|
||||
class ItemQueryParserTest extends FunSuite {
|
||||
|
||||
test("reduce ands") {
|
||||
val q = ItemQueryParser.parseUnsafe("(&(&(&(& name:hello))))")
|
||||
|
@ -1,9 +1,9 @@
|
||||
package docspell.query.internal
|
||||
|
||||
import minitest._
|
||||
import munit._
|
||||
import cats.parse.{Parser => P}
|
||||
|
||||
object MacroParserTest extends SimpleTestSuite {
|
||||
class MacroParserTest extends FunSuite {
|
||||
|
||||
test("fail with unkown macro names") {
|
||||
val p = MacroParser.parser(Map.empty)
|
||||
|
@ -1,10 +1,10 @@
|
||||
package docspell.query.internal
|
||||
|
||||
import minitest._
|
||||
import munit._
|
||||
import docspell.query.ItemQuery.{Operator, TagOperator}
|
||||
import docspell.query.internal.OperatorParser
|
||||
|
||||
object OperatorParserTest extends SimpleTestSuite {
|
||||
class OperatorParserTest extends FunSuite {
|
||||
test("operator values") {
|
||||
val p = OperatorParser.op
|
||||
assertEquals(p.parseAll("="), Right(Operator.Eq))
|
||||
|
@ -2,11 +2,11 @@ package docspell.query.internal
|
||||
|
||||
import cats.data.{NonEmptyList => Nel}
|
||||
import docspell.query.ItemQuery._
|
||||
import minitest._
|
||||
import munit._
|
||||
import docspell.query.Date
|
||||
import java.time.Period
|
||||
|
||||
object SimpleExprParserTest extends SimpleTestSuite {
|
||||
class SimpleExprParserTest extends FunSuite with ValueHelper {
|
||||
|
||||
test("string expr") {
|
||||
val p = SimpleExprParser.stringExpr
|
||||
@ -175,12 +175,4 @@ object SimpleExprParserTest extends SimpleTestSuite {
|
||||
)
|
||||
}
|
||||
|
||||
def ld(y: Int, m: Int, d: Int) =
|
||||
DateParserTest.ld(y, m, d)
|
||||
|
||||
def stringExpr(op: Operator, name: Attr.StringAttr, value: String): Expr.SimpleExpr =
|
||||
Expr.SimpleExpr(op, Property.StringProperty(name, value))
|
||||
|
||||
def dateExpr(op: Operator, name: Attr.DateAttr, value: Date): Expr.SimpleExpr =
|
||||
Expr.SimpleExpr(op, Property.DateProperty(name, value))
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
package docspell.query.internal
|
||||
|
||||
import docspell.query.Date
|
||||
import docspell.query.ItemQuery._
|
||||
import java.time.Period
|
||||
|
||||
trait ValueHelper {
|
||||
|
||||
def ld(year: Int, m: Int, d: Int): Date.DateLiteral =
|
||||
Date(year, m, d).fold(throw _, identity)
|
||||
|
||||
def ldPlus(year: Int, m: Int, d: Int, p: Period): Date.Calc =
|
||||
Date.Calc(ld(year, m, d), Date.CalcDirection.Plus, p)
|
||||
|
||||
def ldMinus(year: Int, m: Int, d: Int, p: Period): Date.Calc =
|
||||
Date.Calc(ld(year, m, d), Date.CalcDirection.Minus, p)
|
||||
|
||||
def stringExpr(op: Operator, name: Attr.StringAttr, value: String): Expr.SimpleExpr =
|
||||
Expr.SimpleExpr(op, Property.StringProperty(name, value))
|
||||
|
||||
def dateExpr(op: Operator, name: Attr.DateAttr, value: Date): Expr.SimpleExpr =
|
||||
Expr.SimpleExpr(op, Property.DateProperty(name, value))
|
||||
|
||||
}
|
@ -156,7 +156,6 @@ object ItemQueryGenerator {
|
||||
date match {
|
||||
case d: Date.DateLiteral =>
|
||||
val ld = dateLiteralToDate(today)(d)
|
||||
println(s">>>> date= $ld")
|
||||
Timestamp.atUtc(ld.atStartOfDay)
|
||||
case Date.Calc(date, c, period) =>
|
||||
val ld = c match {
|
||||
@ -165,7 +164,6 @@ object ItemQueryGenerator {
|
||||
case Date.CalcDirection.Minus =>
|
||||
dateLiteralToDate(today)(date).minus(period)
|
||||
}
|
||||
println(s">>>> date= $ld")
|
||||
Timestamp.atUtc(ld.atStartOfDay())
|
||||
}
|
||||
|
||||
|
@ -24,14 +24,17 @@ object ItemQueryGeneratorTest extends SimpleTestSuite {
|
||||
)
|
||||
val now: LocalDate = LocalDate.of(2021, 2, 25)
|
||||
|
||||
def mkTimestamp(year: Int, month: Int, day: Int): Timestamp =
|
||||
Timestamp.atUtc(LocalDate.of(year, month, day).atStartOfDay())
|
||||
|
||||
test("basic test") {
|
||||
val q = ItemQueryParser
|
||||
.parseUnsafe("(& name:hello date>=2020-02-01 (| source=expense folder=test ))")
|
||||
.parseUnsafe("(& name:hello date>=2020-02-01 (| source:expense* folder=test ))")
|
||||
val cond = ItemQueryGenerator(now, tables, Ident.unsafe("coll"))(q)
|
||||
val expect =
|
||||
tables.item.name.like("hello") && tables.item.itemDate >= Timestamp.atUtc(
|
||||
LocalDate.of(2020, 2, 1).atStartOfDay()
|
||||
) && (tables.item.source === "expense" || tables.folder.name === "test")
|
||||
tables.item.name.like("hello") &&
|
||||
tables.item.itemDate >= mkTimestamp(2020, 2, 1) &&
|
||||
(tables.item.source.like("expense%") || tables.folder.name === "test")
|
||||
|
||||
assertEquals(cond, expect)
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ object Dependencies {
|
||||
val LogbackVersion = "1.2.3"
|
||||
val MariaDbVersion = "2.7.2"
|
||||
val MiniTestVersion = "2.9.3"
|
||||
val MUnitVersion = "0.7.22"
|
||||
val OrganizeImportsVersion = "0.5.0"
|
||||
val PdfboxVersion = "2.0.22"
|
||||
val PoiVersion = "4.1.2"
|
||||
@ -271,6 +272,11 @@ object Dependencies {
|
||||
"io.monix" %% "minitest-laws" % MiniTestVersion
|
||||
).map(_ % Test)
|
||||
|
||||
val munit = Seq(
|
||||
"org.scalameta" %% "munit" % MUnitVersion,
|
||||
"org.scalameta" %% "munit-scalacheck" % MUnitVersion
|
||||
)
|
||||
|
||||
val kindProjectorPlugin = "org.typelevel" %% "kind-projector" % KindProjectorVersion
|
||||
val betterMonadicFor = "com.olegpy" %% "better-monadic-for" % BetterMonadicForVersion
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user