summaryrefslogtreecommitdiff
path: root/test/Spec.hs
blob: 612fea6f2eb08e55b611ef61abd9c131d0bf18a0 (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
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(..))

main :: IO ()
main = defaultMain tests

tests = [
          testGroup "Parsing" [
              testProperty "empty" prop_empty,
              testProperty "correct_item" prop_correct,
              testProperty "tooLong_item" prop_tooLong
          ]
      ]

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)