summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKjetil Orbekk <kjetil.orbekk@gmail.com>2016-03-11 05:20:55 +0100
committerKjetil Orbekk <kjetil.orbekk@gmail.com>2016-03-11 05:21:50 +0100
commitbf6f745595570a3ebaad34b8c4a8a8c827e15178 (patch)
treed7731846dbe42d3bf1e33a56a727904e8abc891b /test
parent92c9891946646f0f54a19b7699e128571fbdc4b3 (diff)
Finish parser chapter.HEADmaster
Adds support for a very simple language (described by K.Ast).
Diffstat (limited to 'test')
-rw-r--r--test/Spec.hs10
1 files changed, 9 insertions, 1 deletions
diff --git a/test/Spec.hs b/test/Spec.hs
index 612fea6..4a90862 100644
--- a/test/Spec.hs
+++ b/test/Spec.hs
@@ -1,3 +1,4 @@
+{-# LANGUAGE OverloadedStrings #-}
import Test.Framework (defaultMain, testGroup)
import Test.Framework.Providers.QuickCheck2 (testProperty)
@@ -6,6 +7,7 @@ import K.NanoParsec
import qualified Data.Text as T
import Data.Text.Arbitrary (Text(..))
+import Control.Lens ((^?), _Right)
main :: IO ()
main = defaultMain tests
@@ -14,7 +16,8 @@ tests = [
testGroup "Parsing" [
testProperty "empty" prop_empty,
testProperty "correct_item" prop_correct,
- testProperty "tooLong_item" prop_tooLong
+ testProperty "tooLong_item" prop_tooLong,
+ testProperty "applicative" prop_applicative
]
]
@@ -26,3 +29,8 @@ 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