{-# LANGUAGE OverloadedStrings #-} import Test.Framework (defaultMain, testGroup) import Test.Framework.Providers.QuickCheck2 (testProperty) import Test.QuickCheck import K.NanoParsec import qualified Data.Text as T import Data.Text.Arbitrary (Text(..)) import Control.Lens ((^?), _Right) main :: IO () main = defaultMain tests tests = [ testGroup "Parsing" [ testProperty "empty" prop_empty, testProperty "correct_item" prop_correct, testProperty "tooLong_item" prop_tooLong, testProperty "applicative" prop_applicative ] ] isRight (Right _) = True isRight _ = False isLeft = not . isRight prop_empty t = T.null t ==> isLeft (runParser item t) prop_correct t = T.length t == 1 ==> isRight (runParser item t) prop_tooLong t = T.length t > 1 ==> isLeft (runParser item t) prop_applicative x = result == Just (x+1) where x' :: Parser Integer x' = unit x result = runParser (pure (+1) <*> x') "" ^? _Right