diff options
author | Vlad Ureche <vlad.ureche@epfl.ch> | 2011-12-16 21:18:38 +0100 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-12-16 14:18:03 -0800 |
commit | 98108febce145b9f2842937d3ac4a9c1d24f6108 (patch) | |
tree | 31921e3138525876412539bf5dd47a4d3751c608 /test | |
parent | 2f5f7c16870ae1fa97bbca1642659ab8c104b442 (diff) | |
download | scala-98108febce145b9f2842937d3ac4a9c1d24f6108.tar.gz scala-98108febce145b9f2842937d3ac4a9c1d24f6108.tar.bz2 scala-98108febce145b9f2842937d3ac4a9c1d24f6108.zip |
Fixed "Definition Classes" in bug #5287
Diffstat (limited to 'test')
-rw-r--r-- | test/scaladoc/resources/SI_5054_q7.scala | 8 | ||||
-rw-r--r-- | test/scaladoc/resources/SI_5287.scala | 17 | ||||
-rw-r--r-- | test/scaladoc/scala/html.flags | 1 | ||||
-rw-r--r-- | test/scaladoc/scala/html/HtmlFactoryTest.flags | 1 | ||||
-rw-r--r-- | test/scaladoc/scala/html/HtmlFactoryTest.scala | 183 |
5 files changed, 104 insertions, 106 deletions
diff --git a/test/scaladoc/resources/SI_5054_q7.scala b/test/scaladoc/resources/SI_5054_q7.scala index 26d4b5fcf4..1bd120e30c 100644 --- a/test/scaladoc/resources/SI_5054_q7.scala +++ b/test/scaladoc/resources/SI_5054_q7.scala @@ -6,17 +6,17 @@ trait SI_5054_q7 { * * @param lost a lost parameter * @return some integer - * @usecase def test(): Int + * @usecase def test1(): Int * * This takes the implicit value in scope. * - * Example: `test()` + * Example: `test1()` * - * @usecase def test(explicit: Int): Int + * @usecase def test2(explicit: Int): Int * * This takes the explicit value passed. * - * Example: `test(3)` + * Example: `test2(3)` */ def test(implicit lost: Int): Int } diff --git a/test/scaladoc/resources/SI_5287.scala b/test/scaladoc/resources/SI_5287.scala new file mode 100644 index 0000000000..141ab15325 --- /dev/null +++ b/test/scaladoc/resources/SI_5287.scala @@ -0,0 +1,17 @@ +trait SI_5287_A { + def method(implicit a: Int): Int = a +} + +trait SI_5287_B extends SI_5287_A { + override def method(implicit a: Int): Int = a + 1 +} + +trait SI_5287 extends SI_5287_B{ + /** + * Some explanation + * + * @usecase def method(): Int + * The usecase explanation + */ + override def method(implicit a: Int): Int = a + 3 +}
\ No newline at end of file diff --git a/test/scaladoc/scala/html.flags b/test/scaladoc/scala/html.flags new file mode 100644 index 0000000000..b2264ec4f4 --- /dev/null +++ b/test/scaladoc/scala/html.flags @@ -0,0 +1 @@ +-encoding UTF-8
\ No newline at end of file diff --git a/test/scaladoc/scala/html/HtmlFactoryTest.flags b/test/scaladoc/scala/html/HtmlFactoryTest.flags new file mode 100644 index 0000000000..b2264ec4f4 --- /dev/null +++ b/test/scaladoc/scala/html/HtmlFactoryTest.flags @@ -0,0 +1 @@ +-encoding UTF-8
\ No newline at end of file diff --git a/test/scaladoc/scala/html/HtmlFactoryTest.scala b/test/scaladoc/scala/html/HtmlFactoryTest.scala index d1bfbb023f..5b17affbf0 100644 --- a/test/scaladoc/scala/html/HtmlFactoryTest.scala +++ b/test/scaladoc/scala/html/HtmlFactoryTest.scala @@ -21,6 +21,9 @@ object XMLUtil { } object Test extends Properties("HtmlFactory") { + + final val RESOURCES = "test/scaladoc/resources/" + import scala.tools.nsc.doc.{DocFactory, Settings} import scala.tools.nsc.doc.model.IndexModelFactory import scala.tools.nsc.doc.html.HtmlFactory @@ -47,7 +50,7 @@ object Test extends Properties("HtmlFactory") { def createTemplates(basename: String) = { val result = scala.collection.mutable.Map[String, scala.xml.NodeSeq]() - createFactory.makeUniverse(List("test/scaladoc/resources/"+basename)) match { + createFactory.makeUniverse(List(RESOURCES+basename)) match { case Some(universe) => { val index = IndexModelFactory.makeIndex(universe) (new HtmlFactory(universe, index)).writeTemplates((page) => { @@ -61,7 +64,7 @@ object Test extends Properties("HtmlFactory") { } def createReferenceIndex(basename: String) = { - createFactory.makeUniverse(List("test/scaladoc/resources/"+basename)) match { + createFactory.makeUniverse(List(RESOURCES+basename)) match { case Some(universe) => { val index = IndexModelFactory.makeIndex(universe) val pages = index.firstLetterIndex.map({ @@ -81,6 +84,52 @@ object Test extends Properties("HtmlFactory") { val html = scala.stripSuffix(".scala") + ".html" createTemplates(scala)(html) } + + /** + * See checkTextOnly(scalaFile: String, checks: List[String]) + */ + def checkText1(scalaFile: String, check: String, debug: Boolean = true): Boolean = checkText(scalaFile, List(check), debug) + + /** + * This tests the text without the markup - ex: + * + * <h4 class="signature"> + * <span class="modifier_kind"> + * <span class="modifier">implicit</span> + * <span class="kind">def</span> + * </span> + * <span class="symbol"> + * <span class="name">test</span><span class="params">()</span><span class="result">: <span name="scala.Int" class="extype">Int</span></span> + * </span> + * </h4> + * + * becomes: + * + * implicit def test(): Int + * + * and is required to contain the text in the given checks + * + * NOTE: Comparison is done ignoring all whitespace + */ + def checkText(scalaFile: String, checks: List[String], debug: Boolean = true): Boolean = { + val htmlFile = scalaFile.stripSuffix(".scala") + ".html" + val htmlText = createTemplates(scalaFile)(htmlFile).text.replace('→',' ').replaceAll("\\s+","") + var result = true + + for (check <- checks) { + val checkText = check.replace('→',' ').replaceAll("\\s+","") + val checkValue = htmlText.contains(checkText) + if (debug && (!checkValue)) { + Console.err.println("Check failed: ") + Console.err.println("HTML: " + htmlText) + Console.err.println("Check: " + checkText) + } + result &&= checkValue + } + + result + } + def shortComments(root: scala.xml.Node) = XMLUtil.stripGroup(root).descendant.flatMap { @@ -377,113 +426,43 @@ object Test extends Properties("HtmlFactory") { createTemplate("SI_4898.scala") true } - - // A piece of the signature - corresponding to the use case - def signature(no: Int, modifier: String) = (""" - <li visbl="pub" name="SI_5054_q""" + no + """#test" data-isabs="false"> - <a id="test():Int"></a> - <h4 class="signature"> - <span class="modifier_kind"> - <span class="modifier">""" + modifier + """</span> - <span class="kind">def</span> - </span> - <span class="symbol"> - <span class="name">test</span><span class="params">()</span><span class="result">: <span name="scala.Int" class="extype">Int</span></span> - </span> - </h4> - <p class="shortcomment cmt">[use case] - </p> - </li>""").replaceAll("\\s+", "") - property("Use cases should override their original members") = { - createTemplate("SI_5054_q1.scala") match { - case node: scala.xml.Node => - node.toString.replaceAll("\\s+","").contains(signature(1, "")) - case _ => false - } - } - - property("Use cases should keep their flags - final should not be lost") = { - createTemplate("SI_5054_q2.scala") match { - case node: scala.xml.Node => - node.toString.replaceAll("\\s+","").contains(signature(2, "final")) - case _ => false - } - } + property("Use cases should override their original members") = + checkText1("SI_5054_q1.scala", """def test(): Int""") && + !checkText1("SI_5054_q1.scala", """def test(implicit lost: Int): Int""") - property("Use cases should keep their flags - implicit should not be lost") = { - createTemplate("SI_5054_q3.scala") match { - case node: scala.xml.Node => - node.toString.replaceAll("\\s+","").contains(signature(3, "implicit")) - case _ => false - } - } - property("Use cases should keep their flags - real abstract should not be lost") = { - createTemplate("SI_5054_q4.scala") match { - case node: scala.xml.Node => - node.toString.replaceAll("\\s+","").contains(signature(4, "abstract")) - case _ => false - } - } - - property("Use cases should keep their flags - traits should not be affected") = { - createTemplate("SI_5054_q5.scala") match { - case node: scala.xml.Node => - node.toString.replaceAll("\\s+","").contains(signature(5, "")) - case _ => false - } - } - - property("Use cases should keep their flags - traits should not be affected") = { - createTemplate("SI_5054_q6.scala") match { - case node: scala.xml.Node => - node.toString.replaceAll("\\s+","").contains(signature(6, "abstract")) - case _ => false - } - } + property("Use cases should keep their flags - final should not be lost") = + checkText1("SI_5054_q2.scala", """final def test(): Int""") - val useCaseExplanation = """ - </li><li visbl="pub" name="SI_5054_q7#test" data-isabs="false"> - <a id="test():Int"></a> - <h4 class="signature"> - <span class="modifier_kind"> - <span class="modifier">abstract </span> - <span class="kind">def</span> - </span> - <span class="symbol"> - <span class="name">test</span><span class="params">()</span><span class="result">: <span name="scala.Int" class="extype">Int</span></span> - </span> - </h4> - <p class="shortcomment cmt">[use case] This takes the implicit value in scope.</p><div class="fullcomment">[use case] <div class="comment cmt"><p>This takes the implicit value in scope.</p><p>Example: <code>test()</code></p></div><dl class="paramcmts block"><dt>returns</dt><dd class="cmt"><p>some integer - </p></dd></dl></div> - </li><li visbl="pub" name="SI_5054_q7#test" data-isabs="false"> - <a id="test(Int):Int"></a> - <h4 class="signature"> - <span class="modifier_kind"> - <span class="modifier">abstract </span> - <span class="kind">def</span> - </span> - <span class="symbol"> - <span class="name">test</span><span class="params">(<span name="explicit">explicit: <span name="scala.Int" class="extype">Int</span></span>)</span><span class="result">: <span name="scala.Int" class="extype">Int</span></span> - </span> - </h4> - <p class="shortcomment cmt">[use case] This takes the explicit value passed.</p><div class="fullcomment">[use case] <div class="comment cmt"><p>This takes the explicit value passed.</p><p>Example: <code>test(3)</code></p></div><dl class="paramcmts block"><dt>returns</dt><dd class="cmt"><p>some integer - </p></dd></dl></div> - </li> - """.replaceAll("\\s+","") - - property("Use case individual signature test") = { - createTemplate("SI_5054_q7.scala") match { - case node: scala.xml.Node => - node.toString.replaceAll("\\s+","").contains(useCaseExplanation) - case _ => false - } - } + property("Use cases should keep their flags - implicit should not be lost") = + checkText1("SI_5054_q3.scala", """implicit def test(): Int""") + + property("Use cases should keep their flags - real abstract should not be lost") = + checkText1("SI_5054_q4.scala", """abstract def test(): Int""") + + property("Use cases should keep their flags - traits should not be affected") = + checkText1("SI_5054_q5.scala", """def test(): Int""") + + property("Use cases should keep their flags - traits should not be affected") = + checkText1("SI_5054_q6.scala", """abstract def test(): Int""") + + property("Use case individual signature test") = + checkText("SI_5054_q7.scala", List( + """abstract def test2(explicit: Int): Int [use case] This takes the explicit value passed.""", + """abstract def test1(): Int [use case] This takes the implicit value in scope.""")) + + property("Display correct \"Definition classes\"") = + checkText1("SI_5287.scala", + """def method(): Int + [use case] The usecase explanation + [use case] The usecase explanation + Definition Classes SI_5287 SI_5287_B SI_5287_A""", debug=true) + // explanation appears twice, as small comment and full comment { val files = createTemplates("basic.scala") - println(files) + //println(files) property("class") = files.get("com/example/p1/Clazz.html") match { case Some(node: scala.xml.Node) => { |