From bf6f745595570a3ebaad34b8c4a8a8c827e15178 Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Fri, 11 Mar 2016 05:20:55 +0100 Subject: Finish parser chapter. Adds support for a very simple language (described by K.Ast). --- test/Spec.hs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'test') 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 -- cgit v1.2.3