summaryrefslogtreecommitdiff
path: root/test/scaladoc/scala/html/HtmlFactoryTest.scala
diff options
context:
space:
mode:
authorVlad Ureche <vlad.ureche@gmail.com>2012-03-16 01:25:36 +0100
committerVlad Ureche <vlad.ureche@gmail.com>2012-03-16 01:25:36 +0100
commitdca8725cbb04e38f86095fe7fb561fa78cdde9b2 (patch)
tree2da2b213cb448ab7068e9347f04ce12405530ab6 /test/scaladoc/scala/html/HtmlFactoryTest.scala
parentee51b6e1b1bc4bd60e6f6bbaea6eb3d4be8b3c97 (diff)
downloadscala-dca8725cbb04e38f86095fe7fb561fa78cdde9b2.tar.gz
scala-dca8725cbb04e38f86095fe7fb561fa78cdde9b2.tar.bz2
scala-dca8725cbb04e38f86095fe7fb561fa78cdde9b2.zip
Merged and cleaned the 'feature/inheritdoc' branch
Diffstat (limited to 'test/scaladoc/scala/html/HtmlFactoryTest.scala')
-rw-r--r--test/scaladoc/scala/html/HtmlFactoryTest.scala196
1 files changed, 143 insertions, 53 deletions
diff --git a/test/scaladoc/scala/html/HtmlFactoryTest.scala b/test/scaladoc/scala/html/HtmlFactoryTest.scala
index 37aa302ac7..ead7c9e99c 100644
--- a/test/scaladoc/scala/html/HtmlFactoryTest.scala
+++ b/test/scaladoc/scala/html/HtmlFactoryTest.scala
@@ -21,9 +21,9 @@ object XMLUtil {
}
object Test extends Properties("HtmlFactory") {
-
- final val RESOURCES = "test/scaladoc/resources/"
-
+
+ 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
@@ -87,7 +87,7 @@ object Test extends Properties("HtmlFactory") {
/**
* This tests the text without the markup - ex:
- *
+ *
* <h4 class="signature">
* <span class="modifier_kind">
* <span class="modifier">implicit</span>
@@ -97,24 +97,24 @@ object Test extends Properties("HtmlFactory") {
* <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, debug: Boolean = true)(checks: (Option[String], String, Boolean)*): Boolean = {
- val htmlFile = scalaFile.stripSuffix(".scala") + ".html"
+ val htmlFile = scalaFile.stripSuffix(".scala") + ".html"
val htmlAllFiles = createTemplates(scalaFile)
var result = true
-
+
for ((fileHint, check, expected) <- checks) {
// resolve the file to be checked
val fileName = fileHint match {
- case Some(file) =>
+ case Some(file) =>
if (file endsWith ".html")
file
else
@@ -122,20 +122,27 @@ object Test extends Properties("HtmlFactory") {
case None =>
htmlFile
}
- val fileText = htmlAllFiles(fileName).text.replace('→',' ').replaceAll("\\s+","")
- val checkText = check.replace('→',' ').replaceAll("\\s+","")
+ val fileTextPretty = htmlAllFiles(fileName).text.replace('→',' ').replaceAll("\\s+"," ")
+ val fileText = fileTextPretty.replaceAll(" ", "")
+
+ val checkTextPretty = check.replace('→',' ').replaceAll("\\s+"," ")
+ val checkText = checkTextPretty.replaceAll(" ", "")
+
val checkValue = fileText.contains(checkText) == expected
if (debug && (!checkValue)) {
- Console.err.println("Check failed: ")
- Console.err.println("HTML: " + fileText)
- Console.err.println("Check: " + checkText)
+ Console.err.println("")
+ Console.err.println("HTML Check failed for resource file " + scalaFile + ":")
+ Console.err.println("Could not match: \n" + checkTextPretty)
+ Console.err.println("In the extracted HTML text: \n" + fileTextPretty)
+ Console.err.println("NOTE: The whitespaces are eliminated before matching!")
+ Console.err.println("")
}
- result &&= checkValue
+ result &&= checkValue
}
-
+
result
}
-
+
def shortComments(root: scala.xml.Node) =
XMLUtil.stripGroup(root).descendant.flatMap {
@@ -284,7 +291,7 @@ object Test extends Properties("HtmlFactory") {
case _ => false
}
}
-
+
property("Trac #4420 - no whitespace at end of line") = {
val files = createTemplates("Trac4420.scala")
@@ -432,47 +439,46 @@ object Test extends Properties("HtmlFactory") {
createTemplate("SI_4898.scala")
true
}
-
+
property("Use cases should override their original members") =
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") =
+ property("Use cases should keep their flags - final should not be lost") =
checkText("SI_5054_q2.scala")((None, """final def test(): Int""", true))
-
- property("Use cases should keep their flags - implicit should not be lost") =
+
+ property("Use cases should keep their flags - implicit should not be lost") =
checkText("SI_5054_q3.scala")((None, """implicit def test(): Int""", true))
-
- property("Use cases should keep their flags - real abstract should not be lost") =
+
+ property("Use cases should keep their flags - real abstract should not be lost") =
checkText("SI_5054_q4.scala")((None, """abstract def test(): Int""", true))
- property("Use cases should keep their flags - traits should not be affected") =
+ property("Use cases should keep their flags - traits should not be affected") =
checkText("SI_5054_q5.scala")((None, """def test(): Int""", true))
- property("Use cases should keep their flags - traits should not be affected") =
+ property("Use cases should keep their flags - traits should not be affected") =
checkText("SI_5054_q6.scala")((None, """abstract def test(): Int""", true))
-
- property("Use case individual signature test") =
+
+ property("Use case individual signature test") =
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\"") =
- checkText("SI_5287.scala")(
+ property("Display correct \"Definition classes\"") =
+ 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""", true)
- ) // the explanation appears twice, as small comment and full comment
-
-
- property("Correct comment inheritance for overriding") =
+ ) // the explanation appears twice, as small comment and full comment
+
+ property("Correct comment inheritance for overriding") =
checkText("implicit-inheritance-override.scala")(
- (Some("Base"),
+ (Some("Base"),
"""def function[T](arg1: T, arg2: String): Double
The base comment.
The base comment. And another sentence...
@@ -481,7 +487,7 @@ object Test extends Properties("HtmlFactory") {
arg2 The string comment
returns The return comment
""", true),
- (Some("DerivedA"),
+ (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.
@@ -490,21 +496,21 @@ object Test extends Properties("HtmlFactory") {
arg2 The string comment
returns The return comment
""", true),
- (Some("DerivedB"),
+ (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"),
+ (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"),
+ (Some("DerivedD"),
"""def function[T](arg1: T, arg2: String): Double
T The overriden type parameter comment
arg1 The T term comment
@@ -512,11 +518,11 @@ object Test extends Properties("HtmlFactory") {
returns The return comment
""", true)
)
-
+
for (useCaseFile <- List("UseCaseInheritance", "UseCaseOverrideInheritance")) {
- property("Correct comment inheritance for usecases") =
+ property("Correct comment inheritance for usecases") =
checkText("implicit-inheritance-usecase.scala")(
- (Some(useCaseFile),
+ (Some(useCaseFile),
"""def missing_arg[T](arg1: T): Double
[use case]
[use case]
@@ -524,7 +530,7 @@ object Test extends Properties("HtmlFactory") {
arg1 The T term comment
returns The return comment
""", true),
- (Some(useCaseFile),
+ (Some(useCaseFile),
"""def missing_targ(arg1: Int, arg2: String): Double
[use case]
[use case]
@@ -532,7 +538,7 @@ object Test extends Properties("HtmlFactory") {
arg2 The string comment
returns The return comment
""", true),
- (Some(useCaseFile),
+ (Some(useCaseFile),
"""def overridden_arg1[T](implicit arg1: T, arg2: String): Double
[use case]
[use case]
@@ -541,7 +547,7 @@ object Test extends Properties("HtmlFactory") {
arg2 The string comment
returns The return comment
""", true),
- (Some(useCaseFile),
+ (Some(useCaseFile),
"""def overridden_targ[T](implicit arg1: T, arg2: String): Double
[use case]
[use case]
@@ -550,7 +556,7 @@ object Test extends Properties("HtmlFactory") {
arg2 The string comment
returns The return comment
""", true),
- (Some(useCaseFile),
+ (Some(useCaseFile),
"""def overridden_return[T](implicit arg1: T, arg2: String): Double
[use case]
[use case]
@@ -559,7 +565,7 @@ object Test extends Properties("HtmlFactory") {
arg2 The string comment
returns The overridden return comment
""", true),
- (Some(useCaseFile),
+ (Some(useCaseFile),
"""def added_arg[T](implicit arg1: T, arg2: String, arg3: Float): Double
[use case]
[use case]
@@ -569,7 +575,7 @@ object Test extends Properties("HtmlFactory") {
arg3 The added float comment
returns The return comment
""", true),
- (Some(useCaseFile),
+ (Some(useCaseFile),
"""def overridden_comment[T](implicit arg1: T, arg2: String): Double
[use case] The overridden comment.
[use case] The overridden comment.
@@ -578,9 +584,93 @@ object Test extends Properties("HtmlFactory") {
arg2 The string comment
returns The return comment
""", true)
- )
- }
-
+ )
+ }
+
+ property("Correct explicit inheritance for override") =
+ checkText("explicit-inheritance-override.scala")(
+ (Some("InheritDocDerived"),
+ """def function[T](arg1: T, arg2: String): Double
+ Starting line
+ Starting line
+ The base comment. And another sentence...
+ The base comment. And another sentence...
+ Ending line
+ T StartT the type of the first argument EndT
+ arg1 Start1 The T term comment End1
+ arg2 Start2 The string comment End2
+ returns StartRet The return comment EndRet
+ Definition Classes InheritDocDerived → InheritDocBase
+ Example: StartExample function[Int](3, "something") EndExample
+ Version StartVer 0.0.2 EndVer
+ Since StartSince 0.0.1 EndSince
+ Exceptions thrown
+ SomeException StartEx if the function is not called with correct parameters EndEx
+ SomeOtherException StartSOE Should Warn <invalid inheritdoc annotation> EndSOE
+ To do StartTodo Call mom. And dad! EndTodo
+ Note StartNote Be careful! EndNote
+ See also StartSee The Manual EndSee
+ """, true))
+
+ property("Correct explicit inheritance for usecase") =
+ checkText("explicit-inheritance-usecase.scala")(
+ (Some("UseCaseInheritDoc"),
+ """def function[T](arg1: T, arg2: String): Double
+ [use case] Starting line
+ [use case] Starting line
+ The base comment. And another sentence...
+ The base comment. And another sentence...
+ Ending line
+ T StartT the type of the first argument EndT
+ arg1 Start1 The T term comment End1
+ arg2 Start2 The string comment End2
+ returns StartRet The return comment EndRet
+ Example: StartExample function[Int](3,"something") EndExample
+ Version StartVer 0.0.2 EndVer
+ Since StartSince 0.0.1 EndSince
+ Exceptions thrown
+ SomeException StartEx if the function is not called with correct parameters EndEx
+ SomeOtherException StartSOE Should Warn <invalid inheritdoc annotation> EndSOE
+ To do StartTodo Call mom. And dad! EndTodo
+ Note StartNote Be careful! EndNote
+ See also StartSee The Manual EndSee
+ """, true))
+
+ property("Correct explicit inheritance in corner cases") =
+ checkText("inheritdoc-corner-cases.scala")(
+ (Some("D"),
+ """def hello1: Int
+ Inherited: Hello 1 comment
+ Inherited: Hello 1 comment
+ Definition Classes D → A
+ """, true),
+ (Some("D"),
+ """def hello2: Int
+ Inherited: Hello 2 comment
+ Inherited: Hello 2 comment
+ Definition Classes D → B
+ """, true),
+ (Some("G"),
+ """def hello1: Int
+ Inherited: Hello 1 comment
+ Inherited: Hello 1 comment
+ Definition Classes G → D → A
+ """, true),
+ (Some("G"),
+ """def hello2: Int
+ Inherited: Hello 2 comment
+ Inherited: Hello 2 comment
+ Definition Classes G → D → B
+ """, true),
+ (Some("I"),
+ """def hello1(i: Int): Unit
+ [use case] Inherited: Hello 1 comment
+ [use case] Inherited: Hello 1 comment
+ Definition Classes I → G → D → A
+ """, true)
+ // traits E, F and H shouldn't crash scaladoc but we don't need to check the output
+ )
+
{
val files = createTemplates("basic.scala")
//println(files)