Skip to content

Commit

Permalink
minor unit test improvements. deferring overhaul to #5
Browse files Browse the repository at this point in the history
  • Loading branch information
matanox committed Nov 16, 2015
1 parent 751ce54 commit 74653f1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.canve.compilerPlugin

/*
* Unique Symbol QualiferID, serializable
*/
case class KindAndName(kind: String, name: String)

case class QualifiedID(value: List[KindAndName]) {
def pickle = value.map(kindAndName => "(" + kindAndName.kind + "|" + kindAndName.name + ")").mkString(".")
}
object QualifiedID {
def unpickle(s: String) =
QualifiedID(s.split('.').toList.map(pair => KindAndName(pair.takeWhile(_!='|').drop(1), pair.dropWhile(_!='|').drop(1).dropRight(1))))
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
package org.canve.compilerPlugin

/*
* Serializable QualiferID
*/
case class KindAndName(kind: String, name: String)
case class QualifiedID(value: List[KindAndName]) {
def pickle = value.map(qualifiedId => "(" + qualifiedId.kind + "|" + qualifiedId.name + ")").mkString(".")
}
object QualifiedID {
def unpickle(s: String) =
QualifiedID(s.split('.').toList.map(pair => KindAndName(pair.takeWhile(_!='|').drop(1), pair.dropWhile(_!='|').drop(1).dropRight(1))))
}

/*
* helper for writing node data to csv
*/
Expand Down
30 changes: 21 additions & 9 deletions compiler-plugin/src/test/scala/Instantiaion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ trait NodeSearch {
* does some testing with its output
*/
object InstantiationTester extends TraversalExtractionTester with NodeSearch {

override def apply(global: Global)(body: global.Tree) = {

val graph: ExtractedGraph = TraversalExtraction(global)(body)(new ExtractedGraph)
Expand All @@ -66,10 +67,7 @@ object InstantiationTester extends TraversalExtractionTester with NodeSearch {
(filterFuncArgs: FilterFuncArguments[ManagedGraphNode, ManagedGraphEdge]) =>
(filterFuncArgs.direction == Egress && filterFuncArgs.edge.data == "declares member"))

println(s"Tracing all acceptable paths from node id ${origin.key} to node id ${target.key}")
println(s"origin node: $origin")
println(s"target node: $target")
println
print(s"Tracing all acceptable paths from ${shortDescription(origin)} to ${shortDescription(target)}...")

def voidFilter(filterFuncArgs: FilterFuncArguments[ManagedGraphNode, ManagedGraphEdge]): Boolean = true
def walkFilter(filterFuncArgs: FilterFuncArguments[ManagedGraphNode, ManagedGraphEdge]): Boolean = {
Expand All @@ -86,15 +84,29 @@ object InstantiationTester extends TraversalExtractionTester with NodeSearch {
paths match {
case None => throw new Exception("relationsnip not found")
case Some(paths) => {
println(s"${paths.size} paths found:")
println(s" ${paths.size} paths found:")
paths.foreach { path =>
println
path.map(id => println(simpleGraph.vertex(id).get))
println(target)
println("Path:")
path.map(id => println(" " + shortDescription(simpleGraph.vertex(id).get)))
println(" " + shortDescription(target))
}
}
}
}
}

/*
* utility function for compact printing of symbols qualified id
*/
def shortDescription(node: ManagedGraphNode) = {
val symbol: ExtractedSymbol = node.data
val shortenedQualifiedId = (symbol.qualifiedId.value.head.name match {
case "<empty>" => symbol.qualifiedId.value.drop(1)
case _ => symbol.qualifiedId.value
}).map(_.name).mkString(".")

s"${symbol.kind} $shortenedQualifiedId (${symbol.id})"
}

}

object MyTestSuite extends TestSuite {
Expand Down

0 comments on commit 74653f1

Please sign in to comment.