2017-04-22 00:10:50 +03:00
|
|
|
module SemanticSpec where
|
|
|
|
|
|
|
|
import Prologue
|
|
|
|
import Semantic
|
|
|
|
import Test.Hspec hiding (shouldBe, shouldNotBe, shouldThrow, errorCall)
|
|
|
|
import Test.Hspec.Expectations.Pretty
|
2017-05-10 01:49:38 +03:00
|
|
|
import Language
|
2017-04-22 00:10:50 +03:00
|
|
|
import Syntax
|
|
|
|
import Renderer
|
|
|
|
import Source
|
|
|
|
|
|
|
|
spec :: Spec
|
|
|
|
spec = parallel $ do
|
|
|
|
describe "parseBlob" $ do
|
|
|
|
it "parses in the specified language" $ do
|
|
|
|
term <- parseBlob methodsBlob
|
|
|
|
void term `shouldBe` cofree (() :< Indexed [ cofree (() :< Method [] (cofree (() :< Leaf "foo")) Nothing [] []) ])
|
|
|
|
|
|
|
|
it "parses line by line if not given a language" $ do
|
2017-05-10 01:49:38 +03:00
|
|
|
term <- parseBlob 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 "") ])
|
|
|
|
|
|
|
|
describe "parseBlobs" $ do
|
|
|
|
it "renders to ByteString output" $ do
|
|
|
|
output <- parseBlobs (SExpressionParseTreeRenderer TreeOnly) [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
|
|
|
|
|
|
|
where
|
2017-05-10 01:49:38 +03:00
|
|
|
methodsBlob = SourceBlob (Source "def foo\nend\n") "ff7bbbe9495f61d9e1e58c597502d152bab1761e" "methods.rb" (Just defaultPlainBlob) (Just Ruby)
|