summaryrefslogtreecommitdiff
path: root/cli/source/test/scala/com/rockymadden/stringmetric/cli/OptionMapSpec.scala
blob: a3a1990cc94b9b47680469c5a1999dd859a4004e (plain) (blame)
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
package com.rockymadden.stringmetric.cli

import com.rockymadden.stringmetric.ScalaTest
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner

@RunWith(classOf[JUnitRunner])
final class OptionMapSpec extends ScalaTest {
	"OptionMap" should provide {
		"apply method" when passed {
			"single valid double dashed option" should returns {
				"populated Map" in {
					val options = OptionMap("--help")

					options('help) should equal ("")
				}
			}
			"multiple valid double dashed options" should returns {
				"populated Map" in {
					val options = OptionMap("--help", "--test=test")

					options('help) should equal ("")
					options('test) should equal ("test")
				}
			}
			"invalid double dashed options" should returns {
				"empty Map" in {
					val options = OptionMap("--help#", "--test%=test")

					options.keysIterator.length should be (0)
				}
			}
			"single valid single dashed option" should returns {
				"populated Map" in {
					val options = OptionMap("-h")

					options('h) should equal ("")
				}
			}
			"multiple valid single dashed options" should returns {
				"populated Map" in {
					val options = OptionMap("-h", "-i")

					options('h) should equal ("")
					options('i) should equal ("")
				}
			}
			"invalid single dashed options" should returns {
				"empty Map" in {
					val options = OptionMap("-h-i", "-i#gloo")

					options.keysIterator.length should be (0)
				}
			}
			"single nameless option" should returns {
				"single key populated Map" in {
					val options = OptionMap("filename0")

					options('dashless).count(_ == ' ') should be (0)
				}
			}
			"multiple single nameless options" should returns {
				"single key populated Map" in {
					val options = OptionMap("filename0", "filename1", "filename2")

					options('dashless).count(_ == ' ') should be (2)
				}
			}
			"mixed options" should returns {
				"populated Map" in {
					val options = OptionMap(
						"-q", "--help", "--test=test", "-go", "filename0", "filename1", "filename2"
					)

					options('q) should equal ("")
					options('help) should equal ("")
					options('test) should equal ("test")
					options('go) should equal ("")
					options('dashless).count(_ == ' ') should be (2)
				}
			}
		}
	}
}