|
| 1 | +import scala.tools.nsc.doc.model._ |
| 2 | +import scala.tools.nsc.doc.model.comment._ |
| 3 | +import scala.tools.partest.ScaladocModelTest |
| 4 | +import java.net.{URI, URL} |
| 5 | +import java.io.File |
| 6 | + |
| 7 | +object Test extends ScaladocModelTest { |
| 8 | + |
| 9 | + override def code = |
| 10 | + """ |
| 11 | + /** See: |
| 12 | + * - [[scala.collection.Map]] Simple linking |
| 13 | + * - [[scala.collection.immutable.::]] Linking with symbolic name |
| 14 | + * - [[scala.Int]].toLong Linking to a class |
| 15 | + * - [[scala.Predef]] Linking to an object |
| 16 | + * - [[scala.Int.toLong]] Linking to a method |
| 17 | + * - [[scala]] Linking to a package |
| 18 | + * - [[scala.AbstractMethodError]] Linking to a member in the package object |
| 19 | + * - [[scala.Predef.String]] Linking to a member in an object |
| 20 | + * |
| 21 | + * Don't look at: |
| 22 | + * - [[scala.NoLink]] Not linking :) |
| 23 | + */ |
| 24 | + object Test { |
| 25 | + def foo(param: Any) {} |
| 26 | + def barr(l: scala.collection.immutable.List[Any]) {} |
| 27 | + def bar(l: List[String]) {} // TODO: Should be able to link to type aliases |
| 28 | + def baz(d: java.util.Date) {} // Should not be resolved |
| 29 | + } |
| 30 | + """ |
| 31 | + |
| 32 | + def scalaURL = "http://bog.us" |
| 33 | + |
| 34 | + override def scaladocSettings = { |
| 35 | + val scalaLibUri = getClass.getClassLoader.getResource("scala/Function1.class").toURI.getSchemeSpecificPart.split("!")(0) |
| 36 | + val scalaLib = new File(new URL(scalaLibUri).getPath).getPath |
| 37 | + val extArg = new URI("file", scalaLib, scalaURL).toString |
| 38 | + "-no-link-warnings -doc-external-uris " + extArg |
| 39 | + } |
| 40 | + |
| 41 | + def testModel(rootPackage: Package) { |
| 42 | + import access._ |
| 43 | + val test = rootPackage._object("Test") |
| 44 | + |
| 45 | + def check(memberDef: Def, expected: Int) { |
| 46 | + val externals = memberDef.valueParams(0)(0).resultType.refEntity collect { |
| 47 | + case (_, (LinkToExternal(name, url), _)) => assert(url.contains(scalaURL)); name |
| 48 | + } |
| 49 | + assert(externals.size == expected) |
| 50 | + } |
| 51 | + |
| 52 | + check(test._method("foo"), 1) |
| 53 | + check(test._method("bar"), 0) |
| 54 | + check(test._method("barr"), 2) |
| 55 | + check(test._method("baz"), 0) |
| 56 | + |
| 57 | + val expectedUrls = collection.mutable.Set[String]( |
| 58 | + "scala.collection.Map", |
| 59 | + "scala.collection.immutable.::", |
| 60 | + "scala.Int", |
| 61 | + "scala.Predef$", |
| 62 | + "scala.Int@toLong:Long", |
| 63 | + "scala.package", |
| 64 | + "scala.package@AbstractMethodError=AbstractMethodError", |
| 65 | + "scala.Predef$@String=String" |
| 66 | + ).map(scalaURL + "/index.html#" + _) |
| 67 | + |
| 68 | + def isExpectedExternalLink(l: EntityLink) = l.link match { |
| 69 | + case LinkToExternal(name, url) => assert(expectedUrls contains url, url); true |
| 70 | + case _ => false |
| 71 | + } |
| 72 | + |
| 73 | + assert(countLinks(test.comment.get, isExpectedExternalLink) == 8, |
| 74 | + countLinks(test.comment.get, isExpectedExternalLink) + " == 8") |
| 75 | + } |
| 76 | +} |
0 commit comments