1
1
mirror of https://github.com/github/semantic.git synced 2024-12-01 17:59:10 +03:00
semantic/test/Semantic/CLI/Spec.hs

56 lines
2.7 KiB
Haskell

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.API (parseSymbolsBuilder, diffSummaryBuilder)
import Semantic.CLI
import Semantic.IO
import Semantic.Task
import Serializing.Format
import SpecHelpers
spec :: Spec
spec = parallel $ do
describe "runDiff" $
for_ diffFixtures $ \ (diffRenderer, runDiff, files, expected) ->
it ("renders to " <> diffRenderer <> " with files " <> show files) $ do
output <- runTask $ readBlobPairs (Right files) >>= runDiff
runBuilder output `shouldBe'` expected
describe "runParse" $
for_ parseFixtures $ \ (parseTreeRenderer, runParse, files, expected) ->
it ("renders to " <> parseTreeRenderer <> " with files " <> show files) $ do
output <- runTask $ readBlobs (Right files) >>= runParse
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)]
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")
, ("symbols", parseSymbolsBuilder Serializing.Format.JSON, path'', prefix </> "parse-tree.symbols.json")
]
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"
diffFixtures :: [(String, [BlobPair] -> TaskEff Builder, [Both File], FilePath)]
diffFixtures =
[ (show JSONDiffRenderer, runDiff JSONDiffRenderer, pathMode, prefix </> "diff-tree.json")
, (show SExpressionDiffRenderer, runDiff SExpressionDiffRenderer, pathMode, "test/fixtures/ruby/corpus/method-declaration.diffA-B.txt")
, ("toc summaries", diffSummaryBuilder Serializing.Format.JSON, pathMode, prefix </> "diff-tree.toc.json")
]
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"