mirror of
https://github.com/alpmestan/taggy.git
synced 2024-08-16 18:30:30 +03:00
Merge pull request #1 from fmapfmapfmap/simplify-tests
Use Test.Hspec.Attoparsec.
This commit is contained in:
commit
9f0d0c2568
@ -68,7 +68,7 @@ test-suite spec
|
||||
base == 4.*
|
||||
, text
|
||||
, hspec
|
||||
, hspec-expectations
|
||||
, hspec-attoparsec
|
||||
, vector
|
||||
, attoparsec
|
||||
, unordered-containers
|
||||
|
@ -2,16 +2,14 @@
|
||||
|
||||
module Text.Taggy.ParserSpec where
|
||||
|
||||
import Control.Monad
|
||||
import Data.Attoparsec.Text.Lazy
|
||||
import Data.Text.Lazy
|
||||
import Test.Hspec
|
||||
import Test.Hspec.Attoparsec (shouldParse)
|
||||
import qualified Test.Hspec.Attoparsec.Source (Source((~>)))
|
||||
import Text.Taggy.Parser
|
||||
import Text.Taggy.Types
|
||||
|
||||
main :: IO ()
|
||||
main = hspec spec
|
||||
|
||||
spec :: Spec
|
||||
spec = do
|
||||
describe "tagopen parser" $ do
|
||||
@ -100,18 +98,4 @@ spec = do
|
||||
]
|
||||
|
||||
(~>) :: Text -> Parser a -> Either String a
|
||||
t ~> p = eitherResult $ parse p t
|
||||
|
||||
shouldParse :: (Eq a, Show a) => Either String a -> a -> Expectation
|
||||
res `shouldParse` expectedVal =
|
||||
either (expectationFailure . errmsg)
|
||||
checkEquality
|
||||
res
|
||||
|
||||
where errmsg err = " expected: " ++ show expectedVal
|
||||
++ "\n but parse failed with error: " ++ err
|
||||
|
||||
checkEquality parsedVal =
|
||||
when (parsedVal /= expectedVal) $
|
||||
expectationFailure $ " expected: " ++ show expectedVal
|
||||
++ "\n but got: " ++ show parsedVal
|
||||
(~>) = (Test.Hspec.Attoparsec.Source.~>)
|
||||
|
Loading…
Reference in New Issue
Block a user