forked from scallop/scallop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNumberOptionTest.scala
80 lines (70 loc) · 1.97 KB
/
NumberOptionTest.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
package org.rogach.scallop
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers
import org.rogach.scallop._
import org.rogach.scallop.exceptions._
class NumberOptionTest extends AnyFunSuite with Matchers with CapturingTest with UsefulMatchers {
throwError.value = true
test ("number option") {
val conf = new ScallopConf(Seq("-42")) {
val answer = number()
verify()
}
conf.answer() shouldBe 42
}
test ("required number option provided") {
val conf = new ScallopConf(Seq("-42")) {
val answer = number(required = true)
verify()
}
conf.answer.toOption shouldBe Some(42)
}
test ("required number option not provided") {
expectException(RequiredOptionNotFound("answer")) {
val conf = new ScallopConf(Nil) {
val answer = number(required = true)
verify()
}
}
}
test ("multiple number options") {
val conf = new ScallopConf(Seq("-1", "-2", "-3")) {
val first = number()
val second = number()
val third = number()
verify()
}
conf.first() shouldBe 1
conf.second() shouldBe 2
conf.third() shouldBe 3
}
test ("number option validation success") {
val conf = new ScallopConf(Seq("-42")) {
val answer = number(validate = _ > 10)
verify()
}
}
test ("number option validation failure") {
expectException(ValidationFailure("Validation failure for 'answer' option parameters: 42")) {
val conf = new ScallopConf(Seq("-42")) {
val answer = number(validate = _ < 10)
verify()
}
}
}
test ("number option help text") {
val (out, err) = captureOutput {
val conf = new ScallopConf() {
val first = number("a", descr = "option a")
val second = number("b", descr = "option b")
verify()
}
conf.printHelp()
}
out shouldBe """ -<a> option a
-<b> option b
-h, --help Show help message
"""
err shouldBe ""
}
}