]> git.wincent.com - docvim.git/commitdiff
More misguided refactoring
authorGreg Hurrell <greg@hurrell.net>
Fri, 10 Jun 2016 14:46:13 +0000 (07:46 -0700)
committerGreg Hurrell <greg@hurrell.net>
Fri, 10 Jun 2016 14:46:13 +0000 (07:46 -0700)
lib/Text/Docvim/Util.hs
tests/tasty.hs

index 0535a2252f3b59b13768eae01a5af02ef0518081..982beeadf86c685e12e5959c66b509c907d67af3 100644 (file)
@@ -1,5 +1,5 @@
 -- | Functions to facilitate automated and manual testing.
-module Text.Docvim.Util ( compileUnit
+module Text.Docvim.Util ( compileUnits
                         , p
                         , parseUnit
                         , pm
@@ -19,20 +19,20 @@ import Text.Show.Pretty
 
 -- | Parse a string containing a translation unit.
 parseUnit :: String -> Either ParseError Node
-parseUnit input = runParser unit () "(eval)" input
+parseUnit = runParser unit () "(eval)"
 
--- | Parse and compile a string containing a translation unit.
-compileUnit :: String -> Either ParseError Node
-compileUnit input = do
-  parsed <- parseUnit input
-  return $ compile [parsed]
+-- | Parse and compile a list of strings containing a translation units.
+compileUnits :: [String] -> Either ParseError Node
+compileUnits inputs = do
+  parsed <- mapM parseUnit inputs
+  return $ compile parsed
 
--- | Convenience function: Parse and compile a string containing a translation
--- unit, but always returns a string even in the case of an error.
-p :: String -> String
-p input = case compileUnit input of
-            Left err -> show err
-            Right ast -> ppShow ast
+-- | Convenience function: Parse and compile a list of strings containing
+-- translation units, but always returns a string even in the case of an error.
+p :: [String] -> String
+p inputs = case compileUnits inputs of
+    Left err -> show err
+    Right ast -> ppShow ast
 
 -- | Pretty-prints the result of parsing and compiling an input string.
 --
@@ -40,30 +40,30 @@ p input = case compileUnit input of
 --
 --     pp "unlet g:var"
 pp :: String -> IO ()
-pp = putStrLn . p
+pp input = putStrLn $ p [input]
 
--- | Parse and compile an input string into Vim help format.
-pv :: String -> String
-pv input = case compileUnit input of
-            Left err -> show err
-            Right ast -> vimHelp ast
+-- | Parse and compile a list of input strings into Vim help format.
+pv :: [String] -> String
+pv inputs = case compileUnits inputs of
+    Left err -> show err
+    Right ast -> vimHelp ast
 
 -- | Pretty-prints the result of parsing and compiling an input string and
 -- transforming into Vim help format.
 --
 -- For logging in the REPL.
 ppv :: String -> IO ()
-ppv = putStr . pv
+ppv input = putStr $ pv [input]
 
--- | Parse and compile an input string into Markdown help format.
-pm :: String -> String
-pm input = case compileUnit input of
-            Left err -> show err
-            Right ast -> markdown ast
+-- | Parse and compile a list of input strings into Markdown help format.
+pm :: [String] -> String
+pm inputs = case compileUnits inputs of
+    Left err -> show err
+    Right ast -> markdown ast
 
 -- | Pretty-prints the result of parsing and compiling an input string and
 -- transforming into Markdown format.
 --
 -- For logging in the REPL.
 ppm :: String -> IO ()
-ppm = putStr . pm
+ppm input = putStr $ pm [input]
index e1f958ff74d6346723060e69854b333071fb4576..096ea27f4097d05dfab9bbbbde7750695becef35 100644 (file)
@@ -30,8 +30,8 @@ parseSuccess _        = True
 
 unitTests :: TestTree
 unitTests = testGroup "Unit tests"
-  [ testCase "Compile empty unit" $ assert $ parseSuccess (compileUnit "")
-  , testCase "Compile whitespace-only unit" $ assert $ parseSuccess (compileUnit "  \n    ")
+  [ testCase "Compile empty unit" $ assert $ parseSuccess (compileUnits [""])
+  , testCase "Compile whitespace-only unit" $ assert $ parseSuccess (compileUnits ["  \n    "])
 
   , testCase "Counting all nodes" $
     7 @=? let
@@ -89,14 +89,13 @@ unitTests = testGroup "Unit tests"
       in symbols
   ]
 
-goldenTests :: String -> [[FilePath]] -> (String -> String) -> TestTree
+goldenTests :: String -> [FilePath] -> ([String] -> String) -> TestTree
 goldenTests description sources transform = testGroup groupName $ do
-  files <- sources -- list monad
-  file <- files
+  file <- sources -- list monad
   let
     run = do
       input <- readFile file
-      let output = normalize $ transform input
+      let output = normalize $ transform [input]
       return $ pack output -- pack because tasty-golden wants a ByteString
     name = takeBaseName file
     golden = replaceExtension file ".golden"
@@ -162,7 +161,7 @@ main = do
   vimHelpSources <- getFixtures "tests/fixtures/vim"
   defaultMain $ testGroup "Test suite"
     [ unitTests
-    , goldenTests "parser" [parserSources] p
-    , goldenTests "Markdown printer" [markdownSources] pm
-    , goldenTests "Vim help printer" [vimHelpSources] pv
+    , goldenTests "parser" parserSources p
+    , goldenTests "Markdown printer" markdownSources pm
+    , goldenTests "Vim help printer" vimHelpSources pv
     ]