summaryrefslogtreecommitdiff
path: root/test/Spec.hs
blob: 4a908622aa3ae4584f69d85a9501b77eb557ae9a (plain)
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
{-# 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