1
1
module Test.Kore.OptionsParser
2
2
( test_flags
3
+ , test_options
3
4
) where
4
5
5
6
import Prelude.Kore
@@ -20,41 +21,66 @@ test_flags =
20
21
[ testGroup " print-definition"
21
22
[ testCase " default is False" $ do
22
23
let flag_value = willPrintDefinition $ runParser commandLineParser
23
- [" mock/path/to/file " ]
24
+ [" mock/path/to/def " ]
24
25
assertEqual " Expected print-definition to be False by default"
25
26
False flag_value
26
27
, testCase " given explicitly is True" $ do
27
28
let flag_value = willPrintDefinition $ runParser commandLineParser
28
- [" mock/path/to/file " , " --print-definition" ]
29
+ [" mock/path/to/def " , " --print-definition" ]
29
30
assertEqual " Expected --print-definition to give True"
30
31
True flag_value
31
32
, testCase " with `no` prefix is False" $ do
32
33
let flag_value = willPrintDefinition $ runParser commandLineParser
33
- [" mock/path/to/file " , " --no-print-definition" ]
34
+ [" mock/path/to/def " , " --no-print-definition" ]
34
35
assertEqual " Expected --no-print-definition to give False"
35
36
False flag_value
36
37
]
37
38
, testGroup " print-pattern"
38
39
[ testCase " default is False" $ do
39
40
let flag_value = willPrintPattern $ runParser commandLineParser
40
- [" mock/path/to/file " ]
41
+ [" mock/path/to/def " ]
41
42
assertEqual " Expected print-pattern to be False by default"
42
43
False flag_value
43
44
, testCase " given explicitly is True" $ do
44
45
let flag_value = willPrintPattern $ runParser commandLineParser
45
- [" mock/path/to/file " , " --print-pattern" ]
46
+ [" mock/path/to/def " , " --print-pattern" ]
46
47
assertEqual " Expected --print-pattern to give True"
47
48
True flag_value
48
49
, testCase " with `no` prefix is False" $ do
49
50
let flag_value = willPrintPattern $ runParser commandLineParser
50
- [" mock/path/to/file " , " --no-print-pattern" ]
51
+ [" mock/path/to/def " , " --no-print-pattern" ]
51
52
assertEqual " Expected --no-print-pattern to give False"
52
53
False flag_value
53
54
]
54
55
]
55
56
56
- runParser :: Parser a -> [String ] -> a
57
- runParser parser input = fromJust $ getParseResult parserResult
57
+ test_options :: [TestTree ]
58
+ test_options =
59
+ [ testGroup " pattern and module must go together"
60
+ [ testCase " pattern only" $ do
61
+ let result = runParser' commandLineParser
62
+ [" mock/path/to/def" , " --pattern" , " mock/path/to/pat" ]
63
+ assertBool " Expected passing only the pattern option to fail"
64
+ $ isNothing result
65
+ , testCase " module only" $ do
66
+ let result = runParser' commandLineParser
67
+ [" mock/path/to/def" , " --module" , " mock_module" ]
68
+ assertBool " Expected passing only the module option to fail"
69
+ $ isNothing result
70
+ , testCase " pattern and module" $ do
71
+ let result = runParser' commandLineParser
72
+ [" mock/path/to/def" , " --pattern" , " mock/path/to/pat"
73
+ , " --module" , " mock_module" ]
74
+ assertBool " Expected passing both pattern and module options to not fail"
75
+ $ isJust result
76
+ ]
77
+ ]
78
+
79
+ runParser' :: Parser a -> [String ] -> Maybe a
80
+ runParser' parser input = getParseResult parserResult
58
81
where
59
82
parserInfo = info parser mempty
60
83
parserResult = execParserPure defaultPrefs parserInfo input
84
+
85
+ runParser :: Parser a -> [String ] -> a
86
+ runParser parser input = fromJust $ runParser' parser input
0 commit comments