2017-11-27 22:00:53 +03:00
|
|
|
module Semantic.Spec where
|
2017-04-22 00:10:50 +03:00
|
|
|
|
2017-06-24 17:09:50 +03:00
|
|
|
import Data.Blob
|
2017-09-27 19:41:41 +03:00
|
|
|
import Data.Diff
|
2017-07-28 21:37:02 +03:00
|
|
|
import Data.Functor (void)
|
2017-05-30 17:33:48 +03:00
|
|
|
import Data.Functor.Both as Both
|
2017-11-27 22:17:48 +03:00
|
|
|
import Data.Language
|
2017-09-27 19:29:07 +03:00
|
|
|
import Data.Patch
|
2017-09-27 19:37:37 +03:00
|
|
|
import Data.Term
|
2017-11-27 21:30:38 +03:00
|
|
|
import Rendering.Renderer
|
2017-04-22 00:10:50 +03:00
|
|
|
import Semantic
|
2017-05-30 17:33:48 +03:00
|
|
|
import Semantic.Task
|
2017-09-29 22:09:58 +03:00
|
|
|
import System.Exit
|
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-09-29 22:09:58 +03:00
|
|
|
it "throws if not given a language" $ do
|
2017-09-29 22:14:37 +03:00
|
|
|
runTask (parseBlob SExpressionTermRenderer methodsBlob { blobLanguage = Nothing }) `shouldThrow` (\ code -> case code of
|
2017-09-29 22:09:58 +03:00
|
|
|
ExitFailure 1 -> True
|
|
|
|
_ -> False)
|
2017-04-22 00:10:50 +03:00
|
|
|
|
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-08-24 21:46:26 +03:00
|
|
|
output `shouldBe` "(Program\n (Method\n (Empty)\n (Identifier)\n ([])))\n"
|
2017-04-22 00:10:50 +03:00
|
|
|
|
2017-05-31 19:40:27 +03:00
|
|
|
describe "diffTermPair" $ do
|
2017-12-10 19:46:17 +03:00
|
|
|
it "produces an Insert when the first term is missing" $ do
|
|
|
|
result <- runTask (diffTermPair replacing (That (termIn () [])))
|
|
|
|
result `shouldBe` (Diff (Patch (Insert (In () []))) :: Diff [] () ())
|
2017-06-01 18:33:12 +03:00
|
|
|
|
2017-12-10 19:46:17 +03:00
|
|
|
it "produces a Delete when the second term is missing" $ do
|
|
|
|
result <- runTask (diffTermPair replacing (This (termIn () [])))
|
|
|
|
result `shouldBe` (Diff (Patch (Delete (In () []))) :: Diff [] () ())
|
2017-05-30 17:33:59 +03:00
|
|
|
|
2017-04-22 00:10:50 +03:00
|
|
|
where
|
2017-12-11 21:59:05 +03:00
|
|
|
methodsBlob = Blob "def foo\nend\n" "methods.rb" (Just Ruby)
|