blob: 8a9762382e99ea1e48463c192489b7fbee68ac52 (
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
|
module Specs.ArgsSpec where
import Chelleport.Args (parseArgs)
import Chelleport.Types
import Data.Default (Default (def))
import Test.Hspec
test :: SpecWith ()
test = do
describe "#parseArgs" $ do
context "when there are no args" $ do
it "parses default configuration" $ do
let config = parseArgs []
config `shouldBe` Right def
context "when args contains --help" $ do
it "enables show help without parsing the rest of the args" $ do
parseArgs ["--help"] `shouldBe` Right (def {configShowHelp = True})
parseArgs ["--help", "-m", "mode"] `shouldBe` Right (def {configShowHelp = True})
context "when args contains -m or --mode with a valid mode" $ do
it "parses configuration with mode" $ do
parseArgs ["-m", "search"] `shouldBe` Right (def {configMode = ModeSearch def})
parseArgs ["--mode", "search"] `shouldBe` Right (def {configMode = ModeSearch def})
parseArgs ["-m", "hints"] `shouldBe` Right (def {configMode = ModeHints def})
parseArgs ["--mode", "hints"] `shouldBe` Right (def {configMode = ModeHints def})
context "when args contains -m or --mode with an invalid mode" $ do
it "returns with error message" $ do
parseArgs ["--mode", "invalidmode"] `shouldBe` Left "Invalid mode: invalidmode"
parseArgs ["-m", "invalidmode"] `shouldBe` Left "Invalid mode: invalidmode"
context "when args contains -m or --mode without any mode" $ do
it "returns with error message" $ do
parseArgs ["--mode"] `shouldBe` Left "Missing value for mode"
context "when args contains an invalid flag" $ do
it "enables show help without parsing the rest of the args" $ do
parseArgs ["--foobar"] `shouldBe` Left "Unrecognized argument: --foobar"
|