mirror of
https://github.com/github/semantic.git
synced 2024-11-24 08:54:07 +03:00
Test Python environments/heaps without encoding addresses.
This commit is contained in:
parent
9ec588ed3c
commit
69bd2c0af5
@ -1,6 +1,7 @@
|
||||
{-# LANGUAGE OverloadedLists, OverloadedStrings #-}
|
||||
module Analysis.Python.Spec (spec) where
|
||||
|
||||
import Data.Abstract.Environment as Env
|
||||
import Data.Abstract.Evaluatable (EvalError(..))
|
||||
import Data.Abstract.Value
|
||||
import Data.Map
|
||||
@ -15,28 +16,19 @@ spec = parallel $ do
|
||||
describe "evaluates Python" $ do
|
||||
it "imports" $ do
|
||||
res <- snd <$> evaluate "main.py"
|
||||
environment res `shouldBe` [ ("print", addr 0)
|
||||
, ("a", addr 1)
|
||||
, ("b", addr 3)
|
||||
]
|
||||
Env.names (environment res) `shouldBe` [ "a", "b", "print" ]
|
||||
|
||||
heapLookup (Address (Precise 1)) (heap res) `shouldBe` ns "a" [ ("foo", addr 2) ]
|
||||
heapLookup (Address (Precise 3)) (heap res) `shouldBe` ns "b" [ ("c", addr 4) ]
|
||||
heapLookup (Address (Precise 4)) (heap res) `shouldBe` ns "c" [ ("baz", addr 5) ]
|
||||
(derefQName (heap res) ("a" :| []) (environment res) >>= deNamespace) `shouldBe` Just ("a", ["foo"])
|
||||
(derefQName (heap res) ("b" :| []) (environment res) >>= deNamespace) `shouldBe` Just ("b", ["c"])
|
||||
(derefQName (heap res) ("b" :| ["c"]) (environment res) >>= deNamespace) `shouldBe` Just ("c", ["baz"])
|
||||
|
||||
it "imports with aliases" $ do
|
||||
env <- environment . snd <$> evaluate "main1.py"
|
||||
env `shouldBe` [ ("print", addr 0)
|
||||
, ("b", addr 1)
|
||||
, ("e", addr 3)
|
||||
]
|
||||
Env.names env `shouldBe` [ "b", "e", "print" ]
|
||||
|
||||
it "imports using 'from' syntax" $ do
|
||||
env <- environment . snd <$> evaluate "main2.py"
|
||||
env `shouldBe` [ ("print", addr 0)
|
||||
, ("foo", addr 1)
|
||||
, ("bar", addr 2)
|
||||
]
|
||||
Env.names env `shouldBe` [ "bar", "foo", "print" ]
|
||||
|
||||
it "subclasses" $ do
|
||||
v <- fst <$> evaluate "subclass.py"
|
||||
|
Loading…
Reference in New Issue
Block a user