mirror of
https://github.com/github/semantic.git
synced 2024-12-24 23:42:31 +03:00
Remove spec specific readFile
This commit is contained in:
parent
afd82561e9
commit
148edbc184
@ -2,7 +2,6 @@
|
||||
module SpecHelpers
|
||||
( diffFilePaths
|
||||
, parseFilePath
|
||||
, readFile
|
||||
, readFilePair
|
||||
, languageForFilePath
|
||||
) where
|
||||
@ -15,37 +14,24 @@ import Data.Functor.Both
|
||||
import Data.Language
|
||||
import Data.Maybe (fromMaybe)
|
||||
import Data.Source
|
||||
import Prelude hiding (readFile)
|
||||
import Rendering.Renderer
|
||||
import Semantic
|
||||
import Semantic.Task
|
||||
import qualified Semantic.IO as IO
|
||||
import System.FilePath
|
||||
|
||||
readFilePair :: Both FilePath -> IO BlobPair
|
||||
readFilePair paths = do
|
||||
let paths' = fmap (\p -> (p, languageForFilePath p)) paths
|
||||
runBothWith IO.readFilePair paths'
|
||||
|
||||
-- | Returns an s-expression formatted diff for the specified FilePath pair.
|
||||
diffFilePaths :: Both FilePath -> IO B.ByteString
|
||||
diffFilePaths paths = readFilePair paths >>= runTask . diffBlobPair SExpressionDiffRenderer
|
||||
|
||||
-- | Returns an s-expression parse tree for the specified FilePath.
|
||||
parseFilePath :: FilePath -> IO B.ByteString
|
||||
parseFilePath path = do
|
||||
blob <- readFile path
|
||||
runTask (parseBlob SExpressionTermRenderer blob)
|
||||
parseFilePath path = IO.readFile path (languageForFilePath path) >>= runTask . parseBlob SExpressionTermRenderer
|
||||
|
||||
-- | Read a file to a Blob.
|
||||
--
|
||||
-- NB: This is intentionally duplicated from Command.Files because eventually
|
||||
-- we want to be able to test a core Semantic library that has no knowledge of
|
||||
-- the filesystem or Git. The tests, however, will still leverage reading files.
|
||||
readFile :: FilePath -> IO Blob
|
||||
readFile path = do
|
||||
source <- (Just . fromBytes <$> B.readFile path) `catch` (const (pure Nothing) :: IOException -> IO (Maybe Source))
|
||||
pure $ fromMaybe (emptyBlob path) (sourceBlob path (languageForFilePath path) <$> source)
|
||||
-- | Read two files to a BlobPair.
|
||||
readFilePair :: Both FilePath -> IO BlobPair
|
||||
readFilePair paths = let paths' = fmap (\p -> (p, languageForFilePath p)) paths in
|
||||
runBothWith IO.readFilePair paths'
|
||||
|
||||
-- | Returns a Maybe Language based on the FilePath's extension.
|
||||
languageForFilePath :: FilePath -> Maybe Language
|
||||
|
Loading…
Reference in New Issue
Block a user