From e3c5df8ec369047d73a54ed94caebe0a4f26627c Mon Sep 17 00:00:00 2001 From: Philippus Baalman Date: Wed, 22 Feb 2017 21:34:35 +0100 Subject: added missing Inline matches to inlineToStr so it is now exhaustive scala.xml.XML.loadString(tag).text will remove all html tags inside the HtmlTag use a regex to remove html tags inside the tag added some tests for the inlineToStr-method moved inlineToStr to companion object of Page added test for nested html tags --- .../run/inlineToStr-strips-unwanted-text.check | 13 ++++++ .../run/inlineToStr-strips-unwanted-text.scala | 51 ++++++++++++++++++++++ .../scaladoc/run/shortDescription-annotation.scala | 19 ++------ 3 files changed, 68 insertions(+), 15 deletions(-) create mode 100644 test/scaladoc/run/inlineToStr-strips-unwanted-text.check create mode 100644 test/scaladoc/run/inlineToStr-strips-unwanted-text.scala (limited to 'test') diff --git a/test/scaladoc/run/inlineToStr-strips-unwanted-text.check b/test/scaladoc/run/inlineToStr-strips-unwanted-text.check new file mode 100644 index 0000000000..986b58d469 --- /dev/null +++ b/test/scaladoc/run/inlineToStr-strips-unwanted-text.check @@ -0,0 +1,13 @@ +Chain(List(Chain(List(Text(This comment contains ), Superscript(Text(superscript)))))) +Chain(List(Chain(List(Text(This comment contains ), Subscript(Text(subscript)))))) +Chain(List(Chain(List(Text(This comment contains a link ), Link(https://scala.epfl.ch/,Text(https://scala.epfl.ch/)))))) +Chain(List(Chain(List(Text(This comment contains an ), HtmlTag(html tag))))) +Chain(List(Chain(List(Text(This comment contains a), HtmlTag(
), Text( single html tag))))) +Chain(List(Chain(List(Text(This comment contains nested ), HtmlTag(html
tags
))))) +This comment contains superscript +This comment contains subscript +This comment contains a link https://scala.epfl.ch/ +This comment contains an html tag +This comment contains a single html tag +This comment contains nested html tags +Done. diff --git a/test/scaladoc/run/inlineToStr-strips-unwanted-text.scala b/test/scaladoc/run/inlineToStr-strips-unwanted-text.scala new file mode 100644 index 0000000000..f51b7d6b3f --- /dev/null +++ b/test/scaladoc/run/inlineToStr-strips-unwanted-text.scala @@ -0,0 +1,51 @@ +import scala.tools.nsc.doc.html.Page +import scala.tools.nsc.doc.model._ +import scala.tools.partest.ScaladocModelTest + +object Test extends ScaladocModelTest { + + override def code = """ + /** This comment contains ^superscript^ */ + class Foo { + /** This comment contains ,,subscript,, */ + def bar = ??? + + /** This comment contains a link [[https://scala.epfl.ch/]] */ + def baz = ??? + + /** This comment contains an html tag */ + def qux = ??? + + /** This comment contains a
single html tag */ + def quux = ??? + + /** This comment contains nested html
tags
*/ + def quuz = ??? + } + """ + def scaladocSettings = "" + + def testModel(root: Package) = { + import scala.tools.nsc.doc.base.comment._ + import access._ + + val foo = root._class("Foo") + val bar = foo._method("bar") + val baz = foo._method("baz") + val qux = foo._method("qux") + val quux = foo._method("quux") + val quuz = foo._method("quuz") + println(foo.comment.get.short) + println(bar.comment.get.short) + println(baz.comment.get.short) + println(qux.comment.get.short) + println(quux.comment.get.short) + println(quuz.comment.get.short) + println(Page.inlineToStr(foo.comment.get.short)) + println(Page.inlineToStr(bar.comment.get.short)) + println(Page.inlineToStr(baz.comment.get.short)) + println(Page.inlineToStr(qux.comment.get.short)) + println(Page.inlineToStr(quux.comment.get.short)) + println(Page.inlineToStr(quuz.comment.get.short)) + } +} diff --git a/test/scaladoc/run/shortDescription-annotation.scala b/test/scaladoc/run/shortDescription-annotation.scala index 0e2950f4f9..4f9a891133 100644 --- a/test/scaladoc/run/shortDescription-annotation.scala +++ b/test/scaladoc/run/shortDescription-annotation.scala @@ -1,3 +1,4 @@ +import scala.tools.nsc.doc.html.Page import scala.tools.nsc.doc.model._ import scala.tools.partest.ScaladocModelTest @@ -26,30 +27,18 @@ object Test extends ScaladocModelTest { import scala.tools.nsc.doc.base.comment._ import access._ - def inlineToStr(inl: Inline): String = inl match { - case Chain(items) => items flatMap (inlineToStr(_)) mkString "" - case Italic(in) => inlineToStr(in) - case Bold(in) => inlineToStr(in) - case Underline(in) => inlineToStr(in) - case Monospace(in) => inlineToStr(in) - case Text(text) => text - case Summary(in) => inlineToStr(in) - case EntityLink(Text(text), _) => text - case _ => inl.toString - } - val foo = rootPackage._package("a")._class("Foo") // Assert that the class has the correct short description - val classDesc = inlineToStr(foo.comment.get.short) + val classDesc = Page.inlineToStr(foo.comment.get.short) assert(classDesc == "This one should appear", classDesc) // Assert that the `foo` method has the correct short description - val fooDesc = inlineToStr(foo._method("foo").comment.get.short) + val fooDesc = Page.inlineToStr(foo._method("foo").comment.get.short) assert(fooDesc == "This comment should appear", fooDesc) // Assert that the `goo` method has the correct short description - val gooDesc = inlineToStr(foo._method("goo").comment.get.short) + val gooDesc = Page.inlineToStr(foo._method("goo").comment.get.short) assert(gooDesc == "This comment should appear", gooDesc) } } -- cgit v1.2.3