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)
|
|
|
|
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-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" $
|
2017-07-19 21:01:56 +03:00
|
|
|
for_ diffFixtures $ \ (diffRenderer, diffMode, expected) ->
|
2017-06-16 19:51:42 +03:00
|
|
|
it ("renders to " <> show diffRenderer <> " in mode " <> show diffMode) $ do
|
2017-07-20 00:23:44 +03:00
|
|
|
output <- runTask $ runDiff diffRenderer diffMode
|
2017-04-21 23:56:19 +03:00
|
|
|
output `shouldBe'` expected
|
2017-06-16 19:47:47 +03:00
|
|
|
|
|
|
|
describe "runParse" $
|
2017-07-19 21:01:56 +03:00
|
|
|
for_ parseFixtures $ \ (parseTreeRenderer, parseMode, expected) ->
|
2017-06-16 19:47:47 +03:00
|
|
|
it ("renders to " <> show parseTreeRenderer <> " in mode " <> show parseMode) $ do
|
2017-07-20 00:23:44 +03:00
|
|
|
output <- runTask $ runParse parseTreeRenderer parseMode
|
2017-04-21 23:56:19 +03:00
|
|
|
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-14 17:27:58 +03:00
|
|
|
parseFixtures :: [(SomeRenderer TermRenderer, Either (Handle 'ReadMode) [File], ByteString)]
|
2017-06-16 19:47:47 +03:00
|
|
|
parseFixtures =
|
2017-07-19 21:01:56 +03:00
|
|
|
[ (SomeRenderer SExpressionTermRenderer, pathMode, sExpressionParseTreeOutput)
|
|
|
|
, (SomeRenderer JSONTermRenderer, pathMode, jsonParseTreeOutput)
|
|
|
|
, (SomeRenderer JSONTermRenderer, pathMode', jsonParseTreeOutput')
|
2017-07-19 22:40:56 +03:00
|
|
|
, (SomeRenderer JSONTermRenderer, Right [], emptyJsonParseTreeOutput)
|
2018-04-21 02:34:37 +03:00
|
|
|
, (SomeRenderer (SymbolsTermRenderer defaultSymbolFields), Right [File "test/fixtures/ruby/corpus/method-declaration.A.rb" (Just Ruby)], symbolsOutput)
|
|
|
|
, (SomeRenderer TagsTermRenderer, Right [File "test/fixtures/ruby/corpus/method-declaration.A.rb" (Just Ruby)], tagsOutput)
|
2017-06-16 19:47:47 +03:00
|
|
|
]
|
2018-04-21 02:34:37 +03:00
|
|
|
where pathMode = Right [File "test/fixtures/ruby/corpus/and-or.A.rb" (Just Ruby)]
|
|
|
|
pathMode' = Right [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-04-18 23:55:21 +03:00
|
|
|
jsonParseTreeOutput = "{\"trees\":[{\"path\":\"test/fixtures/ruby/corpus/and-or.A.rb\",\"programNode\":{\"category\":\"Program\",\"children\":[{\"category\":\"LowAnd\",\"children\":[{\"category\":\"Send\",\"children\":[{\"category\":\"Identifier\",\"children\":[],\"name\":\"foo\",\"sourceRange\":[0,3],\"sourceSpan\":{\"start\":[1,1],\"end\":[1,4]}}],\"sourceRange\":[0,3],\"sourceSpan\":{\"start\":[1,1],\"end\":[1,4]}},{\"category\":\"Send\",\"children\":[{\"category\":\"Identifier\",\"children\":[],\"name\":\"bar\",\"sourceRange\":[8,11],\"sourceSpan\":{\"start\":[1,9],\"end\":[1,12]}}],\"sourceRange\":[8,11],\"sourceSpan\":{\"start\":[1,9],\"end\":[1,12]}}],\"sourceRange\":[0,11],\"sourceSpan\":{\"start\":[1,1],\"end\":[1,12]}}],\"sourceRange\":[0,12],\"sourceSpan\":{\"start\":[1,1],\"end\":[2,1]}},\"language\":\"Ruby\"}]}\n"
|
|
|
|
jsonParseTreeOutput' = "{\"trees\":[{\"path\":\"test/fixtures/ruby/corpus/and-or.A.rb\",\"programNode\":{\"category\":\"Program\",\"children\":[{\"category\":\"LowAnd\",\"children\":[{\"category\":\"Send\",\"children\":[{\"category\":\"Identifier\",\"children\":[],\"name\":\"foo\",\"sourceRange\":[0,3],\"sourceSpan\":{\"start\":[1,1],\"end\":[1,4]}}],\"sourceRange\":[0,3],\"sourceSpan\":{\"start\":[1,1],\"end\":[1,4]}},{\"category\":\"Send\",\"children\":[{\"category\":\"Identifier\",\"children\":[],\"name\":\"bar\",\"sourceRange\":[8,11],\"sourceSpan\":{\"start\":[1,9],\"end\":[1,12]}}],\"sourceRange\":[8,11],\"sourceSpan\":{\"start\":[1,9],\"end\":[1,12]}}],\"sourceRange\":[0,11],\"sourceSpan\":{\"start\":[1,1],\"end\":[1,12]}}],\"sourceRange\":[0,12],\"sourceSpan\":{\"start\":[1,1],\"end\":[2,1]}},\"language\":\"Ruby\"},{\"path\":\"test/fixtures/ruby/corpus/and-or.B.rb\",\"programNode\":{\"category\":\"Program\",\"children\":[{\"category\":\"LowOr\",\"children\":[{\"category\":\"Send\",\"children\":[{\"category\":\"Identifier\",\"children\":[],\"name\":\"foo\",\"sourceRange\":[0,3],\"sourceSpan\":{\"start\":[1,1],\"end\":[1,4]}}],\"sourceRange\":[0,3],\"sourceSpan\":{\"start\":[1,1],\"end\":[1,4]}},{\"category\":\"Send\",\"children\":[{\"category\":\"Identifier\",\"children\":[],\"name\":\"bar\",\"sourceRange\":[7,10],\"sourceSpan\":{\"start\":[1,8],\"end\":[1,11]}}],\"sourceRange\":[7,10],\"sourceSpan\":{\"start\":[1,8],\"end\":[1,11]}}],\"sourceRange\":[0,10],\"sourceSpan\":{\"start\":[1,1],\"end\":[1,11]}},{\"category\":\"LowAnd\",\"children\":[{\"category\":\"LowOr\",\"children\":[{\"category\":\"Send\",\"children\":[{\"category\":\"Identifier\",\"children\":[],\"name\":\"a\",\"sourceRange\":[11,12],\"sourceSpan\":{\"start\":[2,1],\"end\":[2,2]}}],\"sourceRange\":[11,12],\"sourceSpan\":{\"start\":[2,1],\"end\":[2,2]}},{\"category\":\"Send\",\"children\":[{\"category\":\"Identifier\",\"children\":[],\"name\":\"b\",\"sourceRange\":[16,17],\"sourceSpan\":{\"start\":[2,6],\"end\":[2,7]}}],\"sourceRange\":[16,17],\"sourceSpan\":{\"start\":[2,6],\"end\":[2,7]}}],\"sourceRange\":[11,17],\"sourceSpan\":{\"start\":[2,1],\"end\":[2,7]}},{\"category\":\"Send\",\"children\":[{\"category\":\"Identifier\",\"children\":[],\"name\":\"c\",\"sourceRange\":[22,23],\"sourceSpan\":{\"start\":[2,12],\"end\":[2,13]}}],\"sourceRange\":[22,23],\"sourceSpan\":{\"start\":[2,12],\"end\":[2,13]}}],\"sourceRange\":[11,23],\"sourceSpan\":{\"start\":[2,1],\"end\":[2,13]}}],\"sourceRange\":[0,24],\"sourceSpan\":{\"start\":[1,1],\"end\":[3,1]}},\"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-14 17:27:58 +03:00
|
|
|
diffFixtures :: [(SomeRenderer DiffRenderer, Either (Handle 'ReadMode) [Both File], ByteString)]
|
2017-06-16 19:51:42 +03:00
|
|
|
diffFixtures =
|
2017-11-22 01:11:16 +03:00
|
|
|
[ (SomeRenderer JSONDiffRenderer, pathMode, jsonOutput)
|
2017-07-19 21:01:56 +03:00
|
|
|
, (SomeRenderer SExpressionDiffRenderer, pathMode, sExpressionOutput)
|
2017-10-10 20:18:11 +03:00
|
|
|
, (SomeRenderer ToCDiffRenderer, pathMode, tocOutput)
|
2017-06-16 19:51:42 +03:00
|
|
|
]
|
2018-04-21 02:34:37 +03:00
|
|
|
where pathMode = Right [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-04-18 23:55:21 +03:00
|
|
|
jsonOutput = "{\"diffs\":[{\"diff\":{\"merge\":{\"after\":{\"category\":\"Program\",\"sourceRange\":[0,21],\"sourceSpan\":{\"start\":[1,1],\"end\":[4,1]}},\"children\":[{\"merge\":{\"after\":{\"category\":\"Method\",\"sourceRange\":[0,20],\"sourceSpan\":{\"start\":[1,1],\"end\":[3,4]}},\"children\":[{\"merge\":{\"after\":{\"category\":\"Empty\",\"sourceRange\":[0,0],\"sourceSpan\":{\"start\":[1,1],\"end\":[1,1]}},\"children\":[],\"before\":{\"category\":\"Empty\",\"sourceRange\":[0,0],\"sourceSpan\":{\"start\":[1,1],\"end\":[1,1]}}}},{\"patch\":{\"replace\":[{\"category\":\"Identifier\",\"children\":[],\"name\":\"foo\",\"sourceRange\":[4,7],\"sourceSpan\":{\"start\":[1,5],\"end\":[1,8]}},{\"category\":\"Identifier\",\"children\":[],\"name\":\"bar\",\"sourceRange\":[4,7],\"sourceSpan\":{\"start\":[1,5],\"end\":[1,8]}}]}},{\"patch\":{\"insert\":{\"category\":\"Identifier\",\"children\":[],\"name\":\"a\",\"sourceRange\":[8,9],\"sourceSpan\":{\"start\":[1,9],\"end\":[1,10]}}}},{\"merge\":{\"after\":{\"category\":\"\",\"sourceRange\":[13,16],\"sourceSpan\":{\"start\":[2,3],\"end\":[2,6]}},\"children\":[{\"patch\":{\"insert\":{\"category\":\"Send\",\"children\":[{\"patch\":{\"insert\":{\"category\":\"Identifier\",\"children\":[],\"name\":\"baz\",\"sourceRange\":[13,16],\"sourceSpan\":{\"start\":[2,3],\"end\":[2,6]}}}}],\"sourceRange\":[13,16],\"sourceSpan\":{\"start\":[2,3],\"end\":[2,6]}}}}],\"before\":{\"category\":\"[]\",\"sourceRange\":[8,11],\"sourceSpan\":{\"start\":[2,1],\"end\":[2,4]}}}}],\"before\":{\"category\":\"Method\",\"sourceRange\":[0,11],\"sourceSpan\":{\"start\":[1,1],\"end\":[2,4]}}}}],\"before\":{\"category\":\"Program\",\"sourceRange\":[0,12],\"sourceSpan\":{\"start\":[1,1],\"end\":[3,1]}}}},\"stat\":{\"replace\":[{\"path\":\"test/fixtures/ruby/corpus/method-declaration.A.rb\",\"language\":\"Ruby\"},{\"path\":\"test/fixtures/ruby/corpus/method-declaration.B.rb\",\"language\":\"Ruby\"}],\"path\":\"test/fixtures/ruby/corpus/method-declaration.A.rb -> test/fixtures/ruby/corpus/method-declaration.B.rb\"}}]}\n"
|
2018-04-11 08:40:46 +03:00
|
|
|
sExpressionOutput = "(Program\n (Method\n (Empty)\n { (Identifier)\n ->(Identifier) }\n {+(Identifier)+}\n (\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"
|