File: PatternConstructionProps.scala

package info (click to toggle)
scala 2.11.12-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 62,924 kB
  • sloc: javascript: 28,808; java: 13,415; xml: 3,135; sh: 1,620; python: 756; makefile: 38; awk: 36; ansic: 6
file content (36 lines) | stat: -rw-r--r-- 1,237 bytes parent folder | download | duplicates (4)
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)
  }
}