+ new test: a template should impact all the pages within the uriList
authorAlexandre Bertails <bertails@w3.org>
Wed, 27 Jul 2011 17:29:31 -0400
changeset 7 4fbcf56effae
parent 6 7e0ad96e9467
child 8 776f07e1dce3
+ new test: a template should impact all the pages within the uriList
src/main/scala/FragmentDependencies.scala
src/test/scala/Test.scala
--- a/src/main/scala/FragmentDependencies.scala	Wed Jul 27 17:18:40 2011 -0400
+++ b/src/main/scala/FragmentDependencies.scala	Wed Jul 27 17:29:31 2011 -0400
@@ -28,8 +28,8 @@
   }
 
   /** returns the pages impacted by this page through the given recipe */
-  def impactedPage(recipe:Recipe):Seq[Page] =
-    recipe impactedPage this
+  def impactedPages(recipe:Recipe):Seq[Page] =
+    recipe impactedPages this
 
   /** GETs this page and extracts the pages that it contains
     * There must be on page per line
@@ -69,13 +69,13 @@
     definedIn getOrElse "<unknown>"
 
   /** computes the forward dependencies for the given page  */
-  def impactedPage(page:Page):Seq[Page] =
+  def impactedPages(page:Page):Seq[Page] =
     template match {
       // if the given page is used as a template,
       // returns the pages from the <uriList>
       case Some(t) if t == page.url => targets
       // else, be clever and delegate to the rules
-      case _                        => rules flatMap ( _.impactedPage(page, regex) )
+      case _                        => rules flatMap ( _.impactedPages(page, regex) )
     }
 
 }
@@ -105,7 +105,7 @@
     * @param from the page that could be triggered by this rule
     * @param to the potential target for this rules
     */
-  def impactedPage(from:Page, to:Regex):Option[Page] = {
+  def impactedPages(from:Page, to:Regex):Option[Page] = {
     if (source contains "$1") {
       // yep, the generator wasn't designed with forward dependencies in mind...
       val regex = new Regex(source.replaceAll("""\$1""", """(.*?)"""))
@@ -187,7 +187,7 @@
       for {
         page <- pages
         recipe <- recipes
-        impacted <- page impactedPage recipe
+        impacted <- page impactedPages recipe
       } yield impacted
     impacted.distinct
   }
--- a/src/test/scala/Test.scala	Wed Jul 27 17:18:40 2011 -0400
+++ b/src/test/scala/Test.scala	Wed Jul 27 17:29:31 2011 -0400
@@ -10,6 +10,7 @@
   val tr_techs = Recipe.fromURL("http://www.w3.org/Web/fragments/tr-techs.xml")
   val list_status = Page("http://www.w3.org/Web/fragments/list-status")
   val pages = list_status.extractPages
+  val template = Page("http://www.w3.org/2008/site/templates/base.html")
 
   test("tr-techs.xml should be not empty") {
     assert(tr_techs nonEmpty)
@@ -34,9 +35,17 @@
       page <- pages
       dependentPage <- page dependentPages recipe
     } {
-      val impactedPages = dependentPage impactedPage recipe
+      val impactedPages = dependentPage impactedPages recipe
       assert(impactedPages contains page)
     }
   }
 
+  test("a template should impact all the pages within the uriList") {
+    val recipe1 = tr_techs.head
+    val impactedPages = template impactedPages recipe1
+    println(impactedPages)
+    println(recipe1.targetsPage.extractPages)
+    assert(impactedPages sameElements (recipe1.targetsPage.extractPages))
+  }
+
 }