diff options
Diffstat (limited to 'test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala')
-rw-r--r-- | test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala | 100 |
1 files changed, 50 insertions, 50 deletions
diff --git a/test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala b/test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala index 7e846bfb24..fdb0d83277 100644 --- a/test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala +++ b/test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala @@ -50,24 +50,24 @@ trait ClassConstruction { self: QuasiquoteProperties => assertEqAst(q"class Foo extends ..$parents", "class Foo") } - property("splice term name into class") = forAll { (rname: TypeName) => + property("unquote term name into class") = forAll { (rname: TypeName) => // add prefix to avoid failure in case rname is keyword val name = TypeName("prefix$" + rname) eqAst(q"class $name", "class " + name.toString) } - property("splice method into class") = forAll { (name: TypeName, method: DefDef) => + property("unquote method into class") = forAll { (name: TypeName, method: DefDef) => q"class $name { $method }" ≈ classWith(name, body = List(method)) } - property("splice members into class") = forAll { (name: TypeName, defs: List[DefDef], extra: DefDef) => + property("unquote members into class") = forAll { (name: TypeName, defs: List[DefDef], extra: DefDef) => q"""class $name { ..$defs $extra }""" ≈ classWith(name, body = defs :+ extra) } - property("splice type name into class parents") = forAll { (name: TypeName, parent: TypeName) => + property("unquote type name into class parents") = forAll { (name: TypeName, parent: TypeName) => q"class $name extends $parent" ≈ classWith(name, parents = List(Ident(parent))) } @@ -84,27 +84,27 @@ trait ClassConstruction { self: QuasiquoteProperties => } trait TraitConstruction { self: QuasiquoteProperties => - property("splice name into trait def") = test { + property("unquote name into trait def") = test { val Foo = TypeName("Foo") assert(q"trait $Foo" ≈ q"trait Foo") } - property("splice type params into trait def") = test { + property("unquote type params into trait def") = test { val tparams = q"type A" :: q"type B" :: Nil assert(q"trait Foo[..$tparams]" ≈ q"trait Foo[A, B]") } - property("splice defs into trait body") = test { + property("unquote defs into trait body") = test { val body = q"def foo" :: q"val bar: Baz" :: Nil assert(q"trait Foo { ..$body }" ≈ q"trait Foo { def foo; val bar: Baz }") } - property("splice parents into trait") = test { + property("unquote parents into trait") = test { val parents = tq"A" :: tq"B" :: Nil assert(q"trait Foo extends ..$parents" ≈ q"trait Foo extends A with B") } - property("splice early valdef into trait") = test { + property("unquote early valdef into trait") = test { val x = q"val x: Int = 1" assertEqAst(q"trait T extends { $x } with Any", "trait T extends { val x: Int = 1} with Any") } @@ -113,7 +113,7 @@ trait TraitConstruction { self: QuasiquoteProperties => assertEqAst(q"trait T extends { val x: Int = 1 } with Any", "trait T extends { val x: Int = 1 } with Any") } - property("splice defs into early block") = test { + property("unquote defs into early block") = test { val defs = q"val x: Int = 0" :: q"type Foo = Bar" :: Nil assert(q"trait T extends { ..$defs } with Bippy" ≈ q"trait T extends { val x: Int = 0; type Foo = Bar} with Bippy") @@ -126,37 +126,37 @@ trait TraitConstruction { self: QuasiquoteProperties => } trait TypeDefConstruction { self: QuasiquoteProperties => - property("splice type name into typedef") = forAll { (name1: TypeName, name2: TypeName) => + property("unquote type name into typedef") = forAll { (name1: TypeName, name2: TypeName) => q"type $name1 = $name2" ≈ TypeDef(Modifiers(), name1, List(), Ident(name2)) } - property("splice type names into type bounds") = forAll { (T1: TypeName, T2: TypeName, T3: TypeName) => + property("unquote type names into type bounds") = forAll { (T1: TypeName, T2: TypeName, T3: TypeName) => q"type $T1 >: $T2 <: $T3" ≈ TypeDef( Modifiers(DEFERRED), T1, List(), TypeBoundsTree(Ident(T2), Ident(T3))) } - property("splice trees names into type bounds") = forAll { (T: TypeName, t1: Tree, t2: Tree) => + property("unquote trees names into type bounds") = forAll { (T: TypeName, t1: Tree, t2: Tree) => q"type $T >: $t1 <: $t2" ≈ TypeDef( Modifiers(DEFERRED), T, List(), TypeBoundsTree(t1, t2)) } - property("splice tparams into typedef (1)") = forAll { (T: TypeName, targs: List[TypeDef], t: Tree) => + property("unquote tparams into typedef (1)") = forAll { (T: TypeName, targs: List[TypeDef], t: Tree) => q"type $T[..$targs] = $t" ≈ TypeDef(Modifiers(), T, targs, t) } - property("splice tparams into typedef (2)") = forAll { (T: TypeName, targs1: List[TypeDef], targs2: List[TypeDef], t: Tree) => + property("unquote tparams into typedef (2)") = forAll { (T: TypeName, targs1: List[TypeDef], targs2: List[TypeDef], t: Tree) => q"type $T[..$targs1, ..$targs2] = $t" ≈ TypeDef(Modifiers(), T, targs1 ++ targs2, t) } - property("splice tparams into typedef (3)") = forAll { (T: TypeName, targ: TypeDef, targs: List[TypeDef], t: Tree) => + property("unquote tparams into typedef (3)") = forAll { (T: TypeName, targ: TypeDef, targs: List[TypeDef], t: Tree) => q"type $T[$targ, ..$targs] = $t" ≈ TypeDef(Modifiers(), T, targ :: targs, t) } - property("splice typename into typedef with default bounds") = forAll { (T1: TypeName, T2: TypeName, t: Tree) => + property("unquote typename into typedef with default bounds") = forAll { (T1: TypeName, T2: TypeName, t: Tree) => q"type $T1[$T2 >: Any <: Nothing] = $t" ≈ TypeDef( Modifiers(), T1, @@ -169,7 +169,7 @@ trait TypeDefConstruction { self: QuasiquoteProperties => t) } - property("splice type names into compound type tree") = forAll { (T: TypeName, A: TypeName, B: TypeName) => + property("unquote type names into compound type tree") = forAll { (T: TypeName, A: TypeName, B: TypeName) => q"type $T = $A with $B" ≈ TypeDef( Modifiers(), T, List(), @@ -177,7 +177,7 @@ trait TypeDefConstruction { self: QuasiquoteProperties => Template(List(Ident(A), Ident(B)), ValDef(Modifiers(PRIVATE), termNames.WILDCARD, TypeTree(), EmptyTree), List()))) } - property("splice trees into existential type tree") = forAll { + property("unquote trees into existential type tree") = forAll { (T1: TypeName, T2: TypeName, X: TypeName, Lo: TypeName, Hi: TypeName) => q"type $T1 = $T2[$X] forSome { type $X >: $Lo <: $Hi }" ≈ @@ -189,11 +189,11 @@ trait TypeDefConstruction { self: QuasiquoteProperties => TypeDef(Modifiers(DEFERRED), X, List(), TypeBoundsTree(Ident(Lo), Ident(Hi)))))) } - property("splice tree into singleton type tree") = forAll { (name: TypeName, t: Tree) => + property("unquote tree into singleton type tree") = forAll { (name: TypeName, t: Tree) => q"type $name = $t.type" ≈ q"type $name = ${SingletonTypeTree(t)}" } - property("splice into applied type tree") = forAll { (T1: TypeName, T2: TypeName, args: List[Tree]) => + property("unquote into applied type tree") = forAll { (T1: TypeName, T2: TypeName, args: List[Tree]) => q"type $T1 = $T2[..$args]" ≈ TypeDef(Modifiers(), T1, List(), if(args.nonEmpty) AppliedTypeTree(Ident(T2), args) else Ident(T2)) @@ -201,11 +201,11 @@ trait TypeDefConstruction { self: QuasiquoteProperties => } trait ValDefConstruction { self: QuasiquoteProperties => - property("splice into val") = forAll { (name: TermName, tpt: Tree, rhs: Tree) => + property("unquote into val") = forAll { (name: TermName, tpt: Tree, rhs: Tree) => q"val $name: $tpt = $rhs" ≈ ValDef(Modifiers(), name, tpt, rhs) } - property("splice into var") = forAll { (name: TermName, tpt: Tree, rhs: Tree) => + property("unquote into var") = forAll { (name: TermName, tpt: Tree, rhs: Tree) => q"var $name: $tpt = $rhs" ≈ ValDef(Modifiers(MUTABLE), name, tpt, rhs) } @@ -216,28 +216,28 @@ trait ValDefConstruction { self: QuasiquoteProperties => } trait PatDefConstruction { self: QuasiquoteProperties => - property("splice pattern into pat def") = test { + property("unquote pattern into pat def") = test { val pat = pq"(a, b)" assertEqAst(q"val $pat = (1, 2)", "val (a, b) = (1, 2)") val tpt = tq"(Int, Int)" assertEqAst(q"val $pat: $tpt = (1, 2)", "val (a, b): (Int, Int) = (1, 2)") } - property("splice pattern into pat def within other pattern (1)") = test { + property("unquote pattern into pat def within other pattern (1)") = test { val pat = pq"(a, b)" assertEqAst(q"val Foo($pat) = Foo((1, 2))", "val Foo((a, b)) = Foo((1, 2))") val tpt = tq"Foo" assertEqAst(q"val Foo($pat): $tpt = Foo((1, 2))", "val Foo((a, b)): Foo = Foo((1, 2))") } - property("splice patterns into pat def within other pattern (2)") = test { + property("unquote patterns into pat def within other pattern (2)") = test { val pat1 = pq"(a, b)"; val pat2 = pq"(c, d)" assertEqAst(q"val ($pat1, $pat2) = ((1, 2), (3, 4))", "val ((a, b), (c, d)) = ((1, 2), (3, 4))") val tpt = tq"((Int, Int), (Int, Int))" assertEqAst(q"val ($pat1, $pat2): $tpt = ((1, 2), (3, 4))", "val ((a, b), (c, d)): ((Int, Int), (Int, Int)) = ((1, 2), (3, 4))") } - property("splice pattern without free vars into pat def") = test { + property("unquote pattern without free vars into pat def") = test { val pat = pq"((1, 2), 3)" assertEqAst(q"val $pat = ((1, 2), 3)", "{ val ((1, 2), 3) = ((1, 2), 3) }") val tpt = tq"((Int, Int), Int)" @@ -245,19 +245,19 @@ trait PatDefConstruction { self: QuasiquoteProperties => } // won't result into pattern match due to SI-8211 - property("splice typed pat into pat def") = test { + property("unquote typed pat into pat def") = test { val pat = pq"x: Int" assertEqAst(q"val $pat = 2", "{ val x: Int = 2 }") } } trait MethodConstruction { self: QuasiquoteProperties => - property("splice paramss into defdef") = test { + property("unquote paramss into defdef") = test { val paramss = List(q"val x: Int") :: List(q"val y: Int = 1") :: Nil assert(q"def foo(...$paramss)" ≈ parse("def foo(x: Int)(y: Int = 1)")) } - property("splice tparams into defdef") = test { + property("unquote tparams into defdef") = test { val tparams = q"type A" :: q"type B <: Bippy" :: Nil assert(q"def foo[..$tparams]" ≈ parse("def foo[A, B <: Bippy]")) } @@ -270,84 +270,84 @@ trait MethodConstruction { self: QuasiquoteProperties => assert(tree1.mods.annotations ≈ tree2.mods.annotations, s"${tree1.mods.annotations} =/= ${tree2.mods.annotations}") - property("splice type name into annotation") = test { + property("unquote type name into annotation") = test { val name = TypeName("annot") assertSameAnnots(q"@$name def foo", List(q"new $name")) } - property("splice ident into annotation") = test { + property("unquote ident into annotation") = test { val name = TypeName("annot") val ident = Ident(name) assertSameAnnots(q"@$ident def foo", List(q"new $name")) } - property("splice idents into annotation") = test { + property("unquote idents into annotation") = test { val idents = List(Ident(TypeName("annot1")), Ident(TypeName("annot2"))) assertSameAnnots(q"@..$idents def foo", idents.map { ident => Apply(Select(New(ident), termNames.CONSTRUCTOR), List()) }) } - property("splice constructor calls into annotation") = test { + property("unquote constructor calls into annotation") = test { val ctorcalls = List(q"new a1", q"new a2") assertSameAnnots(q"@..$ctorcalls def foo", ctorcalls) } - property("splice multiple annotations (1)") = test { + property("unquote multiple annotations (1)") = test { val annot1 = q"new a1" val annot2 = q"new a2" val res = q"@$annot1 @$annot2 def foo" assertSameAnnots(res, List(annot1, annot2)) } - property("splice multiple annotations (2)") = test { + property("unquote multiple annotations (2)") = test { val annot1 = q"new a1" val annots = List(q"new a2", q"new a3") val res = q"@$annot1 @..$annots def foo" assertSameAnnots(res, annot1 :: annots) } - property("splice annotations with arguments (1)") = test { + property("unquote annotations with arguments (1)") = test { val a = q"new a(x)" assertSameAnnots(q"@$a def foo", q"@a(x) def foo") } - property("splice annotations with arguments (2)") = test { + property("unquote annotations with arguments (2)") = test { val a = TypeName("a") assertSameAnnots(q"@$a(x) def foo", q"@a(x) def foo") } - property("splice annotations with arguments (3") = test { + property("unquote annotations with arguments (3") = test { val a = Ident(TypeName("a")) assertSameAnnots(q"@$a(x) def foo", q"@a(x) def foo") } - property("splice improper tree into annot") = test { + property("unquote improper tree into annot") = test { val t = tq"Foo[Baz]" assertThrows[IllegalArgumentException] { q"@$t def foo" } } - property("can't splice annotations with arguments specificed twice") = test { + property("can't unquote annotations with arguments specificed twice") = test { val a = q"new a(x)" assertThrows[IllegalArgumentException] { q"@$a(y) def foo" } } - property("splice annotation with targs") = test { + property("unquote annotation with targs") = test { val a = q"new Foo[A, B]" assertEqAst(q"@$a def foo", "@Foo[A,B] def foo") } - property("splice annotation with multiple argument lists") = test { + property("unquote annotation with multiple argument lists") = test { val a = q"new Foo(a)(b)" assertEqAst(q"@$a def foo", "@Foo(a)(b) def foo") } } trait PackageConstruction { self: QuasiquoteProperties => - property("splice select into package name") = test { + property("unquote select into package name") = test { val name = q"foo.bar" assertEqAst(q"package $name { }", "package foo.bar { }") } @@ -357,12 +357,12 @@ trait PackageConstruction { self: QuasiquoteProperties => assertEqAst(q"package $name { }", "package bippy { }") } - property("splice members into package body") = test { + property("unquote members into package body") = test { val members = q"class C" :: q"object O" :: Nil assertEqAst(q"package foo { ..$members }", "package foo { class C; object O }") } - property("splice illegal members into package body") = test { + property("unquote illegal members into package body") = test { val f = q"def f" assertThrows[IllegalArgumentException] { q"package foo { $f }" } val v = q"val v = 0" @@ -371,24 +371,24 @@ trait PackageConstruction { self: QuasiquoteProperties => assertThrows[IllegalArgumentException] { q"package foo { $expr }" } } - property("splice name into package object") = test { + property("unquote name into package object") = test { val foo = TermName("foo") assertEqAst(q"package object $foo", "package object foo") } - property("splice parents into package object") = test { + property("unquote parents into package object") = test { val parents = tq"a" :: tq"b" :: Nil assertEqAst(q"package object foo extends ..$parents", "package object foo extends a with b") } - property("splice members into package object") = test { + property("unquote members into package object") = test { val members = q"def foo" :: q"val x = 1" :: Nil assertEqAst(q"package object foo { ..$members }", "package object foo { def foo; val x = 1 }") } - property("splice early def into package object") = test { + property("unquote early def into package object") = test { val edefs = q"val x = 1" :: q"type I = Int" :: Nil assertEqAst(q"package object foo extends { ..$edefs } with Any", "package object foo extends { val x = 1; type I = Int } with Any") |