1
1
mirror of https://github.com/github/semantic.git synced 2024-12-18 20:31:55 +03:00
semantic/test/Semantic/Spec.hs

33 lines
1.6 KiB
Haskell
Raw Normal View History

2019-10-30 20:16:17 +03:00
{-# LANGUAGE OverloadedStrings #-}
2018-03-13 21:10:50 +03:00
module Semantic.Spec (spec) where
import Control.Effect.Reader
import Control.Exception (fromException)
import SpecHelpers
import Data.Blob (NoLanguageForBlob (..))
2019-02-12 23:49:34 +03:00
import Semantic.Api hiding (Blob)
2018-03-13 21:10:50 +03:00
2019-05-22 05:28:32 +03:00
-- we need some lenses here, oof
setBlobLanguage :: Language -> Blob -> Blob
setBlobLanguage lang b = b { blobFile = (blobFile b) { fileLanguage = lang }}
spec :: Spec
2019-06-20 00:22:09 +03:00
spec = do
describe "parseBlob" $ do
2019-10-21 23:46:02 +03:00
let methodsBlob = makeBlob "def foo\nend\n" "methods.rb" Ruby mempty
it "returns error if given an unknown language (json)" $ do
output <- fmap runBuilder . runTaskOrDie . runReader (PerLanguageModes ALaCarte) $ parseTermBuilder TermJSONTree [ setBlobLanguage Unknown methodsBlob ]
output `shouldBe` "{\"trees\":[{\"path\":\"methods.rb\",\"error\":\"NoLanguageForBlob \\\"methods.rb\\\"\",\"language\":\"Unknown\"}]}\n"
2018-09-25 22:04:58 +03:00
it "throws if given an unknown language for sexpression output" $ do
2019-10-01 00:59:23 +03:00
res <- runTaskWithOptions defaultOptions (runReader (PerLanguageModes ALaCarte) (runParseWithConfig (parseTermBuilder TermSExpression [setBlobLanguage Unknown methodsBlob])))
case res of
Left exc -> fromException exc `shouldBe` Just (NoLanguageForBlob "methods.rb")
Right _bad -> fail "Expected parseTermBuilder to fail for an unknown language"
2017-05-30 17:33:48 +03:00
it "renders with the specified renderer" $ do
output <- fmap runBuilder . runTaskOrDie . runReader (PerLanguageModes ALaCarte) $ parseTermBuilder TermSExpression [methodsBlob]
output `shouldBe` "(Statements\n (Method\n (Empty)\n (Identifier)\n (Statements)))\n"