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
|
{-# Language GADTs #-}
{-|
Module : Main
Description : Tests for the glirc library
Copyright : (c) Eric Mertens, 2017
License : ISC
Maintainer : emertens@gmail.com
This module test various components of glirc
-}
module Main (main) where
import Client.Commands.Arguments.Spec
import Client.Commands.Arguments.Parser
import Control.Applicative
import System.Exit
import Test.HUnit
main :: IO a
main =
do outcome <- runTestTT tests
if errors outcome == 0 && failures outcome == 0
then exitSuccess
else exitFailure
tests :: Test
tests = test [ argumentParserTests ]
argumentParserTests :: Test
argumentParserTests = test
[ assertEqual "no arg empty"
(Just ())
(parse () (pure ()) "")
, assertEqual "no arg white"
(Just ())
(parse () (pure ()) " ")
, assertEqual "no arg fail"
Nothing
(parse () (pure ()) " a")
, assertEqual "required"
(Just "argument")
(parse () (simpleToken "field") " argument ")
, assertEqual "optional 1"
(Just (Just "argument"))
(parse () (optionalArg (simpleToken "field")) " argument ")
, assertEqual "optional 2"
(Just Nothing)
(parse () (optionalArg (simpleToken "field")) " ")
, assertEqual "remaining"
(Just "some stuff ")
(parse () (remainingArg "field") " some stuff ")
, assertEqual "token and empty remaining"
(Just ("some", ""))
(parse () (liftA2 (,) (simpleToken "first") (remainingArg "second")) " some")
, assertEqual "token and empty remaining 1"
(Just ("some", ""))
(parse () (liftA2 (,) (simpleToken "first") (remainingArg "second")) " some ")
, assertEqual "token and remaining"
(Just ("some", "text here"))
(parse () (liftA2 (,) (simpleToken "first") (remainingArg "second")) " some text here")
, assertEqual "extra whitespace token and remaining"
(Just ("some", " text here"))
(parse () (liftA2 (,) (simpleToken "first") (remainingArg "second")) " some text here")
]
|