Scala模式在单元测试期间匹配方法的结果



我正在单元测试一个scala方法,该方法返回以下形式的字符串

SELECT col1 FROM tableName WHERE ts<=1533499389

整数值为epoch,每次执行时都会更改。我想知道Scala中是否有一种方法可以匹配模式来断言返回的值

模式可以类似于:

SELECT col1 FROM tableName WHERE ts<={}

您可以使用匹配模式,

import java.time.OffsetDateTime
import org.scalatest.{FunSuite, Matchers}
class SqlSpec extends FunSuite with Matchers {
def fn = s"""SELECT col1 FROM tableName WHERE ts <= ${OffsetDateTime.now().toEpochSecond}"""
test("whatever") {
fn.matches("SELECT col1 FROM tableName WHERE ts <= \d{10}") should be(true)
}
}

最新更新