1
1
mirror of https://github.com/github/semantic.git synced 2024-12-28 09:21:35 +03:00
semantic/test/SemanticSpec.hs

44 lines
1.8 KiB
Haskell
Raw Normal View History

module SemanticSpec where
2017-06-24 17:09:50 +03:00
import Data.Blob
2017-07-28 21:37:02 +03:00
import Data.Functor (void)
2017-09-12 17:49:45 +03:00
import Data.Functor.Binding
2017-05-30 17:33:48 +03:00
import Data.Functor.Both as Both
2017-09-12 17:49:45 +03:00
import Data.Functor.Sum
2017-09-09 16:18:08 +03:00
import Diff
2017-05-30 17:33:48 +03:00
import Language
import Renderer
import Semantic
2017-05-30 17:33:48 +03:00
import Semantic.Task
import Syntax
2017-09-09 16:18:08 +03:00
import Term
import Test.Hspec hiding (shouldBe, shouldNotBe, shouldThrow, errorCall)
import Test.Hspec.Expectations.Pretty
spec :: Spec
spec = parallel $ do
describe "parseBlob" $ do
it "parses in the specified language" $ do
Just term <- runTask $ parseBlob IdentityTermRenderer methodsBlob
2017-09-11 22:48:58 +03:00
void term `shouldBe` Term (() `In` Indexed [ Term (() `In` Method [] (Term (() `In` Leaf "foo")) Nothing [] []) ])
it "parses line by line if not given a language" $ do
Just term <- runTask $ parseBlob IdentityTermRenderer methodsBlob { blobLanguage = Nothing }
2017-09-11 22:48:58 +03:00
void term `shouldBe` Term (() `In` Indexed [ Term (() `In` Leaf "def foo\n"), Term (() `In` Leaf "end\n"), Term (() `In` Leaf "") ])
2017-05-30 17:33:48 +03:00
it "renders with the specified renderer" $ do
output <- runTask $ parseBlob SExpressionTermRenderer methodsBlob
output `shouldBe` "(Program\n (Method\n (Identifier)))\n"
describe "diffTermPair" $ do
it "produces an Insert when the first blob is missing" $ do
result <- runTask (diffTermPair (both (emptyBlob "/foo") (sourceBlob "/foo" Nothing "")) (runBothWith replacing) (pure (termIn () [])))
2017-09-12 17:49:45 +03:00
result `shouldBe` Diff (Let mempty (Either (In () (InR []))))
it "produces a Delete when the second blob is missing" $ do
result <- runTask (diffTermPair (both (sourceBlob "/foo" Nothing "") (emptyBlob "/foo")) (runBothWith replacing) (pure (termIn () [])))
2017-09-12 17:49:45 +03:00
result `shouldBe` Diff (Let mempty (Either (In () (InL []))))
where
2017-06-24 17:15:31 +03:00
methodsBlob = Blob "def foo\nend\n" "ff7bbbe9495f61d9e1e58c597502d152bab1761e" "methods.rb" (Just defaultPlainBlob) (Just Ruby)