mirror of
https://github.com/github/semantic.git
synced 2024-11-28 01:47:01 +03:00
Use isJust where applicable
This commit is contained in:
parent
915937c4be
commit
ade8e8b265
@ -14,19 +14,19 @@ spec = parallel $ do
|
||||
(scopeGraph, (heap, res)) <- evaluate ["main.go", "foo/foo.go", "bar/bar.go", "bar/rab.go"]
|
||||
case ModuleTable.lookup "main.go" <$> res of
|
||||
Right (Just (Module _ (scopeAndFrame, _))) -> do
|
||||
() <$ SpecHelpers.lookupDeclaration "foo" scopeAndFrame heap scopeGraph `shouldBe` Just ()
|
||||
SpecHelpers.lookupDeclaration "foo" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
SpecHelpers.lookupMembers "foo" Import 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 ()
|
||||
SpecHelpers.lookupDeclaration "main" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
SpecHelpers.lookupDeclaration "Bar" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
SpecHelpers.lookupDeclaration "Rab" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
other -> expectationFailure (show other)
|
||||
|
||||
it "imports with aliases (and side effects only)" $ do
|
||||
(scopeGraph, (heap, res)) <- evaluate ["main1.go", "foo/foo.go", "bar/bar.go", "bar/rab.go"]
|
||||
case ModuleTable.lookup "main1.go" <$> res of
|
||||
Right (Just (Module _ (scopeAndFrame, _))) -> do
|
||||
() <$ SpecHelpers.lookupDeclaration "f" scopeAndFrame heap scopeGraph `shouldBe` Just ()
|
||||
() <$ SpecHelpers.lookupDeclaration "main" scopeAndFrame heap scopeGraph `shouldBe` Just ()
|
||||
SpecHelpers.lookupDeclaration "f" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
SpecHelpers.lookupDeclaration "main" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
-- (lookupDeclaration "f" heap >>= deNamespace heap) `shouldBe` Just ("f", ["New"])
|
||||
other -> expectationFailure (show other)
|
||||
|
||||
|
@ -16,8 +16,8 @@ spec = parallel $ do
|
||||
case ModuleTable.lookup "main.php" <$> res of
|
||||
Right (Just (Module _ (scopeAndFrame, value))) -> do
|
||||
value `shouldBe` Value.Unit
|
||||
() <$ SpecHelpers.lookupDeclaration "bar" scopeAndFrame heap scopeGraph `shouldBe` Just ()
|
||||
() <$ SpecHelpers.lookupDeclaration "foo" scopeAndFrame heap scopeGraph `shouldBe` Just ()
|
||||
SpecHelpers.lookupDeclaration "bar" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
SpecHelpers.lookupDeclaration "foo" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
other -> expectationFailure (show other)
|
||||
|
||||
xit "evaluates include_once and require_once" $ do
|
||||
@ -25,16 +25,16 @@ spec = parallel $ do
|
||||
case ModuleTable.lookup "main_once.php" <$> res of
|
||||
Right (Just (Module _ (scopeAndFrame, value))) -> do
|
||||
value `shouldBe` Value.Unit
|
||||
() <$ SpecHelpers.lookupDeclaration "bar" scopeAndFrame heap scopeGraph `shouldBe` Just ()
|
||||
() <$ SpecHelpers.lookupDeclaration "foo" scopeAndFrame heap scopeGraph `shouldBe` Just ()
|
||||
SpecHelpers.lookupDeclaration "bar" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
SpecHelpers.lookupDeclaration "foo" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
other -> expectationFailure (show other)
|
||||
|
||||
xit "evaluates namespaces" $ do
|
||||
(scopeGraph, (heap, res)) <- evaluate ["namespaces.php"]
|
||||
case ModuleTable.lookup "namespaces.php" <$> res of
|
||||
Right (Just (Module _ (scopeAndFrame, _))) -> do
|
||||
() <$ SpecHelpers.lookupDeclaration "Foo" scopeAndFrame heap scopeGraph `shouldBe` Just ()
|
||||
() <$ SpecHelpers.lookupDeclaration "NS1" scopeAndFrame heap scopeGraph `shouldBe` Just ()
|
||||
SpecHelpers.lookupDeclaration "Foo" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
SpecHelpers.lookupDeclaration "NS1" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
|
||||
undefined
|
||||
-- (derefQName heap ("NS1" :| []) env >>= deNamespace heap) `shouldBe` Just ("NS1", ["Sub1", "b", "c"])
|
||||
|
@ -16,8 +16,8 @@ spec = parallel $ do
|
||||
(scopeGraph, (heap, res)) <- evaluate ["main.py", "a.py", "b/__init__.py", "b/c.py"]
|
||||
case ModuleTable.lookup "main.py" <$> res of
|
||||
Right (Just (Module _ (scopeAndFrame, _))) -> do
|
||||
() <$ SpecHelpers.lookupDeclaration "a" scopeAndFrame heap scopeGraph `shouldBe` Just ()
|
||||
() <$ SpecHelpers.lookupDeclaration "b" scopeAndFrame heap scopeGraph `shouldBe` Just ()
|
||||
SpecHelpers.lookupDeclaration "a" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
SpecHelpers.lookupDeclaration "b" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
|
||||
fromJust (SpecHelpers.lookupMembers "a" Import scopeAndFrame heap scopeGraph) `shouldContain` [ "foo" ]
|
||||
fromJust (SpecHelpers.lookupMembers "b" Import scopeAndFrame heap scopeGraph) `shouldContain` ["c"]
|
||||
@ -28,16 +28,16 @@ spec = parallel $ do
|
||||
(scopeGraph, (heap, res)) <- evaluate ["main1.py", "a.py", "b/__init__.py", "b/c.py"]
|
||||
case ModuleTable.lookup "main1.py" <$> res of
|
||||
Right (Just (Module _ (scopeAndFrame, _))) -> do
|
||||
() <$ SpecHelpers.lookupDeclaration "b" scopeAndFrame heap scopeGraph `shouldBe` Just ()
|
||||
() <$ SpecHelpers.lookupDeclaration "e" scopeAndFrame heap scopeGraph `shouldBe` Just ()
|
||||
SpecHelpers.lookupDeclaration "b" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
SpecHelpers.lookupDeclaration "e" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
other -> expectationFailure (show other)
|
||||
|
||||
it "imports using from syntax" $ do
|
||||
(scopeGraph, (heap, res)) <- evaluate ["main2.py", "a.py", "b/__init__.py", "b/c.py"]
|
||||
case ModuleTable.lookup "main2.py" <$> res of
|
||||
Right (Just (Module _ (scopeAndFrame, _))) -> do
|
||||
() <$ SpecHelpers.lookupDeclaration "bar" scopeAndFrame heap scopeGraph `shouldBe` Just ()
|
||||
() <$ SpecHelpers.lookupDeclaration "foo" scopeAndFrame heap scopeGraph `shouldBe` Just ()
|
||||
SpecHelpers.lookupDeclaration "bar" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
SpecHelpers.lookupDeclaration "foo" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
|
||||
-- TODO: Enable when we constrain edge paths with path predicates
|
||||
-- () <$ SpecHelpers.lookupDeclaration "baz" heap scopeGraph `shouldBe` Nothing
|
||||
@ -47,7 +47,7 @@ spec = parallel $ do
|
||||
(scopeGraph, (heap, res)) <- evaluate ["main3.py", "c/__init__.py", "c/utils.py"]
|
||||
case ModuleTable.lookup "main3.py" <$> res of
|
||||
Right (Just (Module _ (scopeAndFrame, _))) -> do
|
||||
() <$ SpecHelpers.lookupDeclaration "utils" scopeAndFrame heap scopeGraph `shouldBe` Just ()
|
||||
SpecHelpers.lookupDeclaration "utils" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
-- (lookupDeclaration "utils" heap >>= deNamespace heap) `shouldBe` Just ("utils", ["to_s"])
|
||||
other -> expectationFailure (show other)
|
||||
|
||||
@ -55,8 +55,8 @@ spec = parallel $ do
|
||||
(scopeGraph, (heap, res)) <- evaluate ["subclass.py"]
|
||||
case ModuleTable.lookup "subclass.py" <$> res of
|
||||
Right (Just (Module _ (scopeAndFrame, value))) -> do
|
||||
() <$ SpecHelpers.lookupDeclaration "Foo" scopeAndFrame heap scopeGraph `shouldBe` Just ()
|
||||
() <$ SpecHelpers.lookupDeclaration "Bar" scopeAndFrame heap scopeGraph `shouldBe` Just ()
|
||||
SpecHelpers.lookupDeclaration "Foo" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
SpecHelpers.lookupDeclaration "Bar" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
SpecHelpers.lookupMembers "Bar" Superclass scopeAndFrame heap scopeGraph `shouldBe` Just [ "dang" ]
|
||||
value `shouldBe` String "\"bar\""
|
||||
other -> expectationFailure (show other)
|
||||
|
@ -22,7 +22,7 @@ spec = parallel $ do
|
||||
case ModuleTable.lookup "main.rb" <$> res of
|
||||
Right (Just (Module _ (scopeAndFrame, value))) -> do
|
||||
value `shouldBe` Value.Integer (Number.Integer 1)
|
||||
() <$ SpecHelpers.lookupDeclaration "foo" scopeAndFrame heap scopeGraph `shouldBe` Just ()
|
||||
SpecHelpers.lookupDeclaration "foo" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
other -> expectationFailure (show other)
|
||||
|
||||
it "evaluates load" $ do
|
||||
@ -30,7 +30,7 @@ spec = parallel $ do
|
||||
case ModuleTable.lookup "load.rb" <$> res of
|
||||
Right (Just (Module _ (scopeAndFrame, value))) -> do
|
||||
value `shouldBe` Value.Integer (Number.Integer 1)
|
||||
() <$ SpecHelpers.lookupDeclaration "foo" scopeAndFrame heap scopeGraph `shouldBe` Just ()
|
||||
SpecHelpers.lookupDeclaration "foo" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
other -> expectationFailure (show other)
|
||||
|
||||
it "evaluates load with wrapper" $ do
|
||||
@ -42,8 +42,8 @@ spec = parallel $ do
|
||||
case ModuleTable.lookup "subclass.rb" <$> res of
|
||||
Right (Just (Module _ (scopeAndFrame, value))) -> do
|
||||
value `shouldBe` String "\"<bar>\""
|
||||
() <$ SpecHelpers.lookupDeclaration "Bar" scopeAndFrame heap scopeGraph `shouldBe` Just ()
|
||||
() <$ SpecHelpers.lookupDeclaration "Foo" scopeAndFrame heap scopeGraph `shouldBe` Just ()
|
||||
SpecHelpers.lookupDeclaration "Bar" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
SpecHelpers.lookupDeclaration "Foo" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
SpecHelpers.lookupMembers "Bar" Superclass scopeAndFrame heap scopeGraph `shouldBe` Just ["baz", "foo", "inspect"]
|
||||
other -> expectationFailure (show other)
|
||||
|
||||
@ -51,7 +51,7 @@ spec = parallel $ do
|
||||
(scopeGraph, (heap, res)) <- evaluate ["modules.rb"]
|
||||
case ModuleTable.lookup "modules.rb" <$> res of
|
||||
Right (Just (Module _ (scopeAndFrame, _))) -> do
|
||||
() <$ SpecHelpers.lookupDeclaration "Bar" scopeAndFrame heap scopeGraph `shouldBe` Just ()
|
||||
SpecHelpers.lookupDeclaration "Bar" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
other -> expectationFailure (show other)
|
||||
|
||||
it "handles break correctly" $ do
|
||||
@ -95,7 +95,7 @@ spec = parallel $ do
|
||||
case ModuleTable.lookup "puts.rb" <$> res of
|
||||
Right (Just (Module _ (scopeAndFrame, value))) -> do
|
||||
value `shouldBe` Unit
|
||||
() <$ SpecHelpers.lookupDeclaration "puts" scopeAndFrame heap scopeGraph `shouldBe` Just ()
|
||||
SpecHelpers.lookupDeclaration "puts" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
other -> expectationFailure (show other)
|
||||
|
||||
where
|
||||
|
@ -29,15 +29,15 @@ spec = parallel $ do
|
||||
(scopeGraph, (heap, res)) <- evaluate ["main6.ts", "baz.ts", "foo.ts"]
|
||||
case ModuleTable.lookup "main6.ts" <$> res of
|
||||
Right (Just (Module _ (scopeAndFrame, _))) -> do
|
||||
() <$ SpecHelpers.lookupDeclaration "foo" scopeAndFrame heap scopeGraph `shouldBe` Just ()
|
||||
SpecHelpers.lookupDeclaration "foo" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
other -> expectationFailure (show other)
|
||||
|
||||
it "imports with aliased symbols" $ do
|
||||
(scopeGraph, (heap, res)) <- evaluate ["main.ts", "foo.ts", "foo/b.ts"]
|
||||
case ModuleTable.lookup "main.ts" <$> res of
|
||||
Right (Just (Module _ (scopeAndFrame, _))) -> do
|
||||
() <$ SpecHelpers.lookupDeclaration "bar" scopeAndFrame heap scopeGraph `shouldBe` Just ()
|
||||
() <$ SpecHelpers.lookupDeclaration "quz" scopeAndFrame heap scopeGraph `shouldBe` Just ()
|
||||
SpecHelpers.lookupDeclaration "bar" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
SpecHelpers.lookupDeclaration "quz" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
|
||||
other -> expectationFailure (show other)
|
||||
|
||||
@ -45,21 +45,21 @@ spec = parallel $ do
|
||||
(scopeGraph, (heap, res)) <- evaluate ["main1.ts", "foo.ts", "a.ts"]
|
||||
case ModuleTable.lookup "main1.ts" <$> res of
|
||||
Right (Just (Module _ (scopeAndFrame, _))) -> do
|
||||
() <$ SpecHelpers.lookupDeclaration "b" scopeAndFrame heap scopeGraph `shouldBe` Just ()
|
||||
() <$ SpecHelpers.lookupDeclaration "z" scopeAndFrame heap scopeGraph `shouldBe` Just ()
|
||||
SpecHelpers.lookupDeclaration "b" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
SpecHelpers.lookupDeclaration "z" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
|
||||
lookupMembers "b" Import scopeAndFrame heap scopeGraph `shouldBe` Just [ "baz", "foo" ]
|
||||
lookupMembers "z" Import scopeAndFrame heap scopeGraph `shouldBe` Just [ "baz", "foo" ]
|
||||
|
||||
() <$ SpecHelpers.lookupDeclaration "baz" scopeAndFrame heap scopeGraph `shouldBe` Nothing
|
||||
() <$ SpecHelpers.lookupDeclaration "foo" scopeAndFrame heap scopeGraph `shouldBe` Nothing
|
||||
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
|
||||
(scopeGraph, (heap, res)) <- evaluate ["a.ts"]
|
||||
case ModuleTable.lookup "a.ts" <$> res of
|
||||
Right (Just (Module _ (scopeAndFrame, value))) -> do
|
||||
() <$ SpecHelpers.lookupDeclaration "baz" scopeAndFrame heap scopeGraph `shouldBe` Just ()
|
||||
SpecHelpers.lookupDeclaration "baz" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
value `shouldBe` Unit
|
||||
other -> expectationFailure (show other)
|
||||
|
||||
@ -67,7 +67,7 @@ spec = parallel $ do
|
||||
(scopeGraph, (heap, res)) <- evaluate ["main4.ts", "foo.ts"]
|
||||
case ModuleTable.lookup "main4.ts" <$> res of
|
||||
Right (Just (Module _ (scopeAndFrame, value))) -> do
|
||||
() <$ SpecHelpers.lookupDeclaration "foo" scopeAndFrame heap scopeGraph `shouldBe` Just ()
|
||||
SpecHelpers.lookupDeclaration "foo" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
value `shouldBe` String (pack "\"this is the foo function\"")
|
||||
other -> expectationFailure (show other)
|
||||
|
||||
@ -75,7 +75,7 @@ spec = parallel $ do
|
||||
(scopeGraph, (heap, res)) <- evaluate ["main3.ts", "a.ts"]
|
||||
case ModuleTable.lookup "main3.ts" <$> res of
|
||||
Right (Just (Module _ (scopeAndFrame, value))) -> do
|
||||
() <$ SpecHelpers.lookupDeclaration "baz" scopeAndFrame heap scopeGraph `shouldBe` Nothing
|
||||
SpecHelpers.lookupDeclaration "baz" scopeAndFrame heap scopeGraph `shouldBe` Nothing
|
||||
value `shouldBe` Unit
|
||||
Heap.heapSize heap `shouldBe` 4
|
||||
other -> expectationFailure (show other)
|
||||
@ -88,7 +88,7 @@ spec = parallel $ do
|
||||
(scopeGraph, (heap, res)) <- evaluate ["early-return.ts"]
|
||||
case ModuleTable.lookup "early-return.ts" <$> res of
|
||||
Right (Just (Module _ (scopeAndFrame, _))) ->
|
||||
() <$ SpecHelpers.lookupDeclaration "foo" scopeAndFrame heap scopeGraph `shouldBe` Just ()
|
||||
SpecHelpers.lookupDeclaration "foo" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
other -> expectationFailure (show other)
|
||||
|
||||
it "evaluates sequence expressions" $ do
|
||||
@ -117,7 +117,7 @@ spec = parallel $ do
|
||||
case ModuleTable.lookup "await.ts" <$> res of
|
||||
Right (Just (Module _ (scopeAndFrame, _))) -> do
|
||||
-- Test that f2 is in the scopegraph and heap.
|
||||
() <$ SpecHelpers.lookupDeclaration "f2" scopeAndFrame heap scopeGraph `shouldBe` Just ()
|
||||
SpecHelpers.lookupDeclaration "f2" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
||||
-- Test we can't reference y from outside the function
|
||||
SpecHelpers.lookupDeclaration "y" scopeAndFrame heap scopeGraph `shouldBe` Nothing
|
||||
other -> expectationFailure (show other)
|
||||
|
Loading…
Reference in New Issue
Block a user