Skip to content

Commit

Permalink
Merge pull request #120 from eed3si9n/wip/method
Browse files Browse the repository at this point in the history
Skip Ident when it's a method call
  • Loading branch information
eed3si9n authored Dec 29, 2020
2 parents ad89b35 + 5762e6a commit 8074232
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 18 deletions.
3 changes: 2 additions & 1 deletion shared/src/main/scala-2/verify/sourcecode/Compat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ object Compat {
nearestEnclosingMethod(enclosingOwner(c)).asMethod.paramLists
}

def isDotty: Boolean = false
def isScala3: Boolean = false
def isDotty: Boolean = isScala3
}
19 changes: 11 additions & 8 deletions shared/src/main/scala-3/verify/asserts/RecorderMacro.scala
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,24 @@ class RecorderMacro(using qctx0: Quotes) {
runtime.select(m)
}
def skipIdent(sym: Symbol): Boolean =
sym.fullName match {
case "scala" | "java" => true
case fullName if fullName.startsWith("scala.") => true
case fullName if fullName.startsWith("java.") => true
case _ => false
sym match {
case sym if sym.isDefDef => sym.signature.paramSigs.nonEmpty
case _ =>
sym.fullName match {
case "scala" | "java" => true
case fullName if fullName.startsWith("scala.") => true
case fullName if fullName.startsWith("java.") => true
case _ => false
}
}

def skipSelect(sym: Symbol): Boolean = {
def skipSelect(sym: Symbol): Boolean =
(sym match {
case sym if sym.isDefDef => sym.signature.paramSigs.nonEmpty
case sym if sym.isDefDef => skipIdent(sym)
case sym if sym.isValDef => skipIdent(sym)
case _ => true
})

}
expr match {
case Select(_, _) if skipSelect(expr.symbol) => expr
case TypeApply(_, _) => expr
Expand Down
3 changes: 2 additions & 1 deletion shared/src/main/scala-3/verify/sourcecode/Compat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ package verify
package sourcecode

object Compat {
def isDotty: Boolean = true
def isScala3: Boolean = true
def isDotty: Boolean = isScala3
}
33 changes: 25 additions & 8 deletions shared/src/test/scala/example/asserttest/RenderingTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
package example.asserttest

import verify._
import verify.sourcecode.Compat.isDotty
import verify.sourcecode.Compat.isScala3

object RenderingTest extends BasicTestSuite {
test("literals") {
Expand All @@ -22,15 +22,15 @@ object RenderingTest extends BasicTestSuite {
"abc".length() == 2
| |
3 false
""") {
""") {
assert {
"abc".length() == 2
}
}
}

test("List.apply") {
if (isDotty) {
if (isScala3) {
outputs("""assertion failed
List() == List(1, 2)
Expand Down Expand Up @@ -58,7 +58,7 @@ List() == List(1, 2)
}

test("List.apply2") {
if (isDotty) {
if (isScala3) {
outputs("""assertion failed
List(1, 2) == List()
Expand Down Expand Up @@ -239,7 +239,7 @@ Person(Fred,42)
val brand = "BMW"
val model = "M5"

if (isDotty) {
if (isScala3) {
outputs("""assertion failed
Car(brand, model).brand == "Audi"
Expand All @@ -266,8 +266,22 @@ BMW M5
}
}

test("method apply") {
outputs("""assertion failed
something(0) == "something1"
| |
something false
""") {
assert {
something(0) == "something1"
}
}
}

test("tuple") {
if (isDotty) {
if (isScala3) {
outputs("""assertion failed
(1, 2)._1 == 3
Expand Down Expand Up @@ -308,7 +322,7 @@ Some(23) | Some(22)

test("message") {
val person = Person()
if (isDotty) {
if (isScala3) {
outputs("""assertion failed: something something
person.age == 43
Expand Down Expand Up @@ -346,7 +360,7 @@ assert(person.age == 43, "something something")
|have it sterile with idleness, or manured with industry, why, the power
|and corrigible authority of this lies in our wills.""".stripMargin

if (isDotty) {
if (isScala3) {
outputs(
"""assertion failed: custom message
Expand Down Expand Up @@ -407,6 +421,8 @@ and corrigible authority of this lies in our wills. |
}
}

def something(x: Int): String = "something"

case class Person(name: String = "Fred", age: Int = 42) {
def doIt() = "done"
def sayTwice(word: String) = word * 2
Expand All @@ -417,4 +433,5 @@ and corrigible authority of this lies in our wills. |
case class Car(val brand: String, val model: String) {
override def toString = brand + " " + model
}

}

0 comments on commit 8074232

Please sign in to comment.