Friday, 15 March 2013

debugging scala / sbt tutorial project in intellij -



debugging scala / sbt tutorial project in intellij -

i next pluralsights scala getting started tutorial , have run problem. code appears match tutorial 1 of tests fail , don't know start debugging new jvm , statically typed compiled languages in general.

the tutorial app meant scan directory files containing filter. have directory called testfiles in root of project contains file readme.txt should found app when test runs

here test fails

"matcher using directory containing 1 file matching filter" should "return list file name" in { val matcher = new matcher("txt", new file(".\\testfiles\\").getcanonicalpath()) val results = matcher.execute() assert(results == list("readme.txt")) }

the error simply

should homecoming list file name * failed * [info] list() did not equal list("readme.txt") (matchertests.scala:24)

and have app code

matcher.scala

package filesearcher import java.io.file class matcher(filter: string, val rootlocation : string = new file(".").getcanonicalpath()) { var rootioobject = fileconverter.converttoioobject(new file(rootlocation)) def execute() = { val matchedfiles = rootioobject match { case file : fileobject if filterchecker(filter) matches file.name => list(file) case directory : directoryobject => filterchecker(filter) findmatchedfiles directory.children() case _ => list() } matchedfiles map(ioobject => ioobject.name) } }

filterchecker.scala

package filesearcher class filterchecker(filter: string) { def matches(content : string) = content contains filter def findmatchedfiles(fileobjects : list[ioobject]) = for(ioobject <- fileobjects if(ioobject.isinstanceof[fileobject]) if(matches(ioobject.name))) yield ioobject } object filterchecker{ def apply(filter: string) = new filterchecker(filter) }

ioobject.scala

package filesearcher import java.io.file trait ioobject { val file: file val name = file.getname() } case class fileobject(file: file) extends ioobject case class directoryobject(file: file) extends ioobject { def children() = seek file.listfiles().tolist map(file=>fileconverter converttoioobject file) grab { case _ : nullpointerexception => list() } }

fileconverter.scala

package filesearcher import java.io.file object fileconverter { def converttoioobject(file: file) = if(file.isdirectory()) directoryobject(file) else fileobject(file) }

really if have made obvious error cant see or if can point me towards tool or tutorial help me step through code figure out breaking great

scala

No comments:

Post a Comment