packages feed

hspec-megaparsec 0.1.1 → 0.2.0

raw patch · 5 files changed

+69/−43 lines, 5 filesdep +containersdep +semigroupsdep ~hspec-megaparsecdep ~megaparsecPVP ok

version bump matches the API change (PVP)

Dependencies added: containers, semigroups

Dependency ranges changed: hspec-megaparsec, megaparsec

API changes (from Hackage documentation)

- Test.Hspec.Megaparsec: failsLeaving :: (Show a, Eq s, Show s, Stream s t) => (State s, Either ParseError a) -> s -> Expectation
+ Test.Hspec.Megaparsec: failsLeaving :: (Show a, Eq s, Show s, Stream s) => (State s, Either (ParseError (Token s) e) a) -> s -> Expectation
- Test.Hspec.Megaparsec: initialState :: Stream s t => s -> State s
+ Test.Hspec.Megaparsec: initialState :: s -> State s
- Test.Hspec.Megaparsec: parseSatisfies :: Show a => Either ParseError a -> (a -> Bool) -> Expectation
+ Test.Hspec.Megaparsec: parseSatisfies :: (Ord t, ShowToken t, ShowErrorComponent e, Show a) => Either (ParseError t e) a -> (a -> Bool) -> Expectation
- Test.Hspec.Megaparsec: shouldFailOn :: (Show a, Stream s t) => (s -> Either ParseError a) -> s -> Expectation
+ Test.Hspec.Megaparsec: shouldFailOn :: Show a => (s -> Either (ParseError t e) a) -> s -> Expectation
- Test.Hspec.Megaparsec: shouldFailWith :: Show a => Either ParseError a -> ParseError -> Expectation
+ Test.Hspec.Megaparsec: shouldFailWith :: (Ord t, ShowToken t, ShowErrorComponent e, Show a) => Either (ParseError t e) a -> ParseError t e -> Expectation
- Test.Hspec.Megaparsec: shouldParse :: (Eq a, Show a) => Either ParseError a -> a -> Expectation
+ Test.Hspec.Megaparsec: shouldParse :: (Ord t, ShowToken t, ShowErrorComponent e, Eq a, Show a) => Either (ParseError t e) a -> a -> Expectation
- Test.Hspec.Megaparsec: shouldSucceedOn :: (Show a, Stream s t) => (s -> Either ParseError a) -> s -> Expectation
+ Test.Hspec.Megaparsec: shouldSucceedOn :: (Ord t, ShowToken t, ShowErrorComponent e, Show a) => (s -> Either (ParseError t e) a) -> s -> Expectation
- Test.Hspec.Megaparsec: succeedsLeaving :: (Show a, Eq s, Show s, Stream s t) => (State s, Either ParseError a) -> s -> Expectation
+ Test.Hspec.Megaparsec: succeedsLeaving :: (ShowToken (Token s), ShowErrorComponent e, Show a, Eq s, Show s, Stream s) => (State s, Either (ParseError (Token s) e) a) -> s -> Expectation

Files

CHANGELOG.md view
@@ -1,3 +1,7 @@+## Hspec Megaparsec 0.2.0++* This version of `hspec-megaparsec` should be used with Megaparsec 5.+ ## Hspec Megaparsec 0.1.1  * Make it pass tests with Megaparsec 4.4.0 and later.
README.md view
@@ -3,6 +3,7 @@ [![License BSD3](https://img.shields.io/badge/license-BSD3-brightgreen.svg)](http://opensource.org/licenses/BSD-3-Clause) [![Hackage](https://img.shields.io/hackage/v/hspec-megaparsec.svg?style=flat)](https://hackage.haskell.org/package/hspec-megaparsec) [![Stackage Nightly](http://stackage.org/package/hspec-megaparsec/badge/nightly)](http://stackage.org/nightly/package/hspec-megaparsec)+[![Stackage LTS](http://stackage.org/package/hspec-megaparsec/badge/lts)](http://stackage.org/lts/package/hspec-megaparsec) [![Build Status](https://travis-ci.org/mrkkrp/hspec-megaparsec.svg?branch=master)](https://travis-ci.org/mrkkrp/hspec-megaparsec) [![Coverage Status](https://coveralls.io/repos/mrkkrp/hspec-megaparsec/badge.svg?branch=master&service=github)](https://coveralls.io/github/mrkkrp/hspec-megaparsec?branch=master) 
Test/Hspec/Megaparsec.hs view
@@ -9,6 +9,8 @@ -- -- Utility functions for testing Megaparsec parsers with Hspec. +{-# LANGUAGE FlexibleContexts #-}+ module Test.Hspec.Megaparsec   ( -- * Basic expectations     shouldParse@@ -24,9 +26,10 @@ where  import Control.Monad (unless)+import Data.List.NonEmpty (NonEmpty (..)) import Test.Hspec.Expectations import Text.Megaparsec-import Text.Megaparsec.Pos (initialPos, defaultTabWidth)+import Text.Megaparsec.Pos (defaultTabWidth)  ---------------------------------------------------------------------------- -- Basic expectations@@ -35,8 +38,8 @@ -- -- > parse letterChar "" "x" `shouldParse` 'x' -shouldParse :: (Eq a, Show a)-  => Either ParseError a+shouldParse :: (Ord t, ShowToken t, ShowErrorComponent e, Eq a, Show a)+  => Either (ParseError t e) a      -- ^ Result of parsing as returned by function like 'parse'   -> a                 -- ^ Desired result   -> Expectation@@ -51,8 +54,8 @@ -- -- > parse (many punctuationChar) "" "?!!" `parseSatisfies` ((== 3) . length) -parseSatisfies :: Show a-  => Either ParseError a+parseSatisfies :: (Ord t, ShowToken t, ShowErrorComponent e, Show a)+  => Either (ParseError t e) a      -- ^ Result of parsing as returned by function like 'parse'   -> (a -> Bool)       -- ^ Predicate   -> Expectation@@ -67,8 +70,8 @@ -- -- > parse (char 'x') "" `shouldFailOn` "a" -shouldFailOn :: (Show a, Stream s t)-  => (s -> Either ParseError a)+shouldFailOn :: Show a+  => (s -> Either (ParseError t e) a)      -- ^ Parser that takes stream and produces result or error message   -> s                 -- ^ Input that the parser should fail on   -> Expectation@@ -78,8 +81,8 @@ -- -- > parse (char 'x') "" `shouldSucceedOn` "x" -shouldSucceedOn :: (Show a, Stream s t)-  => (s -> Either ParseError a)+shouldSucceedOn :: (Ord t, ShowToken t, ShowErrorComponent e, Show a)+  => (s -> Either (ParseError t e) a)      -- ^ Parser that takes stream and produces result or error message   -> s                 -- ^ Input that the parser should succeed on   -> Expectation@@ -96,9 +99,9 @@ -- > parse (char 'x') "" "b" `shouldFailWith` -- >   newErrorMessages [Unexpected "'b'", Expected "'x'"] (initialPos "") -shouldFailWith :: Show a-  => Either ParseError a-  -> ParseError+shouldFailWith :: (Ord t, ShowToken t, ShowErrorComponent e, Show a)+  => Either (ParseError t e) a+  -> ParseError t e   -> Expectation r `shouldFailWith` e = case r of   Left e' -> unless (e == e') . expectationFailure $@@ -119,8 +122,8 @@ -- -- See also: 'initialState'. -failsLeaving :: (Show a, Eq s, Show s, Stream s t)-  => (State s, Either ParseError a)+failsLeaving :: (Show a, Eq s, Show s, Stream s)+  => (State s, Either (ParseError (Token s) e) a)      -- ^ Parser that takes stream and produces result along with actual      -- state information   -> s                 -- ^ Part of input that should be left unconsumed@@ -137,8 +140,13 @@ -- -- See also: 'initialState'. -succeedsLeaving :: (Show a, Eq s, Show s, Stream s t)-  => (State s, Either ParseError a)+succeedsLeaving :: ( ShowToken (Token s)+                   , ShowErrorComponent e+                   , Show a+                   , Eq s+                   , Show s+                   , Stream s )+  => (State s, Either (ParseError (Token s) e) a)      -- ^ Parser that takes stream and produces result along with actual      -- state information   -> s                 -- ^ Part of input that should be left unconsumed@@ -150,15 +158,15 @@ -- with empty file name, default tab width and position at 1 line and 1 -- column). -initialState :: Stream s t => s -> State s-initialState s = State s (initialPos "") defaultTabWidth+initialState :: s -> State s+initialState s = State s (initialPos "" :| []) defaultTabWidth  ---------------------------------------------------------------------------- -- Helpers  -- | Expectation that argument is result of a failed parser. -shouldFail :: Show a => Either ParseError a -> Expectation+shouldFail :: Show a => Either (ParseError t e) a -> Expectation shouldFail r = case r of   Left _ -> return ()   Right v -> expectationFailure $@@ -166,7 +174,8 @@  -- | Expectation that argument is result of a succeeded parser. -shouldSucceed :: Show a => Either ParseError a -> Expectation+shouldSucceed :: (Ord t, ShowToken t, ShowErrorComponent e, Show a)+  => Either (ParseError t e) a -> Expectation shouldSucceed r = case r of   Left e -> expectationFailure $     "the parser is expected to succeed, but it failed with:\n" ++@@ -175,7 +184,7 @@  -- | Compare two streams for equality and in the case of mismatch report it. -checkUnconsumed :: (Eq s, Show s, Stream s t)+checkUnconsumed :: (Eq s, Show s, Stream s)   => s                 -- ^ Expected unconsumed input   -> s                 -- ^ Actual unconsumed input   -> Expectation@@ -186,5 +195,6 @@ -- | Render parse error in a way that is suitable for inserting it in test -- suite report. -showParseError :: ParseError -> String-showParseError = unlines . fmap ("  " ++) . lines . show+showParseError :: (Ord t, ShowToken t, ShowErrorComponent e)+  => ParseError t e -> String+showParseError = unlines . fmap ("  " ++) . lines . parseErrorPretty
hspec-megaparsec.cabal view
@@ -31,7 +31,7 @@ -- POSSIBILITY OF SUCH DAMAGE.  name:                 hspec-megaparsec-version:              0.1.1+version:              0.2.0 cabal-version:        >= 1.10 license:              BSD3 license-file:         LICENSE.md@@ -53,11 +53,16 @@  library   build-depends:      base               >= 4.6 && < 5+                    , containers         >= 0.5 && < 0.6                     , hspec-expectations >= 0.5-                    , megaparsec         >= 4.2+                    , megaparsec         >= 5.0 && < 6.0++  if !impl(ghc >= 8.0)+    build-depends:    semigroups         == 0.18.*+   exposed-modules:    Test.Hspec.Megaparsec   if flag(dev)-    ghc-options:      -Wall -Werror+    ghc-options:      -Wall   else     ghc-options:      -Wall   default-language:   Haskell2010@@ -67,14 +72,18 @@   hs-source-dirs:     tests   type:               exitcode-stdio-1.0   if flag(dev)-    ghc-options:      -Wall -Werror+    ghc-options:      -Wall   else     ghc-options:      -Wall   build-depends:      base               >= 4.6 && < 5+                    , containers         >= 0.5 && < 0.6                     , hspec              >= 2.0                     , hspec-expectations >= 0.5-                    , hspec-megaparsec   >= 0.1-                    , megaparsec         >= 4.2+                    , hspec-megaparsec   >= 0.2+                    , megaparsec         >= 5.0 && < 6.0+  if !impl(ghc >= 8.0)+    build-depends:    semigroups         == 0.18.*+   default-language:   Haskell2010  source-repository head
tests/Main.hs view
@@ -34,11 +34,12 @@  module Main (main) where +import Data.List.NonEmpty (NonEmpty (..)) import Test.Hspec import Test.Hspec.Megaparsec import Text.Megaparsec-import Text.Megaparsec.Error (newErrorMessages)-import Text.Megaparsec.Pos (initialPos)+import Text.Megaparsec.String+import qualified Data.Set as E  #if !MIN_VERSION_base(4,8,0) import Control.Applicative ((<*))@@ -50,29 +51,30 @@ main = hspec $ do   describe "shouldParse" $     it "works" $-      parse letterChar "" "x" `shouldParse` 'x'+      parse (letterChar :: Parser Char) "" "x" `shouldParse` 'x'   describe "parseSatisfies" $     it "works" $-      parse (many punctuationChar) "" "?!!" `parseSatisfies` ((== 3) . length)+      parse (many punctuationChar :: Parser String) "" "?!!"+        `parseSatisfies` ((== 3) . length)   describe "shouldFailOn" $     it "works" $-      parse (char 'x') "" `shouldFailOn` "a"+      parse (char 'x' :: Parser Char) "" `shouldFailOn` "a"   describe "shouldSucceedOn" $     it "works" $-      parse (char 'x') "" `shouldSucceedOn` "x"+      parse (char 'x' :: Parser Char) "" `shouldSucceedOn` "x"   describe "shouldFailWith" $     it "works" $-      parse (char 'x') "" "b" `shouldFailWith`-        newErrorMessages [Unexpected "'b'", Expected "'x'"] (initialPos "")+      parse (char 'x' :: Parser Char) "" "b" `shouldFailWith`+        ParseError+          { errorPos        = initialPos "" :| []+          , errorUnexpected = E.singleton (Tokens $ 'b' :| [])+          , errorExpected   = E.singleton (Tokens $ 'x' :| [])+          , errorCustom     = E.empty }   describe "failsLeaving" $     it "works" $-      runParser' (many (char 'x') <* eof) (initialState "xxa")-#if MIN_VERSION_megaparsec(4,4,0)+      runParser' (many (char 'x') <* eof :: Parser String) (initialState "xxa")         `failsLeaving` "a"-#else-        `failsLeaving` "xxa"-#endif   describe "succeedsLeaving" $     it "works" $-      runParser' (many (char 'x')) (initialState "xxa")+      runParser' (many (char 'x') :: Parser String) (initialState "xxa")         `succeedsLeaving` "a"