aboutsummaryrefslogtreecommitdiff
path: root/sbt-bridge/test/xsbt/ExtractUsedNamesSpecification.scala
diff options
context:
space:
mode:
Diffstat (limited to 'sbt-bridge/test/xsbt/ExtractUsedNamesSpecification.scala')
-rw-r--r--sbt-bridge/test/xsbt/ExtractUsedNamesSpecification.scala39
1 files changed, 39 insertions, 0 deletions
diff --git a/sbt-bridge/test/xsbt/ExtractUsedNamesSpecification.scala b/sbt-bridge/test/xsbt/ExtractUsedNamesSpecification.scala
index ed463a3e6..6cff284fe 100644
--- a/sbt-bridge/test/xsbt/ExtractUsedNamesSpecification.scala
+++ b/sbt-bridge/test/xsbt/ExtractUsedNamesSpecification.scala
@@ -75,6 +75,7 @@ class ExtractUsedNamesSpecification extends Specification {
|}""".stripMargin
val compilerForTesting = new ScalaCompilerForUnitTesting(nameHashing = true)
val usedNames = compilerForTesting.extractUsedNamesFromSrc(srcA, srcB)
+
// DOTTY TODO: "Int" is not actually used, but we collect it because
// it's the inferred return type so it appears in a TypeTree
// We could avoid this by checking if the untyped tree has a return type
@@ -84,6 +85,44 @@ class ExtractUsedNamesSpecification extends Specification {
usedNames === expectedNames
}
+ "extract names in the types of trees" in {
+ val src1 = """|class X0
+ |class X1 extends X0
+ |class Y
+ |class A {
+ | type T >: X1 <: X0
+ |}
+ |class M
+ |class N
+ |class P0
+ |class P1 extends P0
+ |object B {
+ | type S = Y
+ | val lista: List[A] = ???
+ | val at: A#T = ???
+ | val as: S = ???
+ | def foo(m: M): N = ???
+ | def bar[Param >: P1 <: P0](p: Param): Param = ???
+ |}""".stripMargin
+ val src2 = """|object Test {
+ | val x = B.lista
+ | val y = B.at
+ | val z = B.as
+ | B.foo(???)
+ | B.bar(???)
+ |}""".stripMargin
+ val compilerForTesting = new ScalaCompilerForUnitTesting(nameHashing = true)
+ val usedNames = compilerForTesting.extractUsedNamesFromSrc(src1, src2)
+ val expectedNames = standardNames ++ Set("Test", "Test$", "B", "B$",
+ "Predef", "Predef$", "$qmark$qmark$qmark", "Nothing",
+ "lista", "List", "A",
+ "at", "T", "X1", "X0",
+ "as", "S", "Y",
+ "foo", "M", "N",
+ "bar", "P1", "P0")
+ usedNames === expectedNames
+ }
+
// test for https://github.com/gkossakowski/sbt/issues/3
"used names from the same compilation unit" in {
val src = "class A { def foo: Int = 0; def bar: Int = foo }"