Skip to content

Commit 0a0efb3

Browse files
ultrasecrethbvenners
authored andcommitted
add _root_ to the macros defined in TypeMatcherMacro
1 parent 5fc7c4b commit 0a0efb3

File tree

2 files changed

+87
-9
lines changed

2 files changed

+87
-9
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package org.scalatest.matchers
2+
3+
import org.scalatest.{FlatSpec, Matchers}
4+
5+
class TypeMatcherMacroSpec extends FlatSpec with Matchers {
6+
7+
case class Organization(name: String)
8+
val org = Organization("acme")
9+
10+
"assertTypeImpl" should "work when a val called 'org' is in scope" in {
11+
org.name shouldBe a[String]
12+
org.name shouldBe an[String]
13+
}
14+
15+
"aTypeMatcherImpl" should "work when a val called 'org' is in scope" in {
16+
org.name should be(a[String])
17+
}
18+
19+
"anTypeMatcherImpl" should "work when a val called 'org' is in scope" in {
20+
org.name should be(an[String])
21+
}
22+
23+
"notATypeMatcher" should "work when a val called 'org' is in scope" in {
24+
org.name should (not be a [Int] and not be a [Double])
25+
}
26+
27+
"notAnTypeMatcher" should "work when a val called 'org' is in scope" in {
28+
org.name should (not be an[Int] and not be an[Double])
29+
}
30+
31+
"andNotATypeMatcher" should "work when a val called 'org' is in scope" in {
32+
org.name should (be(a[String]) and not be a[Int])
33+
}
34+
35+
"andNotAnTypeMatcher" should "work when a val called 'org' is in scope" in {
36+
org.name should (be(an[String]) and not be an[Int])
37+
}
38+
39+
"orNotATypeMatcher" should "work when a val called 'org' is in scope" in {
40+
org.name should (be(a[Double]) or not be a[Int])
41+
}
42+
43+
"orNotAnTypeMatcher" should "work when a val called 'org' is in scope" in {
44+
org.name should (be(an[Double]) or not be an[Int])
45+
}
46+
47+
"assertATypeShouldBeTrueImpl" should "work when a val called 'org' is in scope" in {
48+
org.name should not be a[Int]
49+
}
50+
51+
"assertAnTypeShouldBeTrueImpl" should "work when a val called 'org' is in scope" in {
52+
org.name should not be an[Int]
53+
}
54+
}

scalatest/src/main/scala/org/scalatest/matchers/TypeMatcherMacro.scala

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ private[scalatest] object TypeMatcherMacro {
7676
Select(
7777
Select(
7878
Select(
79-
Ident(newTermName("org")),
79+
Select(
80+
Ident(newTermName("_root_")),
81+
newTermName("org")
82+
),
8083
newTermName("scalatest")
8184
),
8285
newTermName("matchers")
@@ -112,7 +115,10 @@ private[scalatest] object TypeMatcherMacro {
112115
Select(
113116
Select(
114117
Select(
115-
Ident(newTermName("org")),
118+
Select(
119+
Ident(newTermName("_root_")),
120+
newTermName("org")
121+
),
116122
newTermName("scalatest")
117123
),
118124
newTermName("matchers")
@@ -147,7 +153,10 @@ private[scalatest] object TypeMatcherMacro {
147153
Select(
148154
Select(
149155
Select(
150-
Ident(newTermName("org")),
156+
Select(
157+
Ident(newTermName("_root_")),
158+
newTermName("org")
159+
),
151160
newTermName("scalatest")
152161
),
153162
newTermName("matchers")
@@ -181,7 +190,10 @@ private[scalatest] object TypeMatcherMacro {
181190
Select(
182191
Select(
183192
Select(
184-
Ident(newTermName("org")),
193+
Select(
194+
Ident(newTermName("_root_")),
195+
newTermName("org")
196+
),
185197
newTermName("scalatest")
186198
),
187199
newTermName("matchers")
@@ -353,7 +365,10 @@ private[scalatest] object TypeMatcherMacro {
353365
Select(
354366
Select(
355367
Select(
356-
Ident(newTermName("org")),
368+
Select(
369+
Ident(newTermName("_root_")),
370+
newTermName("org")
371+
),
357372
newTermName("scalatest")
358373
),
359374
newTermName("matchers")
@@ -407,7 +422,10 @@ private[scalatest] object TypeMatcherMacro {
407422
Select(
408423
Select(
409424
Select(
410-
Ident(newTermName("org")),
425+
Select(
426+
Ident(newTermName("_root_")),
427+
newTermName("org")
428+
),
411429
newTermName("scalatest")
412430
),
413431
newTermName("matchers")
@@ -460,7 +478,10 @@ private[scalatest] object TypeMatcherMacro {
460478
Select(
461479
Select(
462480
Select(
463-
Ident(newTermName("org")),
481+
Select(
482+
Ident(newTermName("_root_")),
483+
newTermName("org")
484+
),
464485
newTermName("scalatest")
465486
),
466487
newTermName("matchers")
@@ -506,7 +527,10 @@ private[scalatest] object TypeMatcherMacro {
506527
Select(
507528
Select(
508529
Select(
509-
Ident(newTermName("org")),
530+
Select(
531+
Ident(newTermName("_root_")),
532+
newTermName("org")
533+
),
510534
newTermName("scalatest")
511535
),
512536
newTermName("matchers")
@@ -532,4 +556,4 @@ private[scalatest] object TypeMatcherMacro {
532556
def expectAnTypeWillBeTrueImpl(context: Context)(anType: context.Expr[FactResultOfAnTypeInvocation[_]]): context.Expr[org.scalatest.Fact] =
533557
expectTypeWillBeTrueImpl(context)(anType.tree, "will not be an", "expectAnTypeWillBeTrue")*/
534558

535-
}
559+
}

0 commit comments

Comments
 (0)