diff options
Diffstat (limited to 'tests/Language/Haskell/StylishSpec.hs')
-rw-r--r-- | tests/Language/Haskell/StylishSpec.hs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/Language/Haskell/StylishSpec.hs b/tests/Language/Haskell/StylishSpec.hs new file mode 100644 index 0000000..77a23b1 --- /dev/null +++ b/tests/Language/Haskell/StylishSpec.hs @@ -0,0 +1,51 @@ +module Language.Haskell.StylishSpec where + +-------------------------------------------------------------------------------- +import Test.Framework (Test, testGroup) +import Test.Framework.Providers.HUnit (testCase) +import Test.HUnit (Assertion, (@?=)) + +-------------------------------------------------------------------------------- +import Language.Haskell.Stylish + +-------------------------------------------------------------------------------- +import System.IO.Unsafe +-------------------------------------------------------------------------------- +tests :: Test +tests = testGroup "Language.Haskell.Stylish.Step.Tabs.Tests" + [ testCase "case 01" case01 + , testCase "case 02" case02 + , testCase "case 03" case03 + ] + +-------------------------------------------------------------------------------- +case01 :: Assertion +case01 = (@?=) result (unsafePerformIO $ format Nothing Nothing input) + where + input = "module Herp where\n data Foo = Bar | Baz" + result = Right [ "module Herp where" + , "data Foo = Bar" + , " | Baz" + ] + +case02 :: Assertion +case02 = (@?=) result (unsafePerformIO $ format (Just configLocation) Nothing input) + where + configLocation = ConfigPath "testdata/test-config.yaml" + input = "module Herp where\n data Foo = Bar | Baz" + result = Right [ "module Herp where" + , "data Foo = Bar" + , " | Baz" + ] + +case03 :: Assertion +case03 = do + actual <- format Nothing (Just fileLocation) input + actual @?= result + where + fileLocation = "directory/File.hs" + input = "module Herp" + result = Left $ + "Language.Haskell.Stylish.Parse.parseModule: could not parse " <> + fileLocation <> + ": ParseFailed (SrcLoc \"<unknown>.hs\" 2 1) \"Parse error: EOF\"" |