Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper handling of package references #3

Merged
merged 1 commit into from
Jul 4, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
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