1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 17:04:47 +03:00

Add lookupObjectMembers function to tests

This commit is contained in:
joshvera 2018-11-29 19:37:20 -05:00
parent b2bbd0e78c
commit 17c4bf350c
5 changed files with 13 additions and 25 deletions

View File

@ -15,7 +15,7 @@ spec config = parallel $ do
case ModuleTable.lookup "main.go" <$> res of
Right (Just (Module _ (scopeAndFrame, valueRef) :| [])) -> do
() <$ SpecHelpers.lookupDeclaration "foo" scopeAndFrame heap scopeGraph `shouldBe` Just ()
(SpecHelpers.lookupDeclaration "foo" scopeAndFrame heap scopeGraph >>= objectMembers heap scopeGraph . head) `shouldBe` Just ["New"]
SpecHelpers.lookupObjectMembers "foo" scopeAndFrame heap scopeGraph `shouldBe` Just ["New"]
() <$ SpecHelpers.lookupDeclaration "main" scopeAndFrame heap scopeGraph `shouldBe` Just ()
() <$ SpecHelpers.lookupDeclaration "Bar" scopeAndFrame heap scopeGraph `shouldBe` Just ()
() <$ SpecHelpers.lookupDeclaration "Rab" scopeAndFrame heap scopeGraph `shouldBe` Just ()

View File

@ -19,8 +19,8 @@ spec config = parallel $ do
const () <$> SpecHelpers.lookupDeclaration "a" scopeAndFrame heap scopeGraph `shouldBe` Just ()
const () <$> SpecHelpers.lookupDeclaration "b" scopeAndFrame heap scopeGraph `shouldBe` Just ()
fromJust (SpecHelpers.lookupDeclaration "a" scopeAndFrame heap scopeGraph >>= objectMembers heap scopeGraph . head) `shouldContain` [ "foo" ]
fromJust (SpecHelpers.lookupDeclaration "b" scopeAndFrame heap scopeGraph >>= objectMembers heap scopeGraph . head) `shouldContain` ["c"]
fromJust (SpecHelpers.lookupObjectMembers "a" scopeAndFrame heap scopeGraph) `shouldContain` [ "foo" ]
fromJust (SpecHelpers.lookupObjectMembers "b" scopeAndFrame heap scopeGraph) `shouldContain` ["c"]
-- (derefQName heap ("b" :| ["c"]) env >>= deNamespace heap) `shouldBe` Just ("c", ["baz"])
other -> expectationFailure (show other)

View File

@ -38,13 +38,14 @@ spec config = parallel $ do
case ModuleTable.lookup "main1.ts" <$> res of
Right (Just (Module _ (scopeAndFrame, _) :| [])) -> do
-- Env.names env `shouldBe` [ "b", "z" ]
const () <$> SpecHelpers.lookupDeclaration "b" scopeAndFrame heap scopeGraph `shouldBe` Just ()
const () <$> SpecHelpers.lookupDeclaration "z" scopeAndFrame heap scopeGraph `shouldBe` Just ()
() <$ SpecHelpers.lookupDeclaration "b" scopeAndFrame heap scopeGraph `shouldBe` Just ()
() <$ SpecHelpers.lookupDeclaration "z" scopeAndFrame heap scopeGraph `shouldBe` Just ()
lookupObjectMembers "b" scopeAndFrame heap scopeGraph `shouldBe` Just [ "foo", "baz" ]
lookupObjectMembers "z" scopeAndFrame heap scopeGraph `shouldBe` Just [ "foo", "baz" ]
-- (Heap.lookupDeclaration "b" heap >>= deNamespace heap) `shouldBe` Just ("b", [ "baz", "foo" ])
-- (Heap.lookupDeclaration "z" heap >>= deNamespace heap) `shouldBe` Just ("z", [ "baz", "foo" ])
const () <$> SpecHelpers.lookupDeclaration "baz" scopeAndFrame heap scopeGraph `shouldBe` Just ()
const () <$> SpecHelpers.lookupDeclaration "foo" scopeAndFrame heap scopeGraph `shouldBe` Just ()
() <$ SpecHelpers.lookupDeclaration "baz" scopeAndFrame heap scopeGraph `shouldBe` Nothing
() <$ SpecHelpers.lookupDeclaration "foo" scopeAndFrame heap scopeGraph `shouldBe` Nothing
other -> expectationFailure (show other)
it "stores function declaration in scope graph" $ do

View File

@ -15,7 +15,7 @@ module SpecHelpers
, LogQueue
, StatQueue
, lookupDeclaration
, objectMembers
, lookupObjectMembers
) where
import Control.Abstract hiding (lookupDeclaration)
@ -177,19 +177,9 @@ frameNames heap scopeGraph frame = do
scope <- ScopeGraph.lookupScope scopeAddress scopeGraph
pure (unDeclaration <$> ScopeGraph.declarationNames scope scopeGraph)
-- = either (const Nothing) (snd . snd)
-- . run
-- . runFresh
-- . runEvaluator
-- . runAddressError
-- . raiseHandler (runState heap)
-- . raiseHandler (runState (lowerBound @Span))
-- . raiseHandler (runReader (lowerBound @Span))
-- . raiseHandler (runReader (ModuleInfo "SpecHelper.hs"))
-- . runDeref
-- $ undefined
-- namespaceScope _ _ = Nothing
lookupObjectMembers :: Name -> (Precise, Precise) -> Heap Precise Precise (Value term Precise) -> ScopeGraph Precise -> Maybe [ Name ]
lookupObjectMembers name scopeAndFrame heap scopeGraph =
(lookupDeclaration name scopeAndFrame heap scopeGraph >>= objectMembers heap scopeGraph . Prelude.head)
lookupDeclaration :: Name -> (Precise, Precise) -> Heap Precise Precise (Value term Precise) -> ScopeGraph Precise -> Maybe [ Value term Precise ]
lookupDeclaration name (currentScope, currentFrame) heap scopeGraph = do

View File

@ -1,8 +1,5 @@
// import { baz } from "../foo";
function quz() {
return "this is the quz function"
}
export { quz }
// baz()