ghc-mod/test/UtilsSpec.hs

22 lines
1.3 KiB
Haskell
Raw Normal View History

2014-05-01 00:32:10 +00:00
module UtilsSpec where
import Language.Haskell.GhcMod.Utils
import Control.Exception
import TestUtils
2014-05-01 00:32:10 +00:00
import Test.Hspec
spec :: Spec
spec = do
describe "extractParens" $ do
it "extracts the part of a string surrounded by parentheses" $ do
extractParens "asdasdasd ( hello [ world ] )()() kljlkjlkjlk" `shouldBe` "( hello [ world ] )"
extractParens "[(PackageName \"template-haskell\",InstalledPackageId \"template-haskell-2.9.0.0-8e2a49468f3b663b671c437d8579cd28\"),(PackageName \"base\",InstalledPackageId \"base-4.7.0.0-e4567cc9a8ef85f78696b03f3547b6d5\"),(PackageName \"Cabal\",InstalledPackageId \"Cabal-1.18.1.3-b9a44a5b15a8bce47d40128ac326e369\")][][]" `shouldBe` "[(PackageName \"template-haskell\",InstalledPackageId \"template-haskell-2.9.0.0-8e2a49468f3b663b671c437d8579cd28\"),(PackageName \"base\",InstalledPackageId \"base-4.7.0.0-e4567cc9a8ef85f78696b03f3547b6d5\"),(PackageName \"Cabal\",InstalledPackageId \"Cabal-1.18.1.3-b9a44a5b15a8bce47d40128ac326e369\")]"
describe "liftMonadError" $ do
it "converts IOErrors to GhcModError" $ do
shouldReturnError $
2014-08-19 03:06:36 +00:00
runD' $ liftIOExceptions $ throw (userError "hello") >> return ""
shouldReturnError $
2014-08-19 03:06:36 +00:00
runD' $ liftIOExceptions $ readFile "/DOES_NOT_EXIST" >> return ""