Skip to content

Commit 5a3fb20

Browse files
committed
add tests
1 parent b954a37 commit 5a3fb20

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

src/test/scala/com/github/dwickern/macros/NameOfTest.scala

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,15 @@ class NameOfTest extends AnyFunSuite with Matchers {
9292
nameOf[SomeClass](_.foobar) should equal ("foobar")
9393
nameOf { (c: SomeClass) => c.foobar } should equal ("foobar")
9494
nameOf((_: SomeClass).foobar) should equal ("foobar")
95+
qualifiedNameOf[SomeClass](_.foobar) should equal ("foobar")
9596
}
9697

9798
test("object member") {
9899
object SomeObject {
99100
lazy val member = ???
100101
}
101102
nameOf(SomeObject.member) should equal ("member")
103+
qualifiedNameOf[SomeObject.type](_.member) should equal ("member")
102104
}
103105

104106
test("class") {
@@ -110,7 +112,6 @@ class NameOfTest extends AnyFunSuite with Matchers {
110112
nameOf(CaseClass) should equal ("CaseClass")
111113
nameOfType[CaseClass] should equal ("CaseClass")
112114
qualifiedNameOfType[CaseClass] should equal ("com.github.dwickern.macros.CaseClass")
113-
114115
}
115116

116117
test("nested case class member") {
@@ -120,6 +121,43 @@ class NameOfTest extends AnyFunSuite with Matchers {
120121
case class CaseClass(nested1CaseClass: Nested1CaseClass)
121122

122123
qualifiedNameOf[CaseClass](_.nested1CaseClass.nested2CaseClass.nested3CaseClass.member) should equal("nested1CaseClass.nested2CaseClass.nested3CaseClass.member")
124+
qualifiedNameOf((cc: CaseClass) => cc.nested1CaseClass.nested2CaseClass) should equal("nested1CaseClass.nested2CaseClass")
125+
}
126+
127+
test("nested Java method calls") {
128+
qualifiedNameOf[String](_.length.toLong) should equal("length.toLong")
129+
qualifiedNameOf[String](_.length().toString()) should equal("length.toString")
130+
qualifiedNameOf[String] { str => str.length().toString } should equal("length.toString")
131+
}
132+
133+
test("nested symbolic members") {
134+
class C1(val `multi word name`: C2)
135+
class C2(val 你好: C3)
136+
class C3(val ??? : String)
137+
138+
qualifiedNameOf[C1](_.`multi word name`.你好.???) should equal ("multi word name.你好.???")
139+
}
140+
141+
test("nested generic members") {
142+
trait T1 {
143+
def foo[T]: T2 = ???
144+
}
145+
trait T2 {
146+
def bar[T]: Int = ???
147+
}
148+
149+
qualifiedNameOf[T1](_.foo.bar) should equal ("foo.bar")
150+
}
151+
152+
test("nested function call") {
153+
class C1(val c2: C2)
154+
class C2(val c3: C3.type)
155+
object C3 {
156+
def func(x: Int) = ???
157+
}
158+
159+
qualifiedNameOf[C1](_.c2.c3.func _) should equal ("c2.c3.func")
160+
qualifiedNameOf[C1](_.c2.c3.func(???)) should equal ("c2.c3.func")
123161
}
124162

125163
test("object") {
@@ -198,5 +236,7 @@ class NameOfTest extends AnyFunSuite with Matchers {
198236
illTyped(""" nameOf(true) """, "Unsupported constant expression: true")
199237
illTyped(""" nameOf(null) """, "Unsupported constant expression: null")
200238
illTyped(""" nameOf() """, "Unsupported constant expression: \\(\\)")
239+
illTyped(""" qualifiedNameOf[String](_ => ()) """)
240+
illTyped(""" qualifiedNameOf[String](_ => 3) """)
201241
}
202242
}

0 commit comments

Comments
 (0)