mirror of
https://github.com/github/semantic.git
synced 2024-11-28 18:23:44 +03:00
More tests
This commit is contained in:
parent
d0fc88efee
commit
bdb7ee0430
@ -126,11 +126,6 @@ descend lang t@(In loc _) = do
|
||||
traverse_ subtermRef t
|
||||
exit (constructorName term) snippetRange
|
||||
|
||||
getRangeOfDecl :: Foldable t => Location -> Term t Location -> Maybe Range
|
||||
getRangeOfDecl ann (Term (In body bodyF))
|
||||
| (Term (In firstEl _):_) <- toList bodyF = Just $ subtractLocation ann firstEl
|
||||
| otherwise = Just $ subtractLocation ann body
|
||||
|
||||
subtractLocation :: Location -> Location -> Range
|
||||
subtractLocation a b = subtractRange (locationByteRange a) (locationByteRange b)
|
||||
|
||||
@ -153,7 +148,7 @@ instance Taggable Declaration.Function where
|
||||
, isTextElement exprF = Just (locationByteRange exprAnn)
|
||||
| otherwise = Nothing
|
||||
docsLiteral _ _ = Nothing
|
||||
snippet ann (Declaration.Function _ _ _ body) = getRangeOfDecl ann body
|
||||
snippet ann (Declaration.Function _ _ _ (Term (In body _))) = Just $ subtractLocation ann body
|
||||
|
||||
instance Taggable Declaration.Method where
|
||||
docsLiteral Python (Declaration.Method _ _ _ _ (Term (In _ bodyF)))
|
||||
@ -161,7 +156,7 @@ instance Taggable Declaration.Method where
|
||||
, isTextElement exprF = Just (locationByteRange exprAnn)
|
||||
| otherwise = Nothing
|
||||
docsLiteral _ _ = Nothing
|
||||
snippet ann (Declaration.Method _ _ _ _ body) = getRangeOfDecl ann body
|
||||
snippet ann (Declaration.Method _ _ _ _ (Term (In body _))) = Just $ subtractLocation ann body
|
||||
|
||||
instance Taggable Declaration.Class where
|
||||
docsLiteral Python (Declaration.Class _ _ _ (Term (In _ bodyF)))
|
||||
@ -169,17 +164,17 @@ instance Taggable Declaration.Class where
|
||||
, isTextElement exprF = Just (locationByteRange exprAnn)
|
||||
| otherwise = Nothing
|
||||
docsLiteral _ _ = Nothing
|
||||
snippet ann (Declaration.Class _ _ _ body) = getRangeOfDecl ann body
|
||||
snippet ann (Declaration.Class _ _ _ (Term (In body _))) = Just $ subtractLocation ann body
|
||||
|
||||
instance Taggable Ruby.Class where
|
||||
snippet ann (Ruby.Class _ _ body) = getRangeOfDecl ann body
|
||||
snippet ann (Ruby.Class _ _ (Term (In body _))) = Just $ subtractLocation ann body
|
||||
|
||||
instance Taggable Ruby.Module where
|
||||
snippet ann (Ruby.Module _ (body:_)) = getRangeOfDecl ann body
|
||||
snippet ann (Ruby.Module _ (Term (In body _):_)) = Just $ subtractLocation ann body
|
||||
snippet ann (Ruby.Module _ _) = Just (locationByteRange ann)
|
||||
|
||||
instance Taggable TypeScript.Module where
|
||||
snippet ann (TypeScript.Module _ (body:_)) = getRangeOfDecl ann body
|
||||
snippet ann (TypeScript.Module _ (Term (In body _):_)) = Just $ subtractLocation ann body
|
||||
snippet ann (TypeScript.Module _ _) = Just (locationByteRange ann)
|
||||
|
||||
instance Taggable []
|
||||
|
@ -6,6 +6,55 @@ import SpecHelpers
|
||||
|
||||
spec :: Spec
|
||||
spec = parallel $ do
|
||||
describe "go" $ do
|
||||
it "produces tags for functions with docs" $ do
|
||||
(blob, tree) <- parseTestFile goParser "test/fixtures/go/tags/simple_functions.go"
|
||||
runTagging blob tree `shouldBe` Right
|
||||
[ Tag "TestFromBits" "Function" (Span (Pos 6 1) (Pos 7 2)) ["Statements"] (Just "func TestFromBits(t *testing.T)") (Just "// TestFromBits ...")
|
||||
, Tag "Hi" "Function" (Span (Pos 9 1) (Pos 10 2)) ["Statements"] (Just "func Hi()") Nothing ]
|
||||
|
||||
it "produces tags for methods" $ do
|
||||
(blob, tree) <- parseTestFile goParser "test/fixtures/go/tags/method.go"
|
||||
runTagging blob tree `shouldBe` Right
|
||||
[ Tag "CheckAuth" "Method" (Span (Pos 3 1) (Pos 3 100)) ["Statements"] (Just "func (c *apiClient) CheckAuth(req *http.Request, user, repo string) (*authenticatedActor, error)") Nothing]
|
||||
|
||||
describe "javascript and typescript" $ do
|
||||
it "produces tags for functions with docs" $ do
|
||||
(blob, tree) <- parseTestFile typescriptParser "test/fixtures/javascript/tags/simple_function_with_docs.js"
|
||||
runTagging blob tree `shouldBe` Right
|
||||
[ Tag "myFunction" "Function" (Span (Pos 2 1) (Pos 4 2)) ["Statements"] (Just "function myFunction()") (Just "// This is myFunction") ]
|
||||
|
||||
it "produces tags for classes" $ do
|
||||
(blob, tree) <- parseTestFile typescriptParser "test/fixtures/typescript/tags/class.ts"
|
||||
runTagging blob tree `shouldBe` Right
|
||||
[ Tag "FooBar" "Class" (Span (Pos 1 1) (Pos 1 16)) ["Statements"] (Just "class FooBar") Nothing ]
|
||||
|
||||
it "produces tags for modules" $ do
|
||||
(blob, tree) <- parseTestFile typescriptParser "test/fixtures/typescript/tags/module.ts"
|
||||
runTagging blob tree `shouldBe` Right
|
||||
[ Tag "APromise" "Module" (Span (Pos 1 1) (Pos 1 20)) ["Statements"] (Just "module APromise { }") Nothing ]
|
||||
|
||||
describe "python" $ do
|
||||
it "produces tags for functions" $ do
|
||||
(blob, tree) <- parseTestFile pythonParser "test/fixtures/python/tags/simple_functions.py"
|
||||
runTagging blob tree `shouldBe` Right
|
||||
[ Tag "Foo" "Function" (Span (Pos 1 1) (Pos 5 17)) ["Statements"] (Just "def Foo(x)") Nothing
|
||||
, Tag "Bar" "Function" (Span (Pos 7 1) (Pos 11 13)) ["Statements"] (Just "def Bar()") Nothing
|
||||
, Tag "local" "Function" (Span (Pos 8 5) (Pos 9 17)) ["Statements", "Function", "Statements"] (Just "def local()") Nothing
|
||||
]
|
||||
|
||||
it "produces tags for functions with docs" $ do
|
||||
(blob, tree) <- parseTestFile pythonParser "test/fixtures/python/tags/simple_function_with_docs.py"
|
||||
runTagging blob tree `shouldBe` Right
|
||||
[ Tag "Foo" "Function" (Span (Pos 1 1) (Pos 3 13)) ["Statements"] (Just "def Foo(x)") (Just "\"\"\"This is the foo function\"\"\"") ]
|
||||
|
||||
it "produces tags for classes" $ do
|
||||
(blob, tree) <- parseTestFile pythonParser "test/fixtures/python/tags/class.py"
|
||||
runTagging blob tree `shouldBe` Right
|
||||
[ Tag "Foo" "Class" (Span (Pos 1 1) (Pos 5 17)) ["Statements"] (Just "class Foo") (Just "\"\"\"The Foo class\"\"\"")
|
||||
, Tag "f" "Function" (Span (Pos 3 5) (Pos 5 17)) ["Statements", "Class", "Statements"] (Just "def f(self)") (Just "\"\"\"The f method\"\"\"")
|
||||
]
|
||||
|
||||
describe "ruby" $ do
|
||||
it "produces tags for methods" $ do
|
||||
(blob, tree) <- parseTestFile rubyParser "test/fixtures/ruby/tags/simple_method.rb"
|
||||
@ -24,24 +73,3 @@ spec = parallel $ do
|
||||
, Tag "Bar" "Class" (Span (Pos 5 3 ) (Pos 11 6)) ["Module", "Context", "Statements"] (Just "class Bar") (Just "# Public: Bar")
|
||||
, Tag "baz" "Method" (Span (Pos 8 5 ) (Pos 10 8)) ["Class", "Context", "Module", "Context", "Statements"] (Just "def baz(a)") (Just "# Public: baz")
|
||||
]
|
||||
|
||||
describe "python" $ do
|
||||
it "produces tags for functions" $ do
|
||||
(blob, tree) <- parseTestFile pythonParser "test/fixtures/python/tags/simple_functions.py"
|
||||
runTagging blob tree `shouldBe` Right
|
||||
[ Tag "Foo" "Function" (Span (Pos 1 1) (Pos 5 17)) ["Statements"] (Just "def Foo(x):") Nothing
|
||||
, Tag "Bar" "Function" (Span (Pos 7 1) (Pos 11 13)) ["Statements"] (Just "def Bar():") Nothing
|
||||
, Tag "local" "Function" (Span (Pos 8 5) (Pos 9 17)) ["Statements", "Function", "Statements"] (Just "def local():") Nothing
|
||||
]
|
||||
|
||||
it "produces tags for functions with docs" $ do
|
||||
(blob, tree) <- parseTestFile pythonParser "test/fixtures/python/tags/simple_function_with_docs.py"
|
||||
runTagging blob tree `shouldBe` Right
|
||||
[ Tag "Foo" "Function" (Span (Pos 1 1) (Pos 3 13)) ["Statements"] (Just "def Foo(x):") (Just "\"\"\"This is the foo function\"\"\"") ]
|
||||
|
||||
it "produces tags for classes" $ do
|
||||
(blob, tree) <- parseTestFile pythonParser "test/fixtures/python/tags/class.py"
|
||||
runTagging blob tree `shouldBe` Right
|
||||
[ Tag "Foo" "Class" (Span (Pos 1 1) (Pos 5 17)) ["Statements"] (Just "class Foo:") (Just "\"\"\"The Foo class\"\"\"")
|
||||
, Tag "f" "Function" (Span (Pos 3 5) (Pos 5 17)) ["Statements", "Class", "Statements"] (Just "def f(self):") (Just "\"\"\"The f method\"\"\"")
|
||||
]
|
||||
|
3
test/fixtures/go/tags/method.go
vendored
Normal file
3
test/fixtures/go/tags/method.go
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import "net/http"
|
||||
|
||||
func (c *apiClient) CheckAuth(req *http.Request, user, repo string) (*authenticatedActor, error) {}
|
10
test/fixtures/go/tags/simple_functions.go
vendored
Normal file
10
test/fixtures/go/tags/simple_functions.go
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
package big
|
||||
|
||||
import "testing"
|
||||
|
||||
// TestFromBits ...
|
||||
func TestFromBits(t *testing.T) {
|
||||
}
|
||||
|
||||
func Hi() {
|
||||
}
|
4
test/fixtures/javascript/tags/simple_function_with_docs.js
vendored
Normal file
4
test/fixtures/javascript/tags/simple_function_with_docs.js
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
// This is myFunction
|
||||
function myFunction() {
|
||||
return 0;
|
||||
}
|
1
test/fixtures/typescript/tags/class.ts
vendored
Normal file
1
test/fixtures/typescript/tags/class.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
class FooBar {}
|
1
test/fixtures/typescript/tags/module.ts
vendored
Normal file
1
test/fixtures/typescript/tags/module.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
module APromise { }
|
Loading…
Reference in New Issue
Block a user