aboutsummaryrefslogtreecommitdiff
path: root/dottydoc/test/UsecaseTest.scala
blob: d5f3388929da402a0f29c359c2e586180a7b2b16 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package dotty.tools
package dottydoc

import org.junit.Test
import org.junit.Assert._

import dotc.util.SourceFile
import model._
import model.internal._
import model.references._

class UsecaseTest extends DottyTest {
  @Test def simpleUsecase = {
    val source = new SourceFile(
      "DefWithUseCase.scala",
      """
      |package scala
      |
      |trait Test[A] {
      |  /** Definition with a "disturbing" signature
      |   *
      |   *  @usecase def foo: A
      |   */
      |  def foo[B]: A => B
      |}
      """.stripMargin
    )

    checkSources(source :: Nil) { packages =>
      packages("scala") match {
        case PackageImpl(_, _, List(trt: Trait), _, _) =>
          val List(foo: Def) = trt.members

          val returnValue = foo.returnValue match {
            case ref: TypeReference => ref.title
            case _ =>
              assert(
                false,
                "Incorrect return value after usecase transformation"
              )
              ""
          }

          assert(
            foo.typeParams.isEmpty,
            "Type parameters were not stripped by usecase"
          )
          assert(returnValue == "A", "Incorrect return type after usecase")

          assert(foo.name == "foo", s"Incorrect name after transform: ${foo.name}")
      }
    }
  }

  @Test def checkIterator = {
    val sources =
      "./scala-scala/src/library/scala/collection/Iterator.scala" :: Nil

    checkFiles(sources) { packages =>
      // success if typer throws no errors! :)
    }
  }
}