1
1
mirror of https://github.com/github/semantic.git synced 2024-11-22 23:29:37 +03:00

Fix the specs!

This commit is contained in:
Patrick Thomson 2020-06-27 13:33:56 -04:00
parent a6ab4c4d25
commit 335c3f728d
5 changed files with 26 additions and 19 deletions

View File

@ -41,7 +41,7 @@ load(
)
load(
"@bazel_tools//tools/build_defs/repo:git.bzl",
"git_repository",
"new_git_repository",
)
stack_snapshot(
@ -157,10 +157,17 @@ tree_sitter_node_types_archive(
version = "0.16.0",
)
tree_sitter_node_types_archive(
# TODO: the versioning here is messed up so we have to pin from git.
# We should fix this (and see why the tags are breaking).
new_git_repository(
name = "tree-sitter-ruby",
sha256 = "1a63b43f82837a1194cab997475a22f82bfd820dd32999aa1444cfeae70f7596",
version = "0.16.2",
build_file_content = """
exports_files(["src/node-types.json"])
""",
commit = "eb2b6225bfb80010f2e4cbd27db8c6f3775230b5",
remote = "https://github.com/tree-sitter/tree-sitter-ruby.git",
shallow_since = "1576688803 -0800",
)
tree_sitter_node_types_archive(

View File

@ -213,7 +213,7 @@ instance ToTags Rb.Lambda where
instance ToTags Rb.If where
tags Rb.If {condition = Parse.Success cond, consequence, alternative} = do
tags cond
case consequence of
case consequence of
Just (Parse.Success cons) -> tags cons
_ -> pure ()
case alternative of
@ -224,7 +224,7 @@ instance ToTags Rb.If where
instance ToTags Rb.Elsif where
tags Rb.Elsif {condition = Parse.Success cond, consequence, alternative} = do
tags cond
case consequence of
case consequence of
Just (Parse.Success cons) -> tags cons
_ -> pure ()
case alternative of
@ -235,7 +235,7 @@ instance ToTags Rb.Elsif where
instance ToTags Rb.Unless where
tags Rb.Unless {condition = Parse.Success cond, consequence, alternative} = do
tags cond
case consequence of
case consequence of
Just (Parse.Success cons) -> tags cons
_ -> pure ()
case alternative of
@ -264,7 +264,7 @@ instance ToTags Rb.Lhs where
Prj Rb.Call {ann = Loc {byteRange}, method} -> case method of
EPrj Rb.Identifier {text, ann} -> yieldCall text ann byteRange
EPrj Rb.Constant {text, ann} -> yieldCall text ann byteRange
EPrj Rb.Operator {text, ann} -> yieldCall text ann byteRange
EPrj Rb.Operator {text, ann} -> yieldCall text ann byteRangeg
_ -> gtags t
-- These do check for locals before yielding a call tag
Prj (Rb.Variable (Prj Rb.Identifier {ann = loc@Loc {byteRange}, text})) -> yield text P.CALL loc byteRange

View File

@ -142,6 +142,7 @@ haskell_test(
"test/fixtures/ruby/**/*.rb",
"test/fixtures/javascript/**/*.js",
"test/fixtures/typescript/**/*.ts",
"test/fixtures/cli/*.json",
]),
deps = semantic_common_dependencies + [
"//:base",

View File

@ -33,12 +33,12 @@ testTree = testGroup "Semantic.CLI"
renderDiff :: String -> String -> [String]
renderDiff ref new = unsafePerformIO $ do
let check p = do
exists <- Path.doesFileExist (Path.absFile p)
exists <- Path.doesFileExist (Path.absRel p)
unless exists (throwIO (userError ("Can't find path " <> p)))
check ref
check new
useJD <- (Path.hasExtension ".json" (Path.absPath ref) &&) <$> fmap isJust (Path.findExecutable "jd")
useJD <- (Path.hasExtension ".json" (Path.absRel ref) &&) <$> fmap isJust (Path.findExecutable "jd")
pure $ if useJD
then ["jd", "-set", ref, new]
else ["diff", ref, new]
@ -56,10 +56,9 @@ testForParseFixture (format, runParse, files, expected) =
parseFixtures :: [(String, [Blob] -> ParseC TaskC Builder, [File Language], Path.RelFile)]
parseFixtures =
[ ("s-expression", run . parseTermBuilder TermSExpression, path, Path.relFile "semantic/test/fixtures/ruby/corpus/and-or.parseA.txt")
, ("symbols", run . parseSymbolsBuilder Serializing.Format.JSON, path'', prefix </> Path.file "parse-tree.symbols.json")
, ("protobuf symbols", run . parseSymbolsBuilder Serializing.Format.Proto, path'', prefix </> Path.file "parse-tree.symbols.protobuf.bin")
, ("symbols", run . parseSymbolsBuilder Serializing.Format.JSON, path'', Path.relFile "semantic/test/fixtures/cli/parse-tree.symbols.json")
, ("protobuf symbols", run . parseSymbolsBuilder Serializing.Format.Proto, path'', Path.relFile "semantic/test/fixtures/cli/parse-tree.symbols.protobuf.bin")
]
where path = [File (Path.absRel "semantic/test/fixtures/ruby/corpus/and-or.A.rb") lowerBound Ruby]
path'' = [File (Path.absRel "semantic/test/fixtures/ruby/corpus/method-declaration.A.rb") lowerBound Ruby]
prefix = Path.relDir "semantic/test/fixtures/cli"
run = runReader defaultLanguageModes

View File

@ -32,23 +32,23 @@ spec = do
let a = Blob.fromSource (Path.relFile "method.rb") Ruby "def foo; end"
let b = Blob.fromSource (Path.relFile "method.rb") Ruby "def bar(x); end"
it "returns blobs for valid JSON encoded diff input" $ do
blobs <- blobsFromFilePath "semantic/test/fixtures/cli/diff.json"
blobs <- blobsFromFilePath "test/fixtures/cli/diff.json"
blobs `shouldBe` [Compare a b]
it "returns blobs when there's no before" $ do
blobs <- blobsFromFilePath "semantic/test/fixtures/cli/diff-no-before.json"
blobs <- blobsFromFilePath "test/fixtures/cli/diff-no-before.json"
blobs `shouldBe` [Insert b]
it "returns blobs when there's null before" $ do
blobs <- blobsFromFilePath "semantic/test/fixtures/cli/diff-null-before.json"
blobs <- blobsFromFilePath "test/fixtures/cli/diff-null-before.json"
blobs `shouldBe` [Insert b]
it "returns blobs when there's no after" $ do
blobs <- blobsFromFilePath "semantic/test/fixtures/cli/diff-no-after.json"
blobs <- blobsFromFilePath "test/fixtures/cli/diff-no-after.json"
blobs `shouldBe` [Delete a]
it "returns blobs when there's null after" $ do
blobs <- blobsFromFilePath "semantic/test/fixtures/cli/diff-null-after.json"
blobs <- blobsFromFilePath "test/fixtures/cli/diff-null-after.json"
blobs `shouldBe` [Delete a]
@ -59,7 +59,7 @@ spec = do
blobs `shouldBe` [Insert b']
it "detects language based on filepath for empty language" $ do
blobs <- blobsFromFilePath "semantic/test/fixtures/cli/diff-empty-language.json"
blobs <- blobsFromFilePath "test/fixtures/cli/diff-empty-language.json"
blobs `shouldBe` [Compare a b]
it "throws on blank input" $ do