summaryrefslogtreecommitdiff
path: root/test/scalacheck/scala/reflect/quasiquotes/PatternDeconstructionProps.scala
blob: 182e905c04c06a686944c28f1f838810a4dad0a2 (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
package scala.reflect.quasiquotes

import org.scalacheck._, Prop._, Gen._, Arbitrary._
import scala.reflect.runtime.universe._, Flag._

object PatternDeconstructionProps extends QuasiquoteProperties("pattern deconstruction") {
  property("extract bind") = forAll { (bind: Bind) =>
    val pq"$bind0" = pq"$bind"
    bind0  bind
  }

  property("extract bind and subpattern") = forAll { (name: TermName, subp: Tree) =>
    val pq"$name0 @ $subp0" = pq"$name @ $subp"
    name0  name && subp0  subp
  }

  property("extract typed") = forAll { (typ: Tree) =>
    val pq"_ : $typ0" = pq"_ : $typ"
    typ0  typ
  }

  property("extract apply") = forAll { (pat: Tree, subpat: Tree) =>
    val pq"$pat0($subpat0)" = pq"$pat($subpat)"
    pat0  pat && subpat0  subpat
  }

  property("extract apply many") = forAll { (pat: Tree, subpats: List[Tree]) =>
    val pq"$pat0(..$subpats0)" = pq"$pat(..$subpats)"
    pat0  pat && subpats0  subpats
  }

  property("extract apply last") = forAll { (pat: Tree, subpats: List[Tree], subpatlast: Tree) =>
    val pq"$pat0(..$subpats0, $subpatlast0)" = pq"$pat(..$subpats, $subpatlast)"
    pat0  pat && subpats0  subpats && subpatlast0  subpatlast
  }

  property("extract casedef") = forAll { (pat: Tree, cond: Tree, body: Tree) =>
    val cq"$pat0 if $cond0 => $body0" = cq"$pat if $cond => $body"
    pat0  pat && cond0  cond && body0  body
  }

  property("extract alternative") = forAll { (first: Tree, rest: List[Tree]) =>
    val pq"$first1 | ..$rest1" = pq"$first | ..$rest"
    first1  first && rest1  rest
  }
}