Skip to content

Commit

Permalink
Proper handling of package references
Browse files Browse the repository at this point in the history
  • Loading branch information
bsl-zcs committed Jul 4, 2013
1 parent 257f4d8 commit 6add585
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/main/scala/org/expecty/RecorderMacro.scala
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class RecorderMacro[C <: Context](val context: C, val logging:Boolean = false) {
case Literal(_) => expr // don't record
// don't record value of implicit "this" added by compiler; couldn't find a better way to detect implicit "this" than via point
case Select(x@This(_), y) if getPosition(expr).point == getPosition(x).point => expr
case x:Select if x.symbol.isModule => expr // don't try to record the value of packages
case _ => recordValue(recordSubValues(expr), expr)
}

Expand Down
63 changes: 61 additions & 2 deletions src/test/scala/org/expecty/ExpectyRenderingSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,64 @@ List(1, 2, 3)
}
}

@Test
def tuple() {
outputs("""
(1, 2)._1 == 3
| | |
(1,2) 1 false
""") {
expect {
(1, 2)._1 == 3
}
}
}

@Test
def case_class() {
outputs("""
Some(1).map(_ + 1) == Some(3)
| | | | |
Some(1) | | | Some(3)
| | false
| <function1>
Some(2)
""") {
expect {
Some(1).map(_ + 1) == Some(3)
}
}
}

@Test
def class_with_package() {
outputs("""
collection.mutable.Map(1->"a").get(1) == "b"
| || | |
| |(1,a) | false
| | Some(a)
| scala.Predef$ArrowAssoc@...
Map(1 -> a)
""") {
expect {
collection.mutable.Map(1->"a").get(1) == "b"
}
}
}

@Test
def java_static_method() {
outputs("""
java.util.Collections.emptyList() == null
| |
[] false
""") {
expect {
java.util.Collections.emptyList() == null
}
}
}

@Test
def implicit_conversion() {
outputs("""
Expand All @@ -280,14 +338,15 @@ fred r false
}

def outputs(rendering: String)(expectation: => Boolean) {
def normalize(s:String) = s.trim().lines.mkString
try {
expectation
fail("Expectation should have failed but didn't")
}
catch {
case e: AssertionError => {
val expected = rendering.trim()
val actual = e.getMessage.trim().replaceAll("@[0-9a-f]*", "@\\.\\.\\.")
val expected = normalize(rendering)
val actual = normalize(e.getMessage).replaceAll("@[0-9a-f]*", "@\\.\\.\\.")
if (actual != expected) {
throw new ComparisonFailure("Expectation output doesn't match", expected, actual)
}
Expand Down

0 comments on commit 6add585

Please sign in to comment.