From 17c4bf350c6d6a3e45e422e24cfb2c8d337b25e6 Mon Sep 17 00:00:00 2001 From: joshvera Date: Thu, 29 Nov 2018 19:37:20 -0500 Subject: [PATCH] Add lookupObjectMembers function to tests --- test/Analysis/Go/Spec.hs | 2 +- test/Analysis/Python/Spec.hs | 4 ++-- test/Analysis/TypeScript/Spec.hs | 11 ++++++----- test/SpecHelpers.hs | 18 ++++-------------- test/fixtures/typescript/analysis/foo/b.ts | 3 --- 5 files changed, 13 insertions(+), 25 deletions(-) diff --git a/test/Analysis/Go/Spec.hs b/test/Analysis/Go/Spec.hs index 66938ec40..ddd3bf3c2 100644 --- a/test/Analysis/Go/Spec.hs +++ b/test/Analysis/Go/Spec.hs @@ -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 () diff --git a/test/Analysis/Python/Spec.hs b/test/Analysis/Python/Spec.hs index 51ee24214..25fecdfa8 100644 --- a/test/Analysis/Python/Spec.hs +++ b/test/Analysis/Python/Spec.hs @@ -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) diff --git a/test/Analysis/TypeScript/Spec.hs b/test/Analysis/TypeScript/Spec.hs index b28bae23d..143c622b9 100644 --- a/test/Analysis/TypeScript/Spec.hs +++ b/test/Analysis/TypeScript/Spec.hs @@ -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 diff --git a/test/SpecHelpers.hs b/test/SpecHelpers.hs index 1605c3f01..f59ed7742 100644 --- a/test/SpecHelpers.hs +++ b/test/SpecHelpers.hs @@ -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 diff --git a/test/fixtures/typescript/analysis/foo/b.ts b/test/fixtures/typescript/analysis/foo/b.ts index 38d128277..1f604387e 100644 --- a/test/fixtures/typescript/analysis/foo/b.ts +++ b/test/fixtures/typescript/analysis/foo/b.ts @@ -1,8 +1,5 @@ -// import { baz } from "../foo"; function quz() { return "this is the quz function" } export { quz } - -// baz()