-
Notifications
You must be signed in to change notification settings - Fork 2
/
OptionDslTest.scala
139 lines (120 loc) · 3.41 KB
/
OptionDslTest.scala
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package freecli
package option
import shapeless.{ops => _, _}
import shapeless.test.illTyped
import core.all._
import option.all._
import testkit.Test
class OptionDslTest extends Test {
describe("Options Dsl tests") {
it("allow plain opt") {
opt[String] -- "opt": OptionDsl[Option[String]]
string -- "opt" -~ req: OptionDsl[String]
}
it("allow using default in opt") {
string -- "one" -~ or("1"): OptionDsl[String]
string -- "one" - 'c' -~ or("1"): OptionDsl[String]
string -- "one" - 'c' -~ or("1"): OptionDsl[String]
}
it("allow using default with required in opt") {
string -- "one" -~ req -~ or("1"): OptionDsl[String]
string -- "one" - 'c' -~ req -~ or("2"): OptionDsl[String]
opt[String] -- "one" - 'c' -~ req -~ or("1"): OptionDsl[String]
opt[String] -- "one" - 'c' -~ or("1") -~ req: OptionDsl[String]
}
it("not allow using default or required twice") {
illTyped(
"""opt[String] --"one" -~ or("1") -~ or("1"): OptionDsl[String]"""
)
illTyped("""string --"one" -'c' -~ req -~ req: OptionDsl[String]""")
}
it("allow sub with case class") {
case class A(
value: Option[String],
value2: Option[String],
value3: Option[String]
)
sub[A](des("description")) {
string -- "one" ::
string -- "two" ::
opt[String] -- "three"
}: OptionDsl[A]
}
it("sub does not compile without subconfiguration") {
case class A(v: String)
illTyped("""sub[A](des("description")): OptionDsl[A]""")
}
it("group with help") {
case class A(p: Option[String])
val dsl =
group[A] {
ops.help - 'h' -- "help" ::
string - 'p'
}
}
it("group with help and version") {
case class A(p: Option[String])
val dsl =
group[A] {
ops.help - 'h' -- "help" ::
ops.version - 'v' -- "version" -~ ops.value("1.0") ::
string - 'p'
}
}
it("allow merging options") {
case class A(o: Option[String], o2: Option[Boolean], o3: Boolean)
string -- "name1" ::
string -- "name2" -~ des("name2") ::
int - 'n' ::
sub[A](des("sub")) {
string - 'f' -~ des("f") ::
boolean - 'b' ::
flag - 'g'
}: OptionDsl[Option[String] :: Option[String] :: Option[Int] :: A :: HNil]
}
it("group to single case class") {
case class A(o: Option[String])
group[A] {
string -- "name1"
}
}
it("group to case class") {
case class A(
o: Option[String],
o2: Option[String],
o3: Option[Int],
o4: B
)
case class B(o: Option[String], o2: Option[Boolean], o3: Boolean)
group[A] {
string -- "name1" ::
string -- "name2" -~ des("name2") ::
int - 'n' ::
sub[B](des("sub")) {
string - 'f' -~ des("f") ::
boolean - 'b' ::
flag - 'g'
}
}
}
it("group to tuple") {
groupT {
string -- "name1" ::
string -- "name2" -~ des("name2") ::
int - 'n' ::
subT(des("sub")) {
string - 'f' -~ des("f") ::
boolean - 'b' ::
flag - 'g'
}
}: OptionDsl[
(
Option[String],
Option[String],
Option[Int],
(Option[String], Option[Boolean], Boolean)
)
]
}
}
}