File: HasArgumentsSpec.hs

package info (click to toggle)
haskell-getopt-generics 0.13.1.0-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 260 kB
  • sloc: haskell: 1,644; makefile: 6
file content (34 lines) | stat: -rw-r--r-- 1,024 bytes parent folder | download | duplicates (4)
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
{-# LANGUAGE ScopedTypeVariables #-}

module WithCli.HasArgumentsSpec where

import           Control.Monad
import           Test.Hspec
import           Test.QuickCheck

import           WithCli.HasArguments

spec :: Spec
spec = do
  describe "parseBool" $ do
    forM_ ["true", "True", "tRue", "TRUE", "yes", "yEs", "on", "oN"] $ \ true ->
      it ("parses '" ++ true ++ "' as True") $ do
        parseBool true `shouldBe` Just True

    forM_ ["false", "False", "falSE", "FALSE", "no", "nO", "off", "ofF"] $ \ false ->
      it ("parses '" ++ false ++ "' as False") $ do
        parseBool false `shouldBe` Just False

    it "parses every positive integer as true" $ do
      property $ \ (n :: Int) ->
        n > 0 ==>
        parseBool (show n) `shouldBe` Just True

    it "parses every non-positive integer as false" $ do
      property $ \ (n :: Int) ->
        n <= 0 ==>
        parseBool (show n) `shouldBe` Just False

    it "doesn't parse 'foo'" $ do
      parseBool "foo" `shouldBe` (Nothing :: Maybe Bool)