forked from scallop/scallop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDefaultConverterTest.scala
47 lines (35 loc) · 1.38 KB
/
DefaultConverterTest.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
package org.rogach.scallop
import org.rogach.scallop.exceptions._
import org.scalatest.funsuite.AnyFunSuite
import scala.concurrent.duration._
class DurationConverterTest extends AnyFunSuite with UsefulMatchers {
throwError.value = true
test("convert to Duration") {
def getcf(args: Seq[String]) = new ScallopConf(args) {
val foo = opt[Duration]()
verify()
}
getcf(List("-f", "1 minute")).foo.toOption ==== Some(1.minute)
getcf(List("-f", "Inf")).foo.toOption ==== Some(Duration.Inf)
getcf(List("-f", "MinusInf")).foo.toOption ==== Some(Duration.MinusInf)
expectException(WrongOptionFormat("foo", "bar", "wrong arguments format")) {
getcf(List("-f", "bar")).foo.toOption ==== Some(Duration.MinusInf)
}
}
}
class FiniteDurationConverterTest extends AnyFunSuite with UsefulMatchers {
throwError.value = true
test("convert to Duration") {
def getcf(args: Seq[String]) = new ScallopConf(args) {
val foo = opt[FiniteDuration]()
verify()
}
getcf(List("-f", "1 minute")).foo.toOption ==== Some(1.minute)
expectException(WrongOptionFormat("foo", "Inf", "wrong arguments format")) {
getcf(List("-f", "Inf")).foo.toOption ==== Some(Duration.Inf)
}
expectException(WrongOptionFormat("foo", "bar", "wrong arguments format")) {
getcf(List("-f", "bar")).foo.toOption ==== Some(Duration.MinusInf)
}
}
}