1
1
mirror of https://github.com/github/semantic.git synced 2024-12-21 05:41:54 +03:00
semantic/test/Analysis/Python/Spec.hs

47 lines
1.8 KiB
Haskell
Raw Normal View History

{-# LANGUAGE OverloadedLists, OverloadedStrings #-}
module Analysis.Python.Spec (spec) where
import Data.Abstract.Environment as Env
2018-05-07 00:37:44 +03:00
import Data.Abstract.Evaluatable (EvalError(..))
import Data.Abstract.Value
import Data.Map
2018-04-21 17:22:09 +03:00
import qualified Language.Python.Assignment as Python
2018-04-24 02:47:13 +03:00
import qualified Data.Language as Language
2018-03-13 20:59:06 +03:00
import SpecHelpers
spec :: Spec
spec = parallel $ do
describe "evaluates Python" $ do
it "imports" $ do
2018-05-10 17:58:24 +03:00
((_, state), _) <- evaluate "main.py"
Env.names (environment state) `shouldContain` [ "a", "b" ]
2018-05-10 17:58:24 +03:00
(derefQName (heap state) ("a" :| []) (environment state) >>= deNamespace) `shouldBe` Just ("a", ["foo"])
(derefQName (heap state) ("b" :| []) (environment state) >>= deNamespace) `shouldBe` Just ("b", ["c"])
(derefQName (heap state) ("b" :| ["c"]) (environment state) >>= deNamespace) `shouldBe` Just ("c", ["baz"])
it "imports with aliases" $ do
2018-05-10 17:58:24 +03:00
env <- environment . snd . fst <$> evaluate "main1.py"
Env.names env `shouldContain` [ "b", "e" ]
it "imports using 'from' syntax" $ do
2018-05-10 17:58:24 +03:00
env <- environment . snd . fst <$> evaluate "main2.py"
Env.names env `shouldContain` [ "bar", "foo" ]
it "subclasses" $ do
2018-05-10 17:58:24 +03:00
((res, _), _) <- evaluate "subclass.py"
res `shouldBe` Right [injValue (String "\"bar\"")]
it "handles multiple inheritance left-to-right" $ do
2018-05-10 17:58:24 +03:00
((res, _), _) <- evaluate "multiple_inheritance.py"
res `shouldBe` Right [injValue (String "\"foo!\"")]
where
ns n = Just . Latest . Just . injValue . Namespace n
addr = Address . Precise
fixtures = "test/fixtures/python/analysis/"
evaluate entry = evalPythonProject (fixtures <> entry)
evalPythonProject path = testEvaluating <$> evaluateProject pythonParser Language.Python pythonPrelude path