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

50 lines
1.9 KiB
Haskell
Raw Normal View History

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-06-21 20:22:58 +03:00
((Right [(_, env)], heap), _) <- evaluate "main.py"
Env.names env `shouldContain` [ "a", "b" ]
2018-06-21 20:22:58 +03:00
(derefQName heap ("a" :| []) env >>= deNamespace) `shouldBe` Just ("a", ["foo"])
(derefQName heap ("b" :| []) env >>= deNamespace) `shouldBe` Just ("b", ["c"])
(derefQName heap ("b" :| ["c"]) env >>= deNamespace) `shouldBe` Just ("c", ["baz"])
it "imports with aliases" $ do
((Right [(_, env)], _), _) <- evaluate "main1.py"
Env.names env `shouldContain` [ "b", "e" ]
it "imports using 'from' syntax" $ do
((Right [(_, env)], _), _) <- evaluate "main2.py"
Env.names env `shouldContain` [ "bar", "foo" ]
2018-05-15 21:26:16 +03:00
it "imports with relative syntax" $ do
2018-06-21 20:22:58 +03:00
((Right [(_, env)], heap), _) <- evaluate "main3.py"
Env.names env `shouldContain` [ "utils" ]
2018-06-21 20:22:58 +03:00
(derefQName heap ("utils" :| []) env >>= deNamespace) `shouldBe` Just ("utils", ["to_s"])
2018-05-15 21:26:16 +03:00
it "subclasses" $ do
2018-05-10 17:58:24 +03:00
((res, _), _) <- evaluate "subclass.py"
fmap fst <$> res `shouldBe` Right [String "\"bar\""]
it "handles multiple inheritance left-to-right" $ do
2018-05-10 17:58:24 +03:00
((res, _), _) <- evaluate "multiple_inheritance.py"
fmap fst <$> res `shouldBe` Right [String "\"foo!\""]
where
2018-05-28 15:54:33 +03:00
ns n = Just . Latest . Last . Just . Namespace n
fixtures = "test/fixtures/python/analysis/"
evaluate entry = evalPythonProject (fixtures <> entry)
evalPythonProject path = testEvaluating =<< evaluateProject (Proxy :: Proxy 'Language.Python) pythonParser Language.Python path