在scala中测试对象的私有成员

时间:2015-10-31 14:28:21

标签: scala testing scalatest

这是对象:

package object beautifier {
  private val scientificPattern = """([+-]?\d+(\.\d+)?)([Ee]([+-]?\d+))?""".r
}

测试:

import org.scalatest._ import vu.co.kaiyin.formatting.scientificNotaion.beautifier.scientificPattern

class ScientificNotationSpec extends FlatSpec with Matchers {
  "Regex" should "return correct matches" in {
    "-4.2e-3" match {
      case scientificPattern(coef, _, _, exponent) => {
        coef should be (-4.2)
        exponent should be (-3)
      }
    }
  }
}

我当然得到了一个错误:

Error:(2, 8) object scientificPattern is not a member of package vu.co.kaiyin.formatting.scientificNotaion.beautifier
import vu.co.kaiyin.formatting.scientificNotaion.beautifier.scientificPattern
       ^

如何解决这个问题?

0 个答案:

没有答案