-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from benhag/args
Added macro for passing all arguments of a method as implicit parameter
- Loading branch information
Showing
6 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
sourcecode/shared/src/test/scala/sourcecode/ArgsTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package sourcecode | ||
|
||
object ArgsTests { | ||
def apply() = { | ||
|
||
var args: Seq[Seq[(String, Any)]] = Seq() | ||
|
||
def debug(implicit arguments: sourcecode.Args): Unit = args = arguments.value.map(_.map(t => t.source -> t.value)) | ||
|
||
def foo(p1: String, p2: Long, p3: Boolean)(foo: String, bar: String): Unit = { | ||
debug | ||
} | ||
|
||
def bar(p1: String, p2: Long, p3: Boolean)(foo: String, bar: String): Unit = { | ||
val bar = { | ||
debug | ||
"bar" | ||
} | ||
} | ||
|
||
def baz: Unit = { | ||
debug | ||
} | ||
|
||
def withImplicit(p1: String, p2: Long, p3: Boolean)(implicit foo: String): Unit = { | ||
debug | ||
} | ||
|
||
class Foo(p1: String, p2: Long, p3: Boolean)(foo: String, bar: String) { | ||
debug | ||
|
||
def this(p1: String, p2: Long) = { | ||
this(p1, p2, false)("foo", "bar") | ||
debug | ||
} | ||
} | ||
|
||
new Foo("text", 42, false)("foo", "bar") | ||
assert(args == Seq(Seq("p1" -> "text", "p2" -> 42, "p3" -> false), Seq("foo" -> "foo", "bar" -> "bar"))) | ||
|
||
new Foo("text", 42) | ||
assert(args == Seq(Seq("p1" -> "text", "p2" -> 42))) | ||
|
||
foo("text", 42, false)("foo", "bar") | ||
assert(args == Seq(Seq("p1" -> "text", "p2" -> 42, "p3" -> false), Seq("foo" -> "foo", "bar" -> "bar"))) | ||
|
||
bar("text", 42, false)("foo", "bar") | ||
assert(args == Seq(Seq("p1" -> "text", "p2" -> 42, "p3" -> false), Seq("foo" -> "foo", "bar" -> "bar"))) | ||
|
||
baz | ||
assert(args == Seq()) | ||
|
||
withImplicit("text", 42, false)("foo") | ||
assert(args == Seq(Seq("p1" -> "text", "p2" -> 42, "p3" -> false), Seq("foo" -> "foo"))) | ||
|
||
implicit val implicitFoo = "bar" | ||
withImplicit("text", 42, false) | ||
assert(args == Seq(Seq("p1" -> "text", "p2" -> 42, "p3" -> false), Seq("foo" -> "bar"))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters