How write a property test for particular list content

55 Views Asked by At

I have following function, that I want to test it with ScalaCheck:

object Windows {

  val Directory = "^[a-zA-Z]:\\\\(((?![<>:\"/\\\\|?*]).)+((?<![ .])\\\\)?)*$".r


  def arePathsValid(paths: List[String]): Eval[List[String]] = {
    Foldable[List]
      .foldRight(paths, Eval.later(List.empty[String]))((a: String, b: Eval[List[String]]) => {
        Directory.findFirstIn(a) match {
          case Some(a) => b.map(a :: _)
          case None => b
        }
      })
  }
}

I tried to start with:

val propPaths = forAll { l: List[String] => ??? }

But could not write the implementation for the property.

The String, that should be random generated in the List, should has a Windows pattern path, for example:

C:\temp\foo

How to do the property implementation?

1

There are 1 best solutions below

2
On BEST ANSWER

You can add Windows path prefix like this:

val strGen = Gen.alphaStr // Or any other String generator
val windowsPathGen = strGen.map("C:\temp\foo" + _)