1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 00:42:33 +03:00

Change the signature of Blob.sourceBlob.

This commit is contained in:
Patrick Thomson 2020-01-24 16:07:04 -05:00
parent 801edb8db0
commit 4be80fecef
4 changed files with 8 additions and 7 deletions

View File

@ -44,6 +44,7 @@ import Source.Source (Source, totalSpan)
import qualified Source.Source as Source
import qualified System.FilePath as FP
import qualified System.Path as Path
import qualified System.Path.PartClass as Path.PartClass
type File = Analysis.File.File Language
@ -65,7 +66,7 @@ newtype Blobs a = Blobs { blobs :: [a] }
instance FromJSON Blob where
parseJSON = withObject "Blob" $ \b -> do
src <- b .: "content"
Right pth <- Path.parse <$> (b .: "path")
Right pth <- fmap Path.parse (b .: "path")
lang <- b .: "language"
let lang' = if knownLanguage lang then lang else Language.forPath pth
pure (Blob src (Analysis.File.File pth (totalSpan src) lang'))
@ -73,9 +74,9 @@ instance FromJSON Blob where
nullBlob :: Blob -> Bool
nullBlob Blob{..} = Source.null blobSource
sourceBlob :: FilePath -> Language -> Source -> Blob
sourceBlob :: Path.PartClass.AbsRel ar => Path.File ar -> Language -> Source -> Blob
sourceBlob filepath language source
= Blob source (Analysis.File.File (Path.absRel filepath) (totalSpan source) language)
= Blob source (Analysis.File.File (Path.toAbsRel filepath) (totalSpan source) language)
decodeBlobs :: BL.ByteString -> Either String [Blob]
decodeBlobs = fmap blobs <$> eitherDecode

View File

@ -15,7 +15,7 @@ spec :: Spec
spec = do
describe "parseToAST" $ do
let source = toJSONSource [1 :: Int .. 10000]
let largeBlob = sourceBlob "large.json" JSON source
let largeBlob = sourceBlob (Path.relFile "large.json") JSON source
it "returns a result when the timeout does not expire" $ do
let timeout = fromMicroseconds 0 -- Zero microseconds indicates no timeout

View File

@ -21,8 +21,8 @@ spec = do
readBlobFromFile (File (Path.absRel "/dev/doesnotexist") lowerBound Unknown) `shouldThrow` anyIOException
describe "readBlobPairsFromHandle" $ do
let a = sourceBlob "method.rb" Ruby "def foo; end"
let b = sourceBlob "method.rb" Ruby "def bar(x); end"
let a = sourceBlob (Path.relFile "method.rb") Ruby "def foo; end"
let b = sourceBlob (Path.relFile "method.rb") Ruby "def bar(x); end"
it "returns blobs for valid JSON encoded diff input" $ do
blobs <- blobsFromFilePath "test/fixtures/cli/diff.json"
blobs `shouldBe` [Compare a b]

View File

@ -17,7 +17,7 @@ setBlobLanguage lang b = b { blobFile = (blobFile b) { fileBody = lang }}
spec :: Spec
spec = do
describe "parseBlob" $ do
let methodsBlob = sourceBlob "methods.rb" Ruby "def foo\nend\n"
let methodsBlob = sourceBlob (Path.relFile "methods.rb") Ruby "def foo\nend\n"
it "returns error if given an unknown language (json)" $ do
output <- fmap runBuilder . runTaskOrDie . runReader defaultLanguageModes $ parseTermBuilder TermJSONTree [ setBlobLanguage Unknown methodsBlob ]