Skip to content
Snippets Groups Projects
Commit 16d06138 authored by Ihrig, Arvid Conrad (ari)'s avatar Ihrig, Arvid Conrad (ari)
Browse files

Integrated Pipeline: refactored property matchers, now have a human-readable string representation

parent b5c05df9
No related branches found
No related tags found
No related merge requests found
......@@ -12,109 +12,89 @@ trait MessageMatchers
object MessageMatchers extends MessageMatchers
trait FileTreeTaskMatchers {
def basePath(expectedValue: Path) =
new HavePropertyMatcher[FileTreeScanTask, Path] {
def apply(test: FileTreeScanTask) =
HavePropertyMatchResult(
test.treeBasePath == expectedValue,
"tree base path",
expectedValue,
test.treeBasePath
)
private object Helpers {
def propertyMatcher[T, E](propertyName: String, expected: E, test: T => E): HavePropertyMatcher[T, E] = {
new HavePropertyMatcher[T, E] {
def apply(element: T): HavePropertyMatchResult[E] = {
val actual = test(element)
HavePropertyMatchResult(actual == expected, propertyName, expected, actual)
}
override def toString(): String = s"$propertyName '$expected'"
}
}
}
trait FileTreeTaskMatchers {
def basePath(expectedValue: Path): HavePropertyMatcher[FileTreeScanTask, Path] =
Helpers.propertyMatcher(
propertyName = "tree base path",
expected = expectedValue,
test = (x: FileTreeScanTask) => x.treeBasePath
)
}
trait FileParsingTaskMatchers {
def treeTask(expectedValue: FileTreeScanTask) = new HavePropertyMatcher[FileParsingTaskSignal, FileTreeScanTask] {
def apply(test: FileParsingTaskSignal) =
HavePropertyMatchResult(
test.treeTask == expectedValue,
"parent tree task",
expectedValue,
test.treeTask
)
}
def treeTask(expectedValue: FileTreeScanTask): HavePropertyMatcher[FileParsingTaskSignal, FileTreeScanTask] =
Helpers.propertyMatcher(
propertyName = "parent tree task",
expected = expectedValue,
test = (x: FileParsingTaskSignal) => x.treeTask
)
def relativePath(expectedValue: Path) = new HavePropertyMatcher[FileParsingTask, Path] {
def apply(test: FileParsingTask) = HavePropertyMatchResult(
test.relativePath == expectedValue,
"relative file path",
expectedValue,
test.relativePath
def relativePath(expectedValue: Path): HavePropertyMatcher[FileParsingTask, Path] =
Helpers.propertyMatcher(
propertyName = "relative file path",
expected = expectedValue,
test = (x: FileParsingTask) => x.relativePath
)
}
def relativePath(expectedValue: String): HavePropertyMatcher[FileParsingTask, Path] = {
relativePath(Paths.get(expectedValue))
}
def extractedPath(expectedValue: Option[Path]) = new HavePropertyMatcher[FileParsingTask, Option[Path]] {
def apply(test: FileParsingTask) = HavePropertyMatchResult(
test.extractedPath == expectedValue,
"temporary extracted file path",
expectedValue,
test.extractedPath
def extractedPath(expectedValue: Option[Path]): HavePropertyMatcher[FileParsingTask, Option[Path]] =
Helpers.propertyMatcher(
propertyName = "temporary extracted file path",
expected = expectedValue,
test = (x: FileParsingTask) => x.extractedPath
)
}
def extractedPathString(expectedValue: Option[String]): HavePropertyMatcher[FileParsingTask, Option[Path]] = {
extractedPath(expectedValue.map(Paths.get(_)))
}
def numParsingTasks(expectedValue: Long) =
new HavePropertyMatcher[FileParsingSignalEndTree, Long] {
def apply(test: FileParsingSignalEndTree) = HavePropertyMatchResult(
test.numParsingTasks == expectedValue,
"number of identified candidate calculations",
expectedValue,
test.numParsingTasks
)
}
def numParsingTasks(expectedValue: Long): HavePropertyMatcher[FileParsingSignalEndTree, Long] =
Helpers.propertyMatcher(
propertyName = "number of identified candidate calculations",
expected = expectedValue,
test = (x: FileParsingSignalEndTree) => x.numParsingTasks
)
}
trait FileParsingResultMatchers {
def treeTask(expectedValue: FileTreeScanTask) =
new HavePropertyMatcher[FileParsingResultSignal, FileTreeScanTask] {
def apply(test: FileParsingResultSignal) =
HavePropertyMatchResult(
test.treeTask == expectedValue,
"parent tree task",
expectedValue,
test.treeTask
)
}
def status(expectedValue: ParseResult) =
new HavePropertyMatcher[FileParsingResult, ParseResult] {
def apply(test: FileParsingResult) =
HavePropertyMatchResult(
test.result == expectedValue,
"parsing result status",
expectedValue,
test.result
)
}
def treeTask(expectedValue: FileTreeScanTask): HavePropertyMatcher[FileParsingResultSignal, FileTreeScanTask] =
Helpers.propertyMatcher(
propertyName = "parent tree task",
expected = expectedValue,
test = (x: FileParsingResultSignal) => x.treeTask
)
def relativePath(expectedValue: Path) =
new HavePropertyMatcher[FileParsingResult, Path] {
def apply(test: FileParsingResult) =
HavePropertyMatchResult(
test.task.relativePath == expectedValue,
"relative file path",
expectedValue,
test.task.relativePath
)
}
def status(expectedValue: ParseResult): HavePropertyMatcher[FileParsingResult, ParseResult] =
Helpers.propertyMatcher(
propertyName = "parsing result status",
expected = expectedValue,
test = (x: FileParsingResult) => x.result
)
def relativePath(expectedValue: String) =
new HavePropertyMatcher[FileParsingResult, Path] {
def apply(test: FileParsingResult) =
HavePropertyMatchResult(
test.task.relativePath == Paths.get(expectedValue),
"relative file path",
Paths.get(expectedValue),
test.task.relativePath
)
}
def relativePath(expectedValue: Path): HavePropertyMatcher[FileParsingResult, Path] =
Helpers.propertyMatcher(
propertyName = "relative file path",
expected = expectedValue,
test = (x: FileParsingResult) => x.task.relativePath
)
def relativePath(expectedValue: String): HavePropertyMatcher[FileParsingResult, Path] =
relativePath(Paths.get(expectedValue))
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment