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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
import org.scalacheck._, Prop._, Gen._, Arbitrary._
import scala.reflect.runtime.universe._, Flag._
object LiftableProps extends QuasiquoteProperties("liftable") {
property("splice byte") = test {
val c: Byte = 0
assert(q"$c" ≈ Literal(Constant(c)))
}
property("splice short") = test {
val c: Short = 0
assert(q"$c" ≈ Literal(Constant(c)))
}
property("splice char") = test {
val c: Char = 'c'
assert(q"$c" ≈ Literal(Constant(c)))
}
property("splice int") = test {
val c: Int = 0
assert(q"$c" ≈ Literal(Constant(c)))
}
property("splice long") = test {
val c: Long = 0
assert(q"$c" ≈ Literal(Constant(c)))
}
property("splice float") = test {
val c: Float = 0.0f
assert(q"$c" ≈ Literal(Constant(c)))
}
property("splice double") = test {
val c: Double = 0.0
assert(q"$c" ≈ Literal(Constant(c)))
}
property("splice boolean") = test {
val c: Boolean = false
assert(q"$c" ≈ Literal(Constant(c)))
}
property("splice string") = test {
val c: String = "s"
assert(q"$c" ≈ Literal(Constant(c)))
}
property("splice unit") = test {
val c: Unit = ()
assert(q"$c" ≈ Literal(Constant(c)))
}
property("lift symbol") = test {
val s = rootMirror.staticClass("scala.Int")
assert(q"$s" ≈ Ident(s))
}
property("lift type") = test {
val tpe = rootMirror.staticClass("scala.Int").toType
assert(q"$tpe" ≈ TypeTree(tpe))
}
property("lift type tag") = test {
val tag = TypeTag.Int
assert(q"$tag" ≈ TypeTree(tag.tpe))
}
property("lift weak type tag") = test {
val tag = WeakTypeTag.Int
assert(q"$tag" ≈ TypeTree(tag.tpe))
}
property("lift constant") = test {
val const = Constant(0)
assert(q"$const" ≈ q"0")
}
property("lift list variants") = test {
val lst = List(1, 2)
val immutable = q"$scalapkg.collection.immutable"
assert(q"$lst" ≈ q"$immutable.List(1, 2)")
assert(q"f(..$lst)" ≈ q"f(1, 2)")
val llst = List(List(1), List(2))
assert(q"f(..$llst)" ≈ q"f($immutable.List(1), $immutable.List(2))")
assert(q"f(...$llst)" ≈ q"f(1)(2)")
}
property("lift tuple") = test {
assert(q"${Tuple1(1)}" ≈ q"scala.Tuple1(1)")
assert(q"${(1, 2)}" ≈ q"(1, 2)")
assert(q"${(1, 2, 3)}" ≈ q"(1, 2, 3)")
assert(q"${(1, 2, 3, 4)}" ≈ q"(1, 2, 3, 4)")
assert(q"${(1, 2, 3, 4, 5)}" ≈ q"(1, 2, 3, 4, 5)")
assert(q"${(1, 2, 3, 4, 5, 6)}" ≈ q"(1, 2, 3, 4, 5, 6)")
assert(q"${(1, 2, 3, 4, 5, 6, 7)}" ≈ q"(1, 2, 3, 4, 5, 6, 7)")
assert(q"${(1, 2, 3, 4, 5, 6, 7, 8)}" ≈ q"(1, 2, 3, 4, 5, 6, 7, 8)")
assert(q"${(1, 2, 3, 4, 5, 6, 7, 8, 9)}" ≈ q"(1, 2, 3, 4, 5, 6, 7, 8, 9)")
assert(q"${(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)}" ≈ q"(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)")
assert(q"${(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)}" ≈ q"(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)")
assert(q"${(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)}" ≈ q"(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)")
assert(q"${(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)}" ≈ q"(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)")
assert(q"${(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14)}" ≈ q"(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14)")
assert(q"${(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)}" ≈ q"(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)")
assert(q"${(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)}" ≈ q"(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)")
assert(q"${(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17)}" ≈ q"(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17)")
assert(q"${(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18)}" ≈ q"(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18)")
assert(q"${(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19)}" ≈ q"(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19)")
assert(q"${(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)}" ≈ q"(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)")
assert(q"${(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21)}" ≈ q"(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21)")
assert(q"${(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22)}" ≈ q"(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22)")
}
property("lift nil") = test {
val nil = Nil
assert(q"$nil" ≈ q"scala.collection.immutable.Nil")
}
property("lift some") = test {
val some1 = Some(1)
assert(q"$some1" ≈ q"scala.Some(1)")
val some2: Option[Int] = Some(1)
assert(q"$some2" ≈ q"scala.Some(1)")
}
property("lift none") = test {
val none1 = None
assert(q"$none1" ≈ q"scala.None")
val none2: Option[Int] = None
assert(q"$none2" ≈ q"scala.None")
}
property("lift left") = test {
val left1 = Left(1)
assert(q"$left1" ≈ q"scala.util.Left(1)")
val left2: Left[Int, Int] = Left(1)
assert(q"$left2" ≈ q"scala.util.Left(1)")
val left3: Either[Int, Int] = Left(1)
assert(q"$left3" ≈ q"scala.util.Left(1)")
}
property("lift right") = test {
val right1 = Right(1)
assert(q"$right1" ≈ q"scala.util.Right(1)")
val right2: Right[Int, Int] = Right(1)
assert(q"$right2" ≈ q"scala.util.Right(1)")
val right3: Either[Int, Int] = Right(1)
assert(q"$right3" ≈ q"scala.util.Right(1)")
}
}
|