summaryrefslogtreecommitdiff
path: root/test/files/scalacheck/quasiquotes/PatternConstructionProps.scala
blob: 7ed95fa9848152f4449b859b4a1e10db69d6c8f9 (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
import org.scalacheck._, Prop._, Gen._, Arbitrary._
import scala.reflect.runtime.universe._, Flag._

object PatternConstructionProps extends QuasiquoteProperties("pattern construction") {
  property("unquote bind") = forAll { (bind: Bind) =>
    pq"$bind"  bind
  }

  property("unquote name into bind") = forAll { (name: TermName) =>
    pq"$name"  Bind(name, Ident(termNames.WILDCARD))
  }

  property("unquote name and tree into bind") = forAll { (name: TermName, tree: Tree) =>
    pq"$name @ $tree"  Bind(name, tree)
  }

  property("unquote type name into typed") = forAll { (name: TypeName) =>
    pq"_ : $name"  Typed(Ident(termNames.WILDCARD), Ident(name))
  }

  property("unquote tree into typed") = forAll { (typ: Tree) =>
    pq"_ : $typ"  Typed(Ident(termNames.WILDCARD), typ)
  }

  property("unquote into apply") = forAll { (pat: Tree, subpat: Tree) =>
    pq"$pat($subpat)"  Apply(pat, List(subpat))
  }

  property("unquote into casedef") = forAll { (pat: Tree, cond: Tree, body: Tree) =>
    cq"$pat if $cond => $body"  CaseDef(pat, cond, body)
  }

  property("unquote into alternative") = forAll { (first: Tree, rest: List[Tree]) =>
    pq"$first | ..$rest"  Alternative(first :: rest)
  }
}