lentil-1.0.9.1: test/Lentil/HelpersSpec.hs
module Lentil.HelpersSpec where
import Test.Hspec
import Text.Parsec
import Text.Parsec.String
import Lentil.Helpers
import Prelude -- 7.8 hack
-- Parsing tests
-- simple parser (choosable if we are at begin of line or else)
sp :: Parser a -> String -> Maybe a
sp p cs = either (const Nothing) Just
(runParser p () fp cs)
where fp = "<f>"
main :: IO ()
main = hspec spec
spec :: Spec
spec = do
describe "manyTill1" $ do
it "behaves like manyTill on non-empty string" $
sp (manyTill1 anyChar newline) "foo\n" `shouldBe`
sp (manyTill anyChar newline) "foo\n"
it "fails on empty string (while manyTill does not)" $
(sp (manyTill1 anyChar newline) "\n",
sp (manyTill anyChar newline) "\n") `shouldBe` (Nothing,
Just "")
it "has the same behaviour as manyTill on 1 char w/o end char" $
sp (manyTill1 anyChar newline) "f" `shouldBe`
sp (manyTill anyChar newline) "f"
describe "aliasp" $ do
it "parses an extension alias" $
aliasp "aaa%bc" `shouldBe` Just (".aaa", ".bc")
it "fails on incorrect input" $
aliasp "aaabc" `shouldBe` Nothing