forked from com-lihaoyi/sourcecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArgsTests.scala
More file actions
69 lines (51 loc) · 2 KB
/
ArgsTests.scala
File metadata and controls
69 lines (51 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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))
// FIXME Can't manage to get the arg values from dotty…
val checkValues = !TestUtil.isDotty
def check(expected: Seq[Seq[(String, Any)]]): Unit =
if (checkValues)
assert(args == expected, s"Expected: $expected, got: $args")
else
assert(args.map(_.map(_._1)) == expected.map(_.map(_._1)), s"Expected: ${expected.map(_.map(_._1))}, got: ${args.map(_.map(_._1))}")
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")
check(Seq(Seq("p1" -> "text", "p2" -> 42, "p3" -> false), Seq("foo" -> "foo", "bar" -> "bar")))
new Foo("text", 42)
check(Seq(Seq("p1" -> "text", "p2" -> 42)))
foo("text", 42, false)("foo", "bar")
check(Seq(Seq("p1" -> "text", "p2" -> 42, "p3" -> false), Seq("foo" -> "foo", "bar" -> "bar")))
bar("text", 42, false)("foo", "bar")
check(Seq(Seq("p1" -> "text", "p2" -> 42, "p3" -> false), Seq("foo" -> "foo", "bar" -> "bar")))
baz
check(Seq())
withImplicit("text", 42, false)("foo")
check(Seq(Seq("p1" -> "text", "p2" -> 42, "p3" -> false), Seq("foo" -> "foo")))
implicit val implicitFoo = "bar"
withImplicit("text", 42, false)
check(Seq(Seq("p1" -> "text", "p2" -> 42, "p3" -> false), Seq("foo" -> "bar")))
}
}