diff options
Diffstat (limited to 'test/scaladoc/scala/html/HtmlFactoryTest.scala')
-rw-r--r-- | test/scaladoc/scala/html/HtmlFactoryTest.scala | 195 |
1 files changed, 158 insertions, 37 deletions
diff --git a/test/scaladoc/scala/html/HtmlFactoryTest.scala b/test/scaladoc/scala/html/HtmlFactoryTest.scala index 5b17affbf0..37aa302ac7 100644 --- a/test/scaladoc/scala/html/HtmlFactoryTest.scala +++ b/test/scaladoc/scala/html/HtmlFactoryTest.scala @@ -84,12 +84,7 @@ 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: * @@ -111,20 +106,31 @@ object Test extends Properties("HtmlFactory") { * * NOTE: Comparison is done ignoring all whitespace */ - def checkText(scalaFile: String, checks: List[String], debug: Boolean = true): Boolean = { + def checkText(scalaFile: String, debug: Boolean = true)(checks: (Option[String], String, Boolean)*): Boolean = { val htmlFile = scalaFile.stripSuffix(".scala") + ".html" - val htmlText = createTemplates(scalaFile)(htmlFile).text.replace('→',' ').replaceAll("\\s+","") + val htmlAllFiles = createTemplates(scalaFile) 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 + for ((fileHint, check, expected) <- checks) { + // resolve the file to be checked + val fileName = fileHint match { + case Some(file) => + if (file endsWith ".html") + file + else + file + ".html" + case None => + htmlFile + } + val fileText = htmlAllFiles(fileName).text.replace('→',' ').replaceAll("\\s+","") + val checkText = check.replace('→',' ').replaceAll("\\s+","") + val checkValue = fileText.contains(checkText) == expected + if (debug && (!checkValue)) { + Console.err.println("Check failed: ") + Console.err.println("HTML: " + fileText) + Console.err.println("Check: " + checkText) + } + result &&= checkValue } result @@ -190,9 +196,9 @@ object Test extends Properties("HtmlFactory") { createTemplate("Trac4372.scala") match { case node: scala.xml.Node => { val html = node.toString - html.contains("<span class=\"name\" title=\"gt4s: $plus$colon\">+:</span>") && - html.contains("<span class=\"name\" title=\"gt4s: $minus$colon\">-:</span>") && - html.contains("""<span class="params">(<span name="n">n: <span name="scala.Int" class="extype">Int</span></span>)</span><span class="result">: <span name="scala.Int" class="extype">Int</span></span>""") + html.contains("<span title=\"gt4s: $plus$colon\" class=\"name\">+:</span>") && + html.contains("<span title=\"gt4s: $minus$colon\" class=\"name\">-:</span>") && + html.contains("""<span class="params">(<span name="n">n: <span class="extype" name="scala.Int">Int</span></span>)</span><span class="result">: <span class="extype" name="scala.Int">Int</span></span>""") } case _ => false } @@ -426,40 +432,155 @@ object Test extends Properties("HtmlFactory") { createTemplate("SI_4898.scala") true } - + 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""") - + checkText("SI_5054_q1.scala")( + (None,"""def test(): Int""", true), + (None,"""def test(implicit lost: Int): Int""", false) + ) property("Use cases should keep their flags - final should not be lost") = - checkText1("SI_5054_q2.scala", """final def test(): Int""") + checkText("SI_5054_q2.scala")((None, """final def test(): Int""", true)) property("Use cases should keep their flags - implicit should not be lost") = - checkText1("SI_5054_q3.scala", """implicit def test(): Int""") - + checkText("SI_5054_q3.scala")((None, """implicit def test(): Int""", true)) + property("Use cases should keep their flags - real abstract should not be lost") = - checkText1("SI_5054_q4.scala", """abstract def test(): Int""") + checkText("SI_5054_q4.scala")((None, """abstract def test(): Int""", true)) property("Use cases should keep their flags - traits should not be affected") = - checkText1("SI_5054_q5.scala", """def test(): Int""") + checkText("SI_5054_q5.scala")((None, """def test(): Int""", true)) property("Use cases should keep their flags - traits should not be affected") = - checkText1("SI_5054_q6.scala", """abstract def test(): Int""") + checkText("SI_5054_q6.scala")((None, """abstract def test(): Int""", true)) 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.""")) + checkText("SI_5054_q7.scala")( + (None, """abstract def test2(explicit: Int): Int [use case] This takes the explicit value passed.""", true), + (None, """abstract def test1(): Int [use case] This takes the implicit value in scope.""", true) + ) property("Display correct \"Definition classes\"") = - checkText1("SI_5287.scala", - """def method(): Int + checkText("SI_5287.scala")( + (None, + """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 + Definition Classes SI_5287 SI_5287_B SI_5287_A""", true) + ) // the explanation appears twice, as small comment and full comment + + property("Correct comment inheritance for overriding") = + checkText("implicit-inheritance-override.scala")( + (Some("Base"), + """def function[T](arg1: T, arg2: String): Double + The base comment. + The base comment. And another sentence... + T the type of the first argument + arg1 The T term comment + arg2 The string comment + returns The return comment + """, true), + (Some("DerivedA"), + """def function[T](arg1: T, arg2: String): Double + Overriding the comment, the params and returns comments should stay the same. + Overriding the comment, the params and returns comments should stay the same. + T the type of the first argument + arg1 The T term comment + arg2 The string comment + returns The return comment + """, true), + (Some("DerivedB"), + """def function[T](arg1: T, arg2: String): Double + T the type of the first argument + arg1 The overridden T term comment + arg2 The overridden string comment + returns The return comment + """, true), + (Some("DerivedC"), + """def function[T](arg1: T, arg2: String): Double + T the type of the first argument + arg1 The T term comment + arg2 The string comment + returns The overridden return comment + """, true), + (Some("DerivedD"), + """def function[T](arg1: T, arg2: String): Double + T The overriden type parameter comment + arg1 The T term comment + arg2 The string comment + returns The return comment + """, true) + ) + + for (useCaseFile <- List("UseCaseInheritance", "UseCaseOverrideInheritance")) { + property("Correct comment inheritance for usecases") = + checkText("implicit-inheritance-usecase.scala")( + (Some(useCaseFile), + """def missing_arg[T](arg1: T): Double + [use case] + [use case] + T The type parameter + arg1 The T term comment + returns The return comment + """, true), + (Some(useCaseFile), + """def missing_targ(arg1: Int, arg2: String): Double + [use case] + [use case] + arg1 The T term comment + arg2 The string comment + returns The return comment + """, true), + (Some(useCaseFile), + """def overridden_arg1[T](implicit arg1: T, arg2: String): Double + [use case] + [use case] + T The type parameter + arg1 The overridden T term comment + arg2 The string comment + returns The return comment + """, true), + (Some(useCaseFile), + """def overridden_targ[T](implicit arg1: T, arg2: String): Double + [use case] + [use case] + T The overridden type parameter comment + arg1 The T term comment + arg2 The string comment + returns The return comment + """, true), + (Some(useCaseFile), + """def overridden_return[T](implicit arg1: T, arg2: String): Double + [use case] + [use case] + T The type parameter + arg1 The T term comment + arg2 The string comment + returns The overridden return comment + """, true), + (Some(useCaseFile), + """def added_arg[T](implicit arg1: T, arg2: String, arg3: Float): Double + [use case] + [use case] + T The type parameter + arg1 The T term comment + arg2 The string comment + arg3 The added float comment + returns The return comment + """, true), + (Some(useCaseFile), + """def overridden_comment[T](implicit arg1: T, arg2: String): Double + [use case] The overridden comment. + [use case] The overridden comment. + T The type parameter + arg1 The T term comment + arg2 The string comment + returns The return comment + """, true) + ) + } + { val files = createTemplates("basic.scala") //println(files) |