1
1
mirror of https://github.com/github/semantic.git synced 2024-12-30 18:36:27 +03:00
semantic/test/Analysis/Python/Spec.hs

47 lines
1.4 KiB
Haskell
Raw Normal View History

{-# LANGUAGE OverloadedLists, #-}
module Analysis.Python.Spec (spec) where
import Data.Abstract.Value
import Data.Map
2018-03-13 20:59:06 +03:00
import SpecHelpers
spec :: Spec
spec = parallel $ do
2018-03-10 02:55:04 +03:00
describe "evalutes Python" $ do
it "imports" $ do
2018-03-23 20:11:29 +03:00
env <- findEnv <$> evaluate "main.py"
env `shouldBe` [ (qualifiedName ["a", "foo"], addr 0)
, (qualifiedName ["b", "c", "baz"], addr 1)
]
it "imports with aliases" $ do
2018-03-23 20:11:29 +03:00
env <- findEnv <$> evaluate "main1.py"
env `shouldBe` [ (qualifiedName ["b", "foo"], addr 0)
, (qualifiedName ["e", "baz"], addr 1)
]
it "imports using 'from' syntax" $ do
2018-03-23 20:11:29 +03:00
env <- findEnv <$> evaluate "main2.py"
env `shouldBe` [ (qualifiedName ["foo"], addr 0)
, (qualifiedName ["bar"], addr 1)
]
it "subclasses" $ do
2018-03-23 20:11:29 +03:00
v <- findValue <$> evaluate "subclass.py"
v `shouldBe` Right (Right (Right (injValue (String "\"bar\""))))
it "handles multiple inheritance left-to-right" $ do
2018-03-23 20:11:29 +03:00
v <- findValue <$> evaluate "multiple_inheritance.py"
v `shouldBe` Right (Right (Right (injValue (String "\"foo!\""))))
where
addr = Address . Precise
fixtures = "test/fixtures/python/analysis/"
2018-03-23 20:11:29 +03:00
evaluate entry = evaluateFiles pythonParser
[ fixtures <> entry
, fixtures <> "a.py"
, fixtures <> "b/c.py"
]