1
1
mirror of https://github.com/github/semantic.git synced 2024-12-18 12:21:57 +03:00
semantic/test/Semantic/CLI/Spec.hs

55 lines
2.7 KiB
Haskell
Raw Normal View History

module Semantic.CLI.Spec (spec) where
import Control.Monad (when)
import qualified Data.ByteString as B
import Data.ByteString.Builder
import Data.Foldable (for_)
import Semantic.CLI
import Semantic.IO
import Semantic.Task
2018-03-13 21:10:50 +03:00
import SpecHelpers
spec :: Spec
spec = parallel $ do
2017-06-16 19:51:42 +03:00
describe "runDiff" $
for_ diffFixtures $ \ (diffRenderer, runDiff, files, expected) ->
it ("renders to " <> diffRenderer <> " with files " <> show files) $ do
output <- runTask $ readBlobPairs (Right files) >>= runDiff
2018-05-14 17:28:01 +03:00
runBuilder output `shouldBe'` expected
2017-06-16 19:47:47 +03:00
describe "runParse" $
for_ parseFixtures $ \ (parseTreeRenderer, runParse, files, expected) ->
it ("renders to " <> parseTreeRenderer <> " with files " <> show files) $ do
output <- runTask $ readBlobs (Right files) >>= runParse
2018-05-14 17:28:01 +03:00
runBuilder output `shouldBe'` expected
where
shouldBe' actual' expectedFile = do
let actual = verbatim actual'
expected <- verbatim <$> B.readFile expectedFile
actual `shouldBe` expected
parseFixtures :: [(String, [Blob] -> TaskEff Builder, [File], FilePath)]
2017-06-16 19:47:47 +03:00
parseFixtures =
[ (show SExpressionTermRenderer, runParse SExpressionTermRenderer, path, "test/fixtures/ruby/corpus/and-or.parseA.txt")
, (show JSONTermRenderer, runParse JSONTermRenderer, path, prefix </> "parse-tree.json")
, (show JSONTermRenderer, runParse JSONTermRenderer, path', prefix </> "parse-trees.json")
, (show JSONTermRenderer, runParse JSONTermRenderer, [], prefix </> "parse-tree-empty.json")
, (show (SymbolsTermRenderer defaultSymbolFields), runParse (SymbolsTermRenderer defaultSymbolFields), path'', prefix </> "parse-tree.symbols.json")
, (show TagsTermRenderer, runParse TagsTermRenderer, path'', prefix </> "parse-tree.tags.json")
2017-06-16 19:47:47 +03:00
]
2018-06-05 01:26:47 +03:00
where path = [File "test/fixtures/ruby/corpus/and-or.A.rb" Ruby]
path' = [File "test/fixtures/ruby/corpus/and-or.A.rb" Ruby, File "test/fixtures/ruby/corpus/and-or.B.rb" Ruby]
path'' = [File "test/fixtures/ruby/corpus/method-declaration.A.rb" Ruby]
prefix = "test/fixtures/cli"
2017-06-16 19:47:47 +03:00
diffFixtures :: [(String, [BlobPair] -> TaskEff Builder, [Both File], FilePath)]
2017-06-16 19:51:42 +03:00
diffFixtures =
[ (show JSONDiffRenderer, runDiff JSONDiffRenderer, pathMode, prefix </> "diff-tree.json")
, (show SExpressionDiffRenderer, runDiff SExpressionDiffRenderer, pathMode, "test/fixtures/ruby/corpus/method-declaration.diffA-B.txt")
, (show ToCDiffRenderer, runDiff ToCDiffRenderer, pathMode, prefix </> "diff-tree.toc.json")
2017-06-16 19:51:42 +03:00
]
2018-06-05 01:26:47 +03:00
where pathMode = [both (File "test/fixtures/ruby/corpus/method-declaration.A.rb" Ruby) (File "test/fixtures/ruby/corpus/method-declaration.B.rb" Ruby)]
prefix = "test/fixtures/cli"