2018-03-09 20:07:34 +03:00
|
|
|
module Semantic.CLI.Spec (spec) where
|
2017-04-11 03:10:34 +03:00
|
|
|
|
2018-06-01 03:20:51 +03:00
|
|
|
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
|
|
|
|
|
2017-04-11 03:10:34 +03:00
|
|
|
|
|
|
|
spec :: Spec
|
|
|
|
spec = parallel $ do
|
2017-06-16 19:51:42 +03:00
|
|
|
describe "runDiff" $
|
2018-05-15 01:44:19 +03:00
|
|
|
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" $
|
2018-05-15 01:44:19 +03:00
|
|
|
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
|
2017-04-21 01:13:28 +03:00
|
|
|
where
|
2018-06-01 03:20:51 +03:00
|
|
|
shouldBe' actual' expectedFile = do
|
|
|
|
let actual = verbatim actual'
|
|
|
|
expected <- verbatim <$> B.readFile expectedFile
|
2017-04-21 23:56:19 +03:00
|
|
|
actual `shouldBe` expected
|
|
|
|
|
2018-06-01 03:20:51 +03:00
|
|
|
parseFixtures :: [(String, [Blob] -> TaskEff Builder, [File], FilePath)]
|
2017-06-16 19:47:47 +03:00
|
|
|
parseFixtures =
|
2018-06-01 03:20:51 +03:00
|
|
|
[ (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]
|
2018-06-01 03:20:51 +03:00
|
|
|
prefix = "test/fixtures/cli"
|
2017-06-16 19:47:47 +03:00
|
|
|
|
2018-06-01 03:20:51 +03:00
|
|
|
diffFixtures :: [(String, [BlobPair] -> TaskEff Builder, [Both File], FilePath)]
|
2017-06-16 19:51:42 +03:00
|
|
|
diffFixtures =
|
2018-06-01 03:20:51 +03:00
|
|
|
[ (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)]
|
2018-06-01 03:20:51 +03:00
|
|
|
prefix = "test/fixtures/cli"
|