diff options
Diffstat (limited to 'test')
26 files changed, 421 insertions, 53 deletions
diff --git a/test/files/neg/no-predef.check b/test/files/neg/no-predef.check index a63d8c5ba5..f5c2e82fe1 100644 --- a/test/files/neg/no-predef.check +++ b/test/files/neg/no-predef.check @@ -1,11 +1,11 @@ no-predef.scala:2: error: type mismatch; - found : scala.Long(5L) - required: java.lang.Long + found : Long (in scala) + required: Long (in java.lang) def f1 = 5L: java.lang.Long ^ no-predef.scala:3: error: type mismatch; - found : java.lang.Long - required: scala.Long + found : Long (in java.lang) + required: Long (in scala) def f2 = new java.lang.Long(5) : Long ^ no-predef.scala:4: error: value map is not a member of String diff --git a/test/files/neg/t10207.check b/test/files/neg/t10207.check new file mode 100755 index 0000000000..3330db44a5 --- /dev/null +++ b/test/files/neg/t10207.check @@ -0,0 +1,4 @@ +t10207.scala:14: error: too many arguments (2) for method apply: (key: Int)scala.collection.mutable.ArrayBuffer[String] in trait MapLike + m(1, (_ => empty)) ++= AB("eins", "uno") + ^ +one error found diff --git a/test/files/neg/t10207.scala b/test/files/neg/t10207.scala new file mode 100644 index 0000000000..2dfc5d75c9 --- /dev/null +++ b/test/files/neg/t10207.scala @@ -0,0 +1,16 @@ + +// Was: +// warning: an unexpected type representation reached the compiler backend +// Now: +// error: too many arguments (2) for method apply: (key: Int)scala.collection.mutable.ArrayBuffer[String] in trait MapLike + +trait Test { + import collection.mutable.{Map=>MMap, ArrayBuffer=>AB} + + val m = MMap((1 -> AB("one"))) + + val empty = AB[String]() + + m(1, (_ => empty)) ++= AB("eins", "uno") +} + diff --git a/test/files/neg/t2102.check b/test/files/neg/t2102.check index b4f91a5319..6f70839d22 100644 --- a/test/files/neg/t2102.check +++ b/test/files/neg/t2102.check @@ -1,6 +1,6 @@ t2102.scala:2: error: type mismatch; - found : java.util.Iterator[Int] - required: scala.collection.Iterator[_] + found : Iterator[Int] (in java.util) + required: Iterator[_] (in scala.collection) val x: Iterator[_] = new java.util.ArrayList[Int]().iterator ^ one error found diff --git a/test/files/neg/type-diagnostics.check b/test/files/neg/type-diagnostics.check index c5e6dec3f8..fd327bcb66 100644 --- a/test/files/neg/type-diagnostics.check +++ b/test/files/neg/type-diagnostics.check @@ -1,6 +1,6 @@ type-diagnostics.scala:4: error: type mismatch; - found : scala.collection.Set[String] - required: scala.collection.immutable.Set[String] + found : Set[String] (in scala.collection) + required: Set[String] (in scala.collection.immutable) def f = Calculator("Hello", binding.keySet: collection.Set[String]) ^ type-diagnostics.scala:13: error: type mismatch; diff --git a/test/files/pos/overloaded_ho_fun.scala b/test/files/pos/overloaded_ho_fun.scala index 2699ad35f8..17176715f0 100644 --- a/test/files/pos/overloaded_ho_fun.scala +++ b/test/files/pos/overloaded_ho_fun.scala @@ -49,3 +49,18 @@ object sorting { // def andThen[C](g: Bijection[B, C]): Bijection[A, C] = ??? // def compose[T](g: Bijection[T, A]) = g andThen this // } + +object SI10194 { + trait X[A] { + def map[B](f: A => B): Unit + } + + trait Y[A] extends X[A] { + def map[B](f: A => B)(implicit ordering: Ordering[B]): Unit + } + + trait Z[A] extends Y[A] + + (null: Y[Int]).map(x => x.toString) // compiled + (null: Z[Int]).map(x => x.toString) // didn't compile +} diff --git a/test/files/pos/sam_erasure_boundedwild.scala b/test/files/pos/sam_erasure_boundedwild.scala new file mode 100644 index 0000000000..1ec27e0ea4 --- /dev/null +++ b/test/files/pos/sam_erasure_boundedwild.scala @@ -0,0 +1,11 @@ +class Test { + trait Q[T] { + def toArray[T](x: Array[T]): Array[T] + def toArray(): Array[T] + } + + def crashTyper: Array[_] = { + val x : Q[_] = ??? + x.toArray // crashes while doing overload resolution + } +}
\ No newline at end of file diff --git a/test/files/pos/t4237.scala b/test/files/pos/t4237.scala index fcf6eb8bf1..3f605607b2 100644 --- a/test/files/pos/t4237.scala +++ b/test/files/pos/t4237.scala @@ -2,5 +2,16 @@ class A { (new { def field = 0; def field_=(i: Int) = () }).field = 5 // compiles as expected (new { def field(implicit i: Int) = 0; def field_=(i: Int) = () }).field = 5 // compiles even with implicit params on getter (new { def field = 0; def field_=[T](i: Int) = () }).field = 5 // compiles with type param on setter - (new { def field[T] = 0; def field_=(i: Int) = () }).field = 5 // DOESN'T COMPILE -}
\ No newline at end of file + (new { def field[T] = 0; def field_=(i: Int) = () }).field = 5 // DIDN'T COMPILE + + class Imp + implicit val imp: Imp = new Imp + implicit val implicitList: List[Int] = null + + // compiles even with implicit params on setter + (new { def field(implicit i: Int) = 0; def field_=(i: Int)(implicit j: Imp) = () }).field = 5 + (new { def field(implicit i: Int) = 0; def field_=[T <: Imp](i: Int)(implicit j: T) = () }).field = 5 + // was reassignment to val + (new { def field[T](implicit ts: List[T]) = 0; def field_=[T](i: Int)(implicit ts: List[T]) = () }).field = 5 + (new { def field[T](implicit ts: List[T]) = 0; def field_=[T](i: T)(implicit ts: List[T]) = () }).field = 5 +} diff --git a/test/files/run/elidable-opt.check b/test/files/run/elidable-opt.check index 88cf98e0d1..969b9a420a 100644 --- a/test/files/run/elidable-opt.check +++ b/test/files/run/elidable-opt.check @@ -11,4 +11,4 @@ false 0 0.0 0.0 -null + diff --git a/test/files/run/elidable.check b/test/files/run/elidable.check index 88cf98e0d1..969b9a420a 100644 --- a/test/files/run/elidable.check +++ b/test/files/run/elidable.check @@ -11,4 +11,4 @@ false 0 0.0 0.0 -null + diff --git a/test/files/run/elidable.scala b/test/files/run/elidable.scala index 02785972bb..fed1c7b392 100644 --- a/test/files/run/elidable.scala +++ b/test/files/run/elidable.scala @@ -3,31 +3,36 @@ import elidable._ // runs -Xelide-below WARNING or 900 +object Fail { + def fail(msg: String): Unit = throw new IllegalStateException(s"Expected failure: $msg") +} +import Fail.fail + trait T { @elidable(FINEST) def f1() @elidable(SEVERE) def f2() - @elidable(FINEST) def f3() = assert(false, "Should have been elided.") + @elidable(FINEST) def f3() = fail("Should have been elided.") def f4() } class C extends T { def f1() = println("Good for me, I was not elided. C.f1") def f2() = println("Good for me, I was not elided. C.f2") - @elidable(FINEST) def f4() = assert(false, "Should have been elided.") + @elidable(FINEST) def f4() = fail("Should have been elided.") } object O { - @elidable(FINEST) def f1() = assert(false, "Should have been elided.") - @elidable(INFO) def f2() = assert(false, "Should have been elided.") + @elidable(FINEST) def f1() = fail("Should have been elided.") + @elidable(INFO) def f2() = fail("Should have been elided.") @elidable(SEVERE) def f3() = println("Good for me, I was not elided. O.f3") - @elidable(INFO) def f4 = assert(false, "Should have been elided (no parens).") + @elidable(INFO) def f4 = fail("Should have been elided (no parens).") } object Test { - @elidable(FINEST) def f1() = assert(false, "Should have been elided.") - @elidable(INFO) def f2() = assert(false, "Should have been elided.") + @elidable(FINEST) def f1() = fail("Should have been elided.") + @elidable(INFO) def f2() = fail("Should have been elided.") @elidable(SEVERE) def f3() = println("Good for me, I was not elided. Test.f3") - @elidable(INFO) def f4 = assert(false, "Should have been elided (no parens).") + @elidable(INFO) def f4 = fail("Should have been elided (no parens).") @elidable(FINEST) def f5() = {} @elidable(FINEST) def f6() = true @@ -38,12 +43,12 @@ object Test { @elidable(FINEST) def fb() = 1l @elidable(FINEST) def fc() = 1.0f @elidable(FINEST) def fd() = 1.0 - @elidable(FINEST) def fe() = "s" + @elidable(FINEST) def fe() = { fail("Should have been elided to empty string.") ; "hello, world" } /* variable elisions? see test/files/neg/t10068.scala - @elidable(INFO) val goner1: Int = { assert(false, "Should have been elided.") ; 42 } - @elidable(INFO) lazy val goner2: Int = { assert(false, "Should have been elided.") ; 42 } - @elidable(INFO) var goner3: Int = { assert(false, "Should have been elided.") ; 42 } + @elidable(INFO) val goner1: Int = { fail("Should have been elided.") ; 42 } + @elidable(INFO) lazy val goner2: Int = { fail("Should have been elided.") ; 42 } + @elidable(INFO) var goner3: Int = { fail("Should have been elided.") ; 42 } @elidable(INFO) var goner4: Nothing = _ */ @@ -74,6 +79,19 @@ object Test { println(fc()) println(fd()) println(fe()) + if (!fe().isEmpty) fail(s"Not empty: [${fe()}]") +/* +() +false +0 +0 +0 +0 +0 +0.0 +0.0 + // was: null +*/ // this one won't show up in the output because a call to f1 is elidable when accessed through T (c:T).f1() diff --git a/test/files/run/literals.scala b/test/files/run/literals.scala index 25501123b5..a7962e5cd9 100644 --- a/test/files/run/literals.scala +++ b/test/files/run/literals.scala @@ -6,7 +6,7 @@ object Test { - /* I add a couple of Unicode identifier tests here temporarily */ + /* I add a couple of Unicode identifier tests here "temporarily" */ def \u03b1\u03c1\u03b5\u03c4\u03b7 = "alpha rho epsilon tau eta" @@ -80,6 +80,9 @@ object Test { check_success("1e1f == 10.0f", 1e1f, 10.0f) check_success(".3f == 0.3f", .3f, 0.3f) check_success("0f == 0.0f", 0f, 0.0f) + check_success("0f == -0.000000000000000000e+00f", 0f, -0.000000000000000000e+00f) + check_success("0f == -0.000000000000000000e+00F", 0f, -0.000000000000000000e+00F) + check_success("0f == -0.0000000000000000e14f", 0f, -0.0000000000000000e14f) check_success("01.23f == 1.23f", 01.23f, 1.23f) check_success("3.14f == 3.14f", 3.14f, 3.14f) check_success("6.022e23f == 6.022e23f", 6.022e23f, 6.022e23f) @@ -96,6 +99,11 @@ object Test { check_success(".3 == 0.3", .3, 0.3) check_success("0.0 == 0.0", 0.0, 0.0) check_success("0d == 0.0", 0d, 0.0) + check_success("0d == 0.000000000000000000e+00d", 0d, 0.000000000000000000e+00d) + check_success("0d == -0.000000000000000000e+00d", 0d, -0.000000000000000000e+00d) + check_success("0d == -0.000000000000000000e+00D", 0d, -0.000000000000000000e+00D) + check_success("0.0 == 0.000000000000000000e+00", 0.0, 0.000000000000000000e+00) + check_success("0.0 == -0.000000000000000000e+00", 0.0, -0.000000000000000000e+00) check_success("01.23 == 1.23", 01.23, 1.23) check_success("01.23d == 1.23d", 01.23d, 1.23d) check_success("3.14 == 3.14", 3.14, 3.14) diff --git a/test/files/run/t10026.check b/test/files/run/t10026.check new file mode 100644 index 0000000000..15a62794a9 --- /dev/null +++ b/test/files/run/t10026.check @@ -0,0 +1 @@ +List(1, 2, 3) diff --git a/test/files/run/t10026.scala b/test/files/run/t10026.scala new file mode 100644 index 0000000000..a56840c8c2 --- /dev/null +++ b/test/files/run/t10026.scala @@ -0,0 +1,11 @@ +import scala.reflect.runtime.universe +import scala.tools.reflect.ToolBox + +object Test { + def main(args: Array[String]): Unit = { + val classloader = getClass.getClassLoader + val toolbox = universe.runtimeMirror(classloader).mkToolBox() + println(toolbox.compile(toolbox.parse("Array(1, 2, 3).toList")).apply()) + } +} + diff --git a/test/files/run/t10171/Test.scala b/test/files/run/t10171/Test.scala new file mode 100644 index 0000000000..37a2cfc67f --- /dev/null +++ b/test/files/run/t10171/Test.scala @@ -0,0 +1,59 @@ +import scala.tools.partest._ +import java.io.File + +object Test extends StoreReporterDirectTest { + def code = ??? + + def compileCode(code: String) = { + val classpath = List(sys.props("partest.lib"), testOutput.path) mkString sys.props("path.separator") + compileString(newCompiler("-cp", classpath, "-d", testOutput.path))(code) + } + + def library = """ +package a { + package b { + class C { class D } + } +} +package z { + class Base { + type S = String + def foo(s: S): a.b.C#D = null + } + class Sub extends Base { + def sub = "sub" + } +} + """ + + def client = """ + class Client { new z.Sub().sub } + """ + + def deleteClass(s: String) = { + val f = new File(testOutput.path, s + ".class") + assert(f.exists) + f.delete() + } + + def deletePackage(s: String) = { + val f = new File(testOutput.path, s) + assert(f.exists) + f.delete() + } + + def assertNoErrors(): Unit = { + assert(storeReporter.infos.isEmpty, storeReporter.infos.mkString("\n")) + storeReporter.reset() + } + def show(): Unit = { + compileCode(library) + assertNoErrors() + deleteClass("a/b/C$D") + deleteClass("a/b/C") + deletePackage("a/b") + compileCode(client) + assertNoErrors() + } +} + diff --git a/test/files/run/t9880-9881.check b/test/files/run/t9880-9881.check new file mode 100644 index 0000000000..36513e249a --- /dev/null +++ b/test/files/run/t9880-9881.check @@ -0,0 +1,36 @@ + +scala> // import in various ways + +scala> import java.util.Date +import java.util.Date + +scala> import scala.util._ +import scala.util._ + +scala> import scala.reflect.runtime.{universe => ru} +import scala.reflect.runtime.{universe=>ru} + +scala> import ru.TypeTag +import ru.TypeTag + +scala> + +scala> // show the imports + +scala> :imports + 1) import java.lang._ (...) + 2) import scala._ (...) + 3) import scala.Predef._ (...) + 4) import java.util.Date (...) + 5) import scala.util._ (...) + 6) import scala.reflect.runtime.{universe=>ru} (...) + 7) import ru.TypeTag (...) + +scala> + +scala> // should be able to define this class with the imports above + +scala> class C[T](date: Date, rand: Random, typeTag: TypeTag[T]) +defined class C + +scala> :quit diff --git a/test/files/run/t9880-9881.scala b/test/files/run/t9880-9881.scala new file mode 100644 index 0000000000..0268c8c32c --- /dev/null +++ b/test/files/run/t9880-9881.scala @@ -0,0 +1,29 @@ +import scala.tools.partest.ReplTest +import scala.tools.nsc.Settings + +object Test extends ReplTest { + + override def transformSettings(s: Settings): Settings = { + s.Yreplclassbased.value = true + s + } + + lazy val normalizeRegex = """(import\s.*)\(.*\)""".r + + override def normalize(s: String): String = normalizeRegex.replaceFirstIn(s, "$1(...)") + + def code = + """ + |// import in various ways + |import java.util.Date + |import scala.util._ + |import scala.reflect.runtime.{universe => ru} + |import ru.TypeTag + | + |// show the imports + |:imports + | + |// should be able to define this class with the imports above + |class C[T](date: Date, rand: Random, typeTag: TypeTag[T]) + """.stripMargin +} diff --git a/test/junit/scala/reflect/internal/NamesTest.scala b/test/junit/scala/reflect/internal/NamesTest.scala index 549c10abed..d6182e7cca 100644 --- a/test/junit/scala/reflect/internal/NamesTest.scala +++ b/test/junit/scala/reflect/internal/NamesTest.scala @@ -92,4 +92,29 @@ class NamesTest { assert(h1 string_== h2) assert(h1 string_== h1y) } + + @Test + def pos(): Unit = { + def check(nameString: String, sub: String) = { + val name = TermName(nameString) + val javaResult = name.toString.indexOf(sub) match { case -1 => name.length case x => x } + val nameResult = name.pos(sub) + assertEquals(javaResult, nameResult) + if (sub.length == 1) { + val nameResultChar = name.pos(sub.head) + assertEquals(javaResult, nameResultChar) + } + } + + check("a", "a") // was "String index out of range: 1 + check("a", "b") + check("a", "ab") + check("a", "ba") + check("ab", "a") + check("ab", "b") + check("ab", "ab") + check("ab", "ba") + check("", "x") + check("", "xy") + } } diff --git a/test/junit/scala/sys/process/PipedProcessTest.scala b/test/junit/scala/sys/process/PipedProcessTest.scala index 53f053e9aa..3f403dbe75 100644 --- a/test/junit/scala/sys/process/PipedProcessTest.scala +++ b/test/junit/scala/sys/process/PipedProcessTest.scala @@ -7,13 +7,19 @@ import java.io.{InputStream, OutputStream, PipedInputStream, PipedOutputStream, ByteArrayOutputStream, IOException, Closeable} import java.lang.reflect.InvocationTargetException import scala.concurrent.{Await, Future} -import scala.concurrent.duration.{Duration, SECONDS} import scala.concurrent.ExecutionContext.Implicits.global import scala.util.control.Exception.ignoring -// Each test normally ends in a moment, but for failure cases, waits until one second. +// Each test normally ends in a moment, but for failure cases, waits two seconds. // SI-7350, SI-8768 +// one second wasn't always enough -- +// https://github.com/scala/scala-dev/issues/313 +object TestDuration { + import scala.concurrent.duration.{Duration, SECONDS} + val Standard = Duration(2, SECONDS) +} + @RunWith(classOf[JUnit4]) class PipedProcessTest { class ProcessMock(error: Boolean) extends Process { @@ -81,7 +87,7 @@ class PipedProcessTest { val f = Future { p.callRunAndExitValue(source, sink) } - Await.result(f, Duration(1, SECONDS)) + Await.result(f, TestDuration.Standard) assert(source.releaseCount == 0) assert(sink.releaseCount == 0) assert(a.destroyCount == 0) @@ -102,7 +108,7 @@ class PipedProcessTest { p.callRunAndExitValue(source, sink) } } - Await.result(f, Duration(1, SECONDS)) + Await.result(f, TestDuration.Standard) assert(source.releaseCount == 1) assert(sink.releaseCount == 1) assert(a.destroyCount == 0) @@ -123,7 +129,7 @@ class PipedProcessTest { p.callRunAndExitValue(source, sink) } } - Await.result(f, Duration(1, SECONDS)) + Await.result(f, TestDuration.Standard) assert(source.releaseCount == 1) assert(sink.releaseCount == 1) assert(a.destroyCount == 0) @@ -142,7 +148,7 @@ class PipedProcessTest { val f = Future { p.callRunAndExitValue(source, sink) } - Await.result(f, Duration(1, SECONDS)) + Await.result(f, TestDuration.Standard) assert(source.releaseCount == 1) assert(sink.releaseCount == 1) assert(a.destroyCount == 1) @@ -161,7 +167,7 @@ class PipedProcessTest { val f = Future { p.callRunAndExitValue(source, sink) } - Await.result(f, Duration(1, SECONDS)) + Await.result(f, TestDuration.Standard) assert(source.releaseCount == 1) assert(sink.releaseCount == 1) assert(a.destroyCount == 1) @@ -235,7 +241,7 @@ class PipeSourceSinkTest { source.join() sink.join() } - Await.result(f, Duration(1, SECONDS)) + Await.result(f, TestDuration.Standard) assert(in.closed == true) assert(out.closed == true) assert(source.isReleased == true) @@ -253,7 +259,7 @@ class PipeSourceSinkTest { source.release() sink.release() } - Await.result(f, Duration(1, SECONDS)) + Await.result(f, TestDuration.Standard) assert(out.closed == true) assert(source.isReleased == true) assert(sink.isReleased == true) @@ -270,13 +276,13 @@ class PipeSourceSinkTest { source.release() sink.release() } - Await.result(f, Duration(1, SECONDS)) + Await.result(f, TestDuration.Standard) assert(in.closed == true) assert(source.isReleased == true) assert(sink.isReleased == true) } - // PipeSource and PipeSink must release resources when interrupted during copy streams" + // PipeSource and PipeSink must release resources when interrupted during copy streams @Test def runloopInterrupted() { val in = new DebugInfinityInputStream @@ -290,7 +296,7 @@ class PipeSourceSinkTest { source.release() sink.release() } - Await.result(f, Duration(1, SECONDS)) + Await.result(f, TestDuration.Standard) assert(in.closed == true) assert(out.closed == true) assert(source.isReleased == true) diff --git a/test/junit/scala/tools/nsc/classpath/JrtClassPathTest.scala b/test/junit/scala/tools/nsc/classpath/JrtClassPathTest.scala new file mode 100644 index 0000000000..2c3c5134da --- /dev/null +++ b/test/junit/scala/tools/nsc/classpath/JrtClassPathTest.scala @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2014 Contributor. All rights reserved. + */ +package scala.tools.nsc.classpath + +import org.junit.Assert._ +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +import scala.tools.nsc.Settings +import scala.tools.nsc.backend.jvm.AsmUtils +import scala.tools.nsc.util.ClassPath +import scala.tools.util.PathResolver + +@RunWith(classOf[JUnit4]) +class JrtClassPathTest { + + @Test def lookupJavaClasses(): Unit = { + val specVersion = scala.util.Properties.javaSpecVersion + // Run the test using the JDK8 or 9 provider for rt.jar depending on the platform the test is running on. + val cp: ClassPath = + if (specVersion == "" || specVersion == "1.8") { + val settings = new Settings() + val resolver = new PathResolver(settings) + val elements = new ClassPathFactory(settings).classesInPath(resolver.Calculated.javaBootClassPath) + AggregateClassPath(elements) + } + else JrtClassPath().get + + assertEquals(Nil, cp.classes("")) + assertTrue(cp.packages("java").toString, cp.packages("java").exists(_.name == "java.lang")) + assertTrue(cp.classes("java.lang").exists(_.name == "Object")) + val jl_Object = cp.classes("java.lang").find(_.name == "Object").get + assertEquals("java/lang/Object", AsmUtils.classFromBytes(jl_Object.file.toByteArray).name) + assertTrue(cp.list("java.lang").packages.exists(_.name == "java.lang.annotation")) + assertTrue(cp.list("java.lang").classesAndSources.exists(_.name == "Object")) + assertTrue(cp.findClass("java.lang.Object").isDefined) + assertTrue(cp.findClassFile("java.lang.Object").isDefined) + } +} diff --git a/test/scalacheck/duration.scala b/test/scalacheck/duration.scala index 89cb9ff955..fc861b886a 100644 --- a/test/scalacheck/duration.scala +++ b/test/scalacheck/duration.scala @@ -32,7 +32,10 @@ object DurationTest extends Properties("Division of Duration by Long") { val genClose = for { a <- weightedLong if a != 0 - b <- choose(Long.MaxValue / a - 10, Long.MaxValue / a + 10) + val center = Long.MaxValue / a + b <- + if (center - 10 < center + 10) choose(center - 10, center + 10) + else choose(center + 10, center - 10) // deal with overflow if abs(a) == 1 } yield (a, b) val genBorderline = diff --git a/test/scaladoc/run/SI-9704.check b/test/scaladoc/run/SI-9704.check new file mode 100644 index 0000000000..5a73befd9b --- /dev/null +++ b/test/scaladoc/run/SI-9704.check @@ -0,0 +1,4 @@ +Chain(List(Chain(List(Text(Demonstrates a scala issue in which the closing link tag is duplicated), Text( +), HtmlTag(<a href="https://link">title</a>), Text( +), Text())))) +Done. diff --git a/test/scaladoc/run/SI-9704.scala b/test/scaladoc/run/SI-9704.scala new file mode 100644 index 0000000000..e6f071704e --- /dev/null +++ b/test/scaladoc/run/SI-9704.scala @@ -0,0 +1,22 @@ +import scala.tools.nsc.doc.model._ +import scala.tools.partest.ScaladocModelTest + +object Test extends ScaladocModelTest { + override def code = """ + object Foo { + /** + * Demonstrates a scala issue in which the closing link tag is duplicated + * <a href="https://link">title</a> + */ + def bar = ??? + } + """ + + def scaladocSettings = "" + + def testModel(root: Package) = { + import access._ + val thing = root._object("Foo")._method("bar") + println(thing.comment.get.short) + } +} 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..619c56180b --- /dev/null +++ b/test/scaladoc/run/inlineToStr-strips-unwanted-text.check @@ -0,0 +1 @@ +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..8faaf1b93d --- /dev/null +++ b/test/scaladoc/run/inlineToStr-strips-unwanted-text.scala @@ -0,0 +1,58 @@ +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 <strong>html tag</strong> */ + def qux = ??? + + /** This comment contains a<br> single html tag */ + def quux = ??? + + /** This comment contains nested <strong>html<br> tags</strong> */ + def quuz = ??? + + /** This comment contains a [[corge ,,link with a subscript title,,]] */ + def corge = ??? + } + """ + def scaladocSettings = "" + + def testModel(root: Package) = { + import scala.tools.nsc.doc.base.comment._ + import access._ + + val foo = root._class("Foo") + + val fooStr = Page.inlineToStr(foo.comment.get.short) + assert(fooStr == "This comment contains superscript", fooStr) + + val barStr = Page.inlineToStr(foo._method("bar").comment.get.short) + assert(barStr == "This comment contains subscript", barStr) + + val bazStr = Page.inlineToStr(foo._method("baz").comment.get.short) + assert(bazStr == "This comment contains a link https://scala.epfl.ch/", bazStr) + + val quxStr = Page.inlineToStr(foo._method("qux").comment.get.short) + assert(quxStr == "This comment contains an html tag", quxStr) + + val quuxStr = Page.inlineToStr(foo._method("quux").comment.get.short) + assert(quuxStr == "This comment contains a single html tag", quuxStr) + + val quuzStr = Page.inlineToStr(foo._method("quuz").comment.get.short) + assert(quuzStr == "This comment contains nested html tags", quuzStr) + + val corgeStr = Page.inlineToStr(foo._method("corge").comment.get.short) + assert(corgeStr == "This comment contains a link with a subscript title", corgeStr) + } +} 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) } } |