Skip to content

Commit 7a967a7

Browse files
committed
add named arguments tests
1 parent f70a179 commit 7a967a7

8 files changed

+60
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package example
2+
3+
object NamedApplyBlockMethods/*<<=example.NamedApplyBlockMethods.*/ {
4+
val local/*<<=example.NamedApplyBlockMethods.local.*/ = 1
5+
def foo/*<<=example.NamedApplyBlockMethods.foo().*/(a/*<<=example.NamedApplyBlockMethods.foo().(a)*/: Int/*=>>scala.Int#*/ = 1, b/*<<=example.NamedApplyBlockMethods.foo().(b)*/: Int/*=>>scala.Int#*/ = 2, c/*<<=example.NamedApplyBlockMethods.foo().(c)*/: Int/*=>>scala.Int#*/ = 3): Int/*=>>scala.Int#*/ = a/*=>>example.NamedApplyBlockMethods.foo().(a)*/ +/*=>>scala.Int#`+`(+4).*/ b/*=>>example.NamedApplyBlockMethods.foo().(b)*/ +/*=>>scala.Int#`+`(+4).*/ c/*=>>example.NamedApplyBlockMethods.foo().(c)*/
6+
def baseCase/*<<=example.NamedApplyBlockMethods.baseCase().*/ = foo/*=>>example.NamedApplyBlockMethods.foo().*/(local/*=>>example.NamedApplyBlockMethods.local.*/, c = 3) // as named apply is desugared, it would take more work to inspect within the body of the setter
7+
def recursive/*<<=example.NamedApplyBlockMethods.recursive().*/ = foo/*=>>example.NamedApplyBlockMethods.foo().*/(local/*=>>example.NamedApplyBlockMethods.local.*/, c = foo(local, c = 3)) // as named apply is desugared, it would take more work to inspect within the body of the setter
8+
}
9+
10+
object NamedApplyBlockCaseClassConstruction/*<<=example.NamedApplyBlockCaseClassConstruction.*/ {
11+
case class Msg/*<<=example.NamedApplyBlockCaseClassConstruction.Msg#*/(body/*<<=example.NamedApplyBlockCaseClassConstruction.Msg#body.*/: String/*=>>scala.Predef.String#*/, head/*<<=example.NamedApplyBlockCaseClassConstruction.Msg#head.*/: String/*=>>scala.Predef.String#*/ = "default", tail/*<<=example.NamedApplyBlockCaseClassConstruction.Msg#tail.*/: String/*=>>scala.Predef.String#*/)
12+
val bodyText/*<<=example.NamedApplyBlockCaseClassConstruction.bodyText.*/ = "body"
13+
val msg/*<<=example.NamedApplyBlockCaseClassConstruction.msg.*/ = Msg/*=>>example.NamedApplyBlockCaseClassConstruction.Msg.*/(bodyText/*=>>example.NamedApplyBlockCaseClassConstruction.bodyText.*/, tail = "tail")
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package example
2+
3+
object NamedApplyBlockMethods {
4+
val local = 1
5+
def foo(a: Int = 1, b: Int = 2, c: Int = 3): Int = a + b + c
6+
def baseCase = foo(local, c = 3) // as named apply is desugared, it would take more work to inspect within the body of the setter
7+
def recursive = foo(local, c = foo(local, c = 3)) // as named apply is desugared, it would take more work to inspect within the body of the setter
8+
}
9+
10+
object NamedApplyBlockCaseClassConstruction {
11+
case class Msg(body: String, head: String = "default", tail: String)
12+
val bodyText = "body"
13+
val msg = Msg(bodyText, tail = "tail")
14+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package example
2+
3+
class NamedArguments/*<<=example.NamedArguments#*/ {
4+
case class User/*<<=example.NamedArguments#User#*/(name/*<<=example.NamedArguments#User#name.*/: String/*=>>scala.Predef.String#*/)
5+
User/*=>>example.NamedArguments#User.*/(name = "John") // as there is no API to get the symbols of method arguments, this proposes a problem for how to generate references from a NamedArg
6+
User/*=>>example.NamedArguments#User.*/.apply/*=>>example.NamedArguments#User.apply().*/(name = "John") // as there is no API to get the symbols of method arguments, this proposes a problem for how to generate references from a NamedArg
7+
}

tests/semanticdb/NamedArguments.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package example
2+
3+
class NamedArguments {
4+
case class User(name: String)
5+
User(name = "John") // as there is no API to get the symbols of method arguments, this proposes a problem for how to generate references from a NamedArg
6+
User.apply(name = "John") // as there is no API to get the symbols of method arguments, this proposes a problem for how to generate references from a NamedArg
7+
}

tests/semanticdb/Objects.expect.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package objects
2+
3+
object X/*<<=objects.X.*/ {
4+
object Y/*<<=objects.X.Y.*/
5+
}

tests/semanticdb/Objects.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package objects
2+
3+
object X {
4+
object Y
5+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package example
2+
3+
trait A/*<<=example.A#*/ { def foo/*<<=example.A#foo().*/: Int/*=>>scala.Int#*/ }
4+
class B/*<<=example.B#*/() extends A/*=>>example.A#*/ { def foo/*<<=example.B#foo().*/: Int/*=>>scala.Int#*/ = 2 }

tests/semanticdb/Overrides.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package example
2+
3+
trait A { def foo: Int }
4+
class B() extends A { def foo: Int = 2 }

0 commit comments

Comments
 (0)