2018-03-09 20:07:34 +03:00
|
|
|
module Semantic.CLI.Spec (spec) where
|
2017-04-11 03:10:34 +03:00
|
|
|
|
2017-07-28 21:37:02 +03:00
|
|
|
import Control.Monad (when)
|
2018-05-15 01:44:19 +03:00
|
|
|
import Data.ByteString.Builder
|
2017-07-28 21:37:02 +03:00
|
|
|
import Data.Foldable (for_)
|
2017-11-27 19:57:27 +03:00
|
|
|
import Semantic.CLI
|
2018-05-14 17:27:58 +03:00
|
|
|
import Semantic.IO
|
2018-05-15 01:44:19 +03:00
|
|
|
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
|
2017-04-21 23:56:19 +03:00
|
|
|
shouldBe' actual expected = do
|
|
|
|
when (actual /= expected) $ print actual
|
|
|
|
actual `shouldBe` expected
|
|
|
|
|
2018-05-15 01:44:19 +03:00
|
|
|
parseFixtures :: [(String, [Blob] -> TaskEff Builder, [File], ByteString)]
|
2017-06-16 19:47:47 +03:00
|
|
|
parseFixtures =
|
2018-05-15 01:44:19 +03:00
|
|
|
[ (show SExpressionTermRenderer, runParse SExpressionTermRenderer, pathMode, sExpressionParseTreeOutput)
|
|
|
|
, (show JSONTermRenderer, runParse JSONTermRenderer, pathMode, jsonParseTreeOutput)
|
|
|
|
, (show JSONTermRenderer, runParse JSONTermRenderer, pathMode', jsonParseTreeOutput')
|
|
|
|
, (show JSONTermRenderer, runParse JSONTermRenderer, [], emptyJsonParseTreeOutput)
|
|
|
|
, (show (SymbolsTermRenderer defaultSymbolFields), runParse (SymbolsTermRenderer defaultSymbolFields), [File "test/fixtures/ruby/corpus/method-declaration.A.rb" (Just Ruby)], symbolsOutput)
|
|
|
|
, (show TagsTermRenderer, runParse TagsTermRenderer, [File "test/fixtures/ruby/corpus/method-declaration.A.rb" (Just Ruby)], tagsOutput)
|
2017-06-16 19:47:47 +03:00
|
|
|
]
|
2018-05-15 01:39:41 +03:00
|
|
|
where pathMode = [File "test/fixtures/ruby/corpus/and-or.A.rb" (Just Ruby)]
|
|
|
|
pathMode' = [File "test/fixtures/ruby/corpus/and-or.A.rb" (Just Ruby), File "test/fixtures/ruby/corpus/and-or.B.rb" (Just Ruby)]
|
2017-06-16 19:47:47 +03:00
|
|
|
|
2018-04-11 08:40:46 +03:00
|
|
|
sExpressionParseTreeOutput = "(Program\n (LowAnd\n (Send\n (Identifier))\n (Send\n (Identifier))))\n"
|
2018-05-31 20:56:04 +03:00
|
|
|
jsonParseTreeOutput = "{\"trees\":[{\"tree\":{\"term\":\"Program\",\"children\":[{\"children\":{\"term\":\"Send\",\"sourceRange\":[8,11],\"sendReceiver\":null,\"sendBlock\":null,\"sendArgs\":[],\"sourceSpan\":{\"start\":[1,9],\"end\":[1,12]},\"sendSelector\":{\"term\":\"Identifier\",\"name\":\"bar\",\"sourceRange\":[8,11],\"sourceSpan\":{\"start\":[1,9],\"end\":[1,12]}}},\"term\":\"LowAnd\",\"sourceRange\":[0,11],\"sourceSpan\":{\"start\":[1,1],\"end\":[1,12]}}],\"sourceRange\":[0,12],\"sourceSpan\":{\"start\":[1,1],\"end\":[2,1]}},\"path\":\"test/fixtures/ruby/corpus/and-or.A.rb\",\"language\":\"Ruby\"}]}\n"
|
|
|
|
jsonParseTreeOutput' = "{\"trees\":[{\"tree\":{\"term\":\"Program\",\"children\":[{\"children\":{\"term\":\"Send\",\"sourceRange\":[8,11],\"sendReceiver\":null,\"sendBlock\":null,\"sendArgs\":[],\"sourceSpan\":{\"start\":[1,9],\"end\":[1,12]},\"sendSelector\":{\"term\":\"Identifier\",\"name\":\"bar\",\"sourceRange\":[8,11],\"sourceSpan\":{\"start\":[1,9],\"end\":[1,12]}}},\"term\":\"LowAnd\",\"sourceRange\":[0,11],\"sourceSpan\":{\"start\":[1,1],\"end\":[1,12]}}],\"sourceRange\":[0,12],\"sourceSpan\":{\"start\":[1,1],\"end\":[2,1]}},\"path\":\"test/fixtures/ruby/corpus/and-or.A.rb\",\"language\":\"Ruby\"},{\"tree\":{\"term\":\"Program\",\"children\":[{\"children\":{\"term\":\"Send\",\"sourceRange\":[7,10],\"sendReceiver\":null,\"sendBlock\":null,\"sendArgs\":[],\"sourceSpan\":{\"start\":[1,8],\"end\":[1,11]},\"sendSelector\":{\"term\":\"Identifier\",\"name\":\"bar\",\"sourceRange\":[7,10],\"sourceSpan\":{\"start\":[1,8],\"end\":[1,11]}}},\"term\":\"LowOr\",\"sourceRange\":[0,10],\"sourceSpan\":{\"start\":[1,1],\"end\":[1,11]}},{\"children\":{\"term\":\"Send\",\"sourceRange\":[22,23],\"sendReceiver\":null,\"sendBlock\":null,\"sendArgs\":[],\"sourceSpan\":{\"start\":[2,12],\"end\":[2,13]},\"sendSelector\":{\"term\":\"Identifier\",\"name\":\"c\",\"sourceRange\":[22,23],\"sourceSpan\":{\"start\":[2,12],\"end\":[2,13]}}},\"term\":\"LowAnd\",\"sourceRange\":[11,23],\"sourceSpan\":{\"start\":[2,1],\"end\":[2,13]}}],\"sourceRange\":[0,24],\"sourceSpan\":{\"start\":[1,1],\"end\":[3,1]}},\"path\":\"test/fixtures/ruby/corpus/and-or.B.rb\",\"language\":\"Ruby\"}]}\n"
|
2018-01-08 20:36:17 +03:00
|
|
|
emptyJsonParseTreeOutput = "{\"trees\":[]}\n"
|
2018-04-18 23:55:21 +03:00
|
|
|
symbolsOutput = "{\"files\":[{\"path\":\"test/fixtures/ruby/corpus/method-declaration.A.rb\",\"symbols\":[{\"span\":{\"start\":[1,1],\"end\":[2,4]},\"kind\":\"Method\",\"symbol\":\"foo\"}],\"language\":\"Ruby\"}]}\n"
|
|
|
|
tagsOutput = "[{\"span\":{\"start\":[1,1],\"end\":[2,4]},\"path\":\"test/fixtures/ruby/corpus/method-declaration.A.rb\",\"kind\":\"Method\",\"symbol\":\"foo\",\"line\":\"def foo\",\"language\":\"Ruby\"}]\n"
|
2017-04-21 23:56:19 +03:00
|
|
|
|
|
|
|
|
2018-05-15 01:44:19 +03:00
|
|
|
diffFixtures :: [(String, [BlobPair] -> TaskEff Builder, [Both File], ByteString)]
|
2017-06-16 19:51:42 +03:00
|
|
|
diffFixtures =
|
2018-05-15 01:44:19 +03:00
|
|
|
[ (show JSONDiffRenderer, runDiff JSONDiffRenderer, pathMode, jsonOutput)
|
|
|
|
, (show SExpressionDiffRenderer, runDiff SExpressionDiffRenderer, pathMode, sExpressionOutput)
|
|
|
|
, (show ToCDiffRenderer, runDiff ToCDiffRenderer, pathMode, tocOutput)
|
2017-06-16 19:51:42 +03:00
|
|
|
]
|
2018-05-15 01:39:41 +03:00
|
|
|
where pathMode = [both (File "test/fixtures/ruby/corpus/method-declaration.A.rb" (Just Ruby)) (File "test/fixtures/ruby/corpus/method-declaration.B.rb" (Just Ruby))]
|
2017-04-21 23:56:19 +03:00
|
|
|
|
2018-05-31 20:56:04 +03:00
|
|
|
jsonOutput = "{\"diffs\":[{\"diff\":{\"merge\":{\"term\":\"Program\",\"children\":[{\"merge\":{\"after\":{\"sourceRange\":[0,20],\"sourceSpan\":{\"start\":[1,1],\"end\":[3,4]}},\"methodParameters\":[{\"patch\":{\"insert\":{\"term\":\"Identifier\",\"name\":\"a\",\"sourceRange\":[8,9],\"sourceSpan\":{\"start\":[1,9],\"end\":[1,10]}}}}],\"methodName\":{\"patch\":{\"replace\":[{\"term\":\"Identifier\",\"name\":\"foo\",\"sourceRange\":[4,7],\"sourceSpan\":{\"start\":[1,5],\"end\":[1,8]}},{\"term\":\"Identifier\",\"name\":\"bar\",\"sourceRange\":[4,7],\"sourceSpan\":{\"start\":[1,5],\"end\":[1,8]}}]}},\"methodContext\":[],\"methodReceiver\":{\"merge\":{\"after\":{\"sourceRange\":[0,0],\"sourceSpan\":{\"start\":[1,1],\"end\":[1,1]}},\"term\":\"Empty\",\"before\":{\"sourceRange\":[0,0],\"sourceSpan\":{\"start\":[1,1],\"end\":[1,1]}}}},\"term\":\"Method\",\"methodBody\":{\"merge\":{\"after\":{\"sourceRange\":[13,16],\"sourceSpan\":{\"start\":[2,3],\"end\":[2,6]}},\"children\":[{\"patch\":{\"insert\":{\"term\":\"Send\",\"sourceRange\":[13,16],\"sendReceiver\":null,\"sendBlock\":null,\"sendArgs\":[],\"sourceSpan\":{\"start\":[2,3],\"end\":[2,6]},\"sendSelector\":{\"patch\":{\"insert\":{\"term\":\"Identifier\",\"name\":\"baz\",\"sourceRange\":[13,16],\"sourceSpan\":{\"start\":[2,3],\"end\":[2,6]}}}}}}}],\"before\":{\"sourceRange\":[8,11],\"sourceSpan\":{\"start\":[2,1],\"end\":[2,4]}}}},\"before\":{\"sourceRange\":[0,11],\"sourceSpan\":{\"start\":[1,1],\"end\":[2,4]}}}}],\"before\":{\"sourceRange\":[0,12],\"sourceSpan\":{\"start\":[1,1],\"end\":[3,1]}},\"after\":{\"sourceRange\":[0,21],\"sourceSpan\":{\"start\":[1,1],\"end\":[4,1]}}}},\"stat\":{\"path\":\"test/fixtures/ruby/corpus/method-declaration.A.rb -> test/fixtures/ruby/corpus/method-declaration.B.rb\",\"replace\":[{\"path\":\"test/fixtures/ruby/corpus/method-declaration.A.rb\",\"language\":\"Ruby\"},{\"path\":\"test/fixtures/ruby/corpus/method-declaration.B.rb\",\"language\":\"Ruby\"}]}}]}\n"
|
2018-05-30 00:25:31 +03:00
|
|
|
sExpressionOutput = "(Program\n (Method\n (Empty)\n { (Identifier)\n ->(Identifier) }\n {+(Identifier)+}\n (Statements\n {+(Send\n {+(Identifier)+})+})))\n"
|
2018-04-18 23:55:21 +03:00
|
|
|
tocOutput = "{\"changes\":{\"test/fixtures/ruby/corpus/method-declaration.A.rb -> test/fixtures/ruby/corpus/method-declaration.B.rb\":[{\"span\":{\"start\":[1,1],\"end\":[3,4]},\"category\":\"Method\",\"term\":\"bar\",\"changeType\":\"modified\"}]},\"errors\":{}}\n"
|