2017-04-22 00:10:50 +03:00
|
|
|
module SemanticSpec where
|
|
|
|
|
2017-05-30 17:33:48 +03:00
|
|
|
import Data.Functor.Both as Both
|
|
|
|
import Language
|
|
|
|
import Patch
|
2017-04-22 00:10:50 +03:00
|
|
|
import Prologue
|
2017-05-30 17:33:48 +03:00
|
|
|
import Renderer
|
2017-04-22 00:10:50 +03:00
|
|
|
import Semantic
|
2017-05-30 17:33:48 +03:00
|
|
|
import Semantic.Task
|
|
|
|
import Source
|
|
|
|
import Syntax
|
2017-04-22 00:10:50 +03:00
|
|
|
import Test.Hspec hiding (shouldBe, shouldNotBe, shouldThrow, errorCall)
|
|
|
|
import Test.Hspec.Expectations.Pretty
|
|
|
|
|
|
|
|
spec :: Spec
|
|
|
|
spec = parallel $ do
|
2017-05-31 19:25:40 +03:00
|
|
|
describe "parseBlob" $ do
|
2017-04-22 00:10:50 +03:00
|
|
|
it "parses in the specified language" $ do
|
2017-05-31 19:25:40 +03:00
|
|
|
Just term <- runTask $ parseBlob IdentityTermRenderer methodsBlob
|
2017-04-22 00:10:50 +03:00
|
|
|
void term `shouldBe` cofree (() :< Indexed [ cofree (() :< Method [] (cofree (() :< Leaf "foo")) Nothing [] []) ])
|
|
|
|
|
|
|
|
it "parses line by line if not given a language" $ do
|
2017-05-31 19:25:40 +03:00
|
|
|
Just term <- runTask $ parseBlob IdentityTermRenderer methodsBlob { blobLanguage = Nothing }
|
2017-04-22 00:10:50 +03:00
|
|
|
void term `shouldBe` cofree (() :< Indexed [ cofree (() :< Leaf "def foo\n"), cofree (() :< Leaf "end\n"), cofree (() :< Leaf "") ])
|
|
|
|
|
2017-05-30 17:33:48 +03:00
|
|
|
it "renders with the specified renderer" $ do
|
2017-05-31 19:25:40 +03:00
|
|
|
output <- runTask $ parseBlob SExpressionTermRenderer methodsBlob
|
2017-05-04 00:11:33 +03:00
|
|
|
output `shouldBe` "(Program\n (Method\n (Identifier)))\n"
|
2017-04-22 00:10:50 +03:00
|
|
|
|
2017-05-31 19:40:27 +03:00
|
|
|
describe "diffTermPair" $ do
|
2017-06-01 18:33:12 +03:00
|
|
|
it "produces an Insert when the first blob is missing" $ do
|
|
|
|
result <- runTask (diffTermPair (both (emptySourceBlob "/foo") (sourceBlob "/foo" Nothing "")) (runBothWith replacing) (pure (cofree (() :< []))))
|
|
|
|
(() <$) <$> result `shouldBe` pure (Insert ())
|
|
|
|
|
|
|
|
it "produces a Delete when the second blob is missing" $ do
|
|
|
|
result <- runTask (diffTermPair (both (sourceBlob "/foo" Nothing "") (emptySourceBlob "/foo")) (runBothWith replacing) (pure (cofree (() :< []))))
|
|
|
|
(() <$) <$> result `shouldBe` pure (Delete ())
|
2017-05-30 17:33:59 +03:00
|
|
|
|
2017-04-22 00:10:50 +03:00
|
|
|
where
|
2017-05-10 01:49:38 +03:00
|
|
|
methodsBlob = SourceBlob (Source "def foo\nend\n") "ff7bbbe9495f61d9e1e58c597502d152bab1761e" "methods.rb" (Just defaultPlainBlob) (Just Ruby)
|