1
1
mirror of https://github.com/github/semantic.git synced 2024-12-26 08:25:19 +03:00

Add function arg test

This commit is contained in:
joshvera 2020-01-23 11:20:35 -05:00
parent 3a1fdebfae
commit c9eb0cfa76
2 changed files with 25 additions and 1 deletions

View File

@ -11,6 +11,7 @@ import Control.Carrier.Sketch.Fresh
import Control.Monad import Control.Monad
import qualified Data.ByteString as ByteString import qualified Data.ByteString as ByteString
import Data.Name (Name) import Data.Name (Name)
import qualified Data.Name as Name
import qualified Data.ScopeGraph as ScopeGraph import qualified Data.ScopeGraph as ScopeGraph
import qualified Language.Python () import qualified Language.Python ()
import qualified Language.Python as Py (Term) import qualified Language.Python as Py (Term)
@ -91,6 +92,16 @@ expectedLexicalScope = do
reference "foo" "foo" RefProperties {} reference "foo" "foo" RefProperties {}
pure Complete pure Complete
expectedFunctionArg :: (Has Sketch sig m) => m Result
expectedFunctionArg = do
declare "foo" (DeclProperties ScopeGraph.Function ScopeGraph.Default Nothing)
withScope (Name.nameI 0) $ do
declare "x" (DeclProperties ScopeGraph.Identifier ScopeGraph.Default Nothing)
reference "x" "x" RefProperties
pure ()
reference "foo" "foo" RefProperties
pure Complete
assertLexicalScope :: HUnit.Assertion assertLexicalScope :: HUnit.Assertion
assertLexicalScope = do assertLexicalScope = do
let path = "semantic-python/test/fixtures/5-02-simple-function.py" let path = "semantic-python/test/fixtures/5-02-simple-function.py"
@ -99,6 +110,14 @@ assertLexicalScope = do
HUnit.assertEqual "Should work for simple case" expecto graph HUnit.assertEqual "Should work for simple case" expecto graph
assertFunctionArg :: HUnit.Assertion
assertFunctionArg = do
let path = "semantic-python/test/fixtures/5-03-function-argument.py"
(graph, result) <- graphFile path
let (expecto, Complete) = run $ runSketch Nothing expectedFunctionArg
HUnit.assertEqual "Should work for simple case" expecto graph
main :: IO () main :: IO ()
main = do main = do
-- make sure we're in the root directory so the paths resolve properly -- make sure we're in the root directory so the paths resolve properly
@ -115,6 +134,7 @@ main = do
HUnit.testCase "simple reference" assertSimpleReference HUnit.testCase "simple reference" assertSimpleReference
], ],
Tasty.testGroup "lexical scopes" [ Tasty.testGroup "lexical scopes" [
HUnit.testCase "simple scope" assertLexicalScope HUnit.testCase "simple function scope" assertLexicalScope
, HUnit.testCase "simple function argument" assertFunctionArg
] ]
] ]

View File

@ -0,0 +1,4 @@
def foo(x):
return x
foo(1)