2018-03-13 21:10:50 +03:00
|
|
|
module Semantic.Spec (spec) where
|
2017-04-22 00:10:50 +03:00
|
|
|
|
2019-02-12 23:49:34 +03:00
|
|
|
import Semantic.Api hiding (Blob)
|
2019-06-06 05:07:48 +03:00
|
|
|
import Semantic.Git
|
2017-09-29 22:09:58 +03:00
|
|
|
import System.Exit
|
2018-03-13 21:10:50 +03:00
|
|
|
|
|
|
|
import SpecHelpers
|
|
|
|
|
2019-05-22 05:28:32 +03:00
|
|
|
-- we need some lenses here, oof
|
|
|
|
setBlobLanguage :: Language -> Blob -> Blob
|
2019-05-22 05:58:25 +03:00
|
|
|
setBlobLanguage lang b = b { blobFile = (blobFile b) { fileLanguage = lang }}
|
2017-04-22 00:10:50 +03:00
|
|
|
|
|
|
|
spec :: Spec
|
|
|
|
spec = parallel $ do
|
2017-05-31 19:25:40 +03:00
|
|
|
describe "parseBlob" $ do
|
2018-08-30 22:51:29 +03:00
|
|
|
it "returns error if given an unknown language (json)" $ do
|
2019-05-22 05:28:32 +03:00
|
|
|
output <- fmap runBuilder . runTaskOrDie $ parseTermBuilder TermJSONTree [ setBlobLanguage Unknown methodsBlob ]
|
2018-11-13 22:02:23 +03:00
|
|
|
output `shouldBe` "{\"trees\":[{\"path\":\"methods.rb\",\"error\":\"NoLanguageForBlob \\\"methods.rb\\\"\",\"language\":\"Unknown\"}]}\n"
|
2018-08-30 22:51:29 +03:00
|
|
|
|
2018-09-25 22:04:58 +03:00
|
|
|
it "throws if given an unknown language for sexpression output" $ do
|
2019-05-22 05:28:32 +03:00
|
|
|
runTaskOrDie (parseTermBuilder TermSExpression [setBlobLanguage Unknown methodsBlob]) `shouldThrow` (== ExitFailure 1)
|
2017-04-22 00:10:50 +03:00
|
|
|
|
2017-05-30 17:33:48 +03:00
|
|
|
it "renders with the specified renderer" $ do
|
2019-02-02 02:04:23 +03:00
|
|
|
output <- fmap runBuilder . runTaskOrDie $ parseTermBuilder TermSExpression [methodsBlob]
|
2018-06-01 21:44:03 +03:00
|
|
|
output `shouldBe` "(Statements\n (Method\n (Empty)\n (Identifier)\n (Statements)))\n"
|
2019-06-06 05:07:48 +03:00
|
|
|
|
2019-06-07 06:24:22 +03:00
|
|
|
describe "git ls-tree parsing" $ do
|
2019-06-06 05:07:48 +03:00
|
|
|
it "parses a git output string" $ do
|
2019-06-07 06:24:22 +03:00
|
|
|
let input = "100644 tree abcdef\t/this/is/the/path"
|
2019-06-09 23:11:58 +03:00
|
|
|
let expected = Right $ TreeEntry NormalMode TreeObject (OID "abcdef") "/this/is/the/path"
|
2019-06-06 05:07:48 +03:00
|
|
|
parseEntry input `shouldBe` expected
|
|
|
|
|
2019-06-07 06:24:22 +03:00
|
|
|
it "allows whitespace in the path" $ do
|
|
|
|
let input = "100644 tree 12345\t/this\n/is\t/the /path\r"
|
2019-06-09 23:11:58 +03:00
|
|
|
let expected = Right $ TreeEntry NormalMode TreeObject (OID "12345") "/this\n/is\t/the /path\r"
|
2019-06-06 05:07:48 +03:00
|
|
|
parseEntry input `shouldBe` expected
|
|
|
|
|
|
|
|
it "parses many outputs separated by \\NUL" $ do
|
2019-06-07 06:24:22 +03:00
|
|
|
let input = "100644 tree abcdef\t/this/is/the/path\NUL120000 blob 17776\t/dev/urandom\NUL\n"
|
|
|
|
let expected = [ TreeEntry NormalMode TreeObject (OID "abcdef") "/this/is/the/path", TreeEntry SymlinkMode BlobObject (OID "17776") "/dev/urandom"]
|
2019-06-06 05:07:48 +03:00
|
|
|
parseEntries input `shouldBe` expected
|
|
|
|
|
2017-04-22 00:10:50 +03:00
|
|
|
where
|
2019-05-24 18:52:35 +03:00
|
|
|
methodsBlob = makeBlob "def foo\nend\n" "methods.rb" Ruby mempty
|