Skip to content

Commit

Permalink
Merge branch 'taisukeoe-fix-diagrams-repeated-bug' into 3.2.x-new
Browse files Browse the repository at this point in the history
  • Loading branch information
bvenners committed Jun 21, 2021
2 parents d3c223a + 4c80d47 commit e6e656b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ object DiagramsMacro {
def handleArgs(argTps: List[TypeRepr], args: List[Term]): (List[Term], List[Term]) =
args.zip(argTps).foldLeft(Nil -> Nil : (List[Term], List[Term])) { case ((diagrams, others), pair) =>
pair match {
case (Typed(Repeated(args, _), _), AppliedType(_, _)) =>
(diagrams :++ args.map(parse), others)
case (arg, ByNameType(_)) =>
(diagrams, others :+ arg)
case (arg, tp) =>
Expand Down Expand Up @@ -131,7 +133,7 @@ object DiagramsMacro {
l.asExpr match {
case '{ $left: DiagrammedExpr[t] } =>
val rights = rs.map(_.asExprOf[DiagrammedExpr[_]])
val res = Select.unique(l, "value").select(sel.symbol).appliedToArgs(diagrams.map(r => Select.unique(r, "value")) ++ others).asExprOf[r]
val res = Select.overloaded(Select.unique(l, "value"), op, Nil, diagrams.map(r => Select.unique(r, "value")) ++ others).asExprOf[r]
'{ DiagrammedExpr.applyExpr[r]($left, ${Expr.ofList(rights)}, $res, $anchor) }.asTerm
}
}
Expand All @@ -150,7 +152,7 @@ object DiagramsMacro {
l.asExpr match {
case '{ $left: DiagrammedExpr[t] } =>
val rights = rs.map(_.asExprOf[DiagrammedExpr[_]])
val res = Select.unique(l, "value").select(sel.symbol).appliedToArgs(diagrams.map(r => Select.unique(r, "value")) ++ others).asExprOf[r]
val res = Select.overloaded(Select.unique(l, "value"), op, Nil, diagrams.map(r => Select.unique(r, "value")) ++ others).asExprOf[r]
'{ DiagrammedExpr.applyExpr[r]($left, ${Expr.ofList(rights)}, $res, $anchor) }.asTerm
}
}
Expand Down Expand Up @@ -187,8 +189,7 @@ object DiagramsMacro {
l.asExpr match {
case '{ $left: DiagrammedExpr[t] } =>
val rights = rs.map(_.asExprOf[DiagrammedExpr[_]])
val res = Select.unique(l, "value").select(sel.symbol).appliedToTypes(targs.map(_.tpe))
.appliedToArgs(diagrams.map(r => Select.unique(r, "value")) ++ others).asExprOf[r]
val res = Select.overloaded(Select.unique(l, "value"), op, targs.map(_.tpe), diagrams.map(r => Select.unique(r, "value")) ++ others).asExprOf[r]
'{ DiagrammedExpr.applyExpr[r]($left, ${Expr.ofList(rights)}, $res, $anchor) }.asTerm
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ class DiagramsSpec extends AnyFunSpec with Matchers with Diagrams {
def woof(f: => Unit) = "woof"
def meow(x: Int = 0, y: Int = 3) = "meow"

def varargs(x: Int, y: String*): (Int, Seq[String]) = (x, y.toSeq)
class CustomList(value: List[Int]) {
def contains(x: Int*): Boolean = x.forall(value.contains(_))
}
val cList1 = new CustomList(List(1, 2, 3))

describe("Diagrams") {

val a = 3
Expand Down Expand Up @@ -584,6 +590,26 @@ class DiagramsSpec extends AnyFunSpec with Matchers with Diagrams {
e.failedCodeLineNumber should be (Some(thisLineNumber - 15))
}

it("should do nothing when is used to check Seq(a, b) == Seq(3, 5)") {
assert(Seq(a, b) == Seq(3, 5))
}

it("should throw TestFailedException when is used to check Set(a, b) == Set(4)") {
val e = intercept[TestFailedException] {
assert(Set(a, b) == Set(4))
}
e.failedCodeFileName should be (Some(fileName))
e.failedCodeLineNumber should be (Some(thisLineNumber - 3))
}

it("should do nothing when is used to check varargs(1, y, z) == 1 -> Seq(y, z)") {
assert(varargs(1, "y", "z") == 1 -> Seq("y", "z"))
}

it("should do nothing when is used to check cList1.contains(1, 2)") {
assert(cList1.contains(1, 2))
}

it("should do nothing when is used to check a === 3") {
assert(a === 3)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ class DirectDiagrammedAssertionsSpec extends AnyFunSpec with org.scalatest.match
def woof(f: => Unit) = "woof"
def meow(x: Int = 0, y: Int = 3) = "meow"

def varargs(x: Int, y: String*): (Int, Seq[String]) = (x, y.toSeq)
class CustomList(value: List[Int]) {
def contains(x: Int*): Boolean = x.forall(value.contains(_))
}
val cList1 = new CustomList(List(1, 2, 3))

describe("DiagrammedAssertions") {

val a = 3
Expand Down Expand Up @@ -583,6 +589,26 @@ class DirectDiagrammedAssertionsSpec extends AnyFunSpec with org.scalatest.match
e.failedCodeFileName should be (Some(fileName))
e.failedCodeLineNumber should be (Some(thisLineNumber - 15))
}

it("should do nothing when is used to check Seq(a, b) == Seq(3, 5)") {
org.scalatest.diagrams.Diagrams.assert(Seq(a, b) == Seq(3, 5))
}

it("should throw TestFailedException when is used to check Set(a, b) == Set(4)") {
val e = intercept[TestFailedException] {
org.scalatest.diagrams.Diagrams.assert(Set(a, b) == Set(4))
}
e.failedCodeFileName should be (Some(fileName))
e.failedCodeLineNumber should be (Some(thisLineNumber - 3))
}

it("should do nothing when is used to check varargs(1, y, z) == 1 -> Seq(y, z)") {
org.scalatest.diagrams.Diagrams.assert(varargs(1, "y", "z") == 1 -> Seq("y", "z"))
}

it("should do nothing when is used to check cList1.contains(1, 2)") {
org.scalatest.diagrams.Diagrams.assert(cList1.contains(1, 2))
}

it("should do nothing when is used to check a === 3") {
org.scalatest.diagrams.Diagrams.assert(a === 3)
Expand Down

0 comments on commit e6e656b

Please sign in to comment.