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

46 lines
1.2 KiB
Haskell
Raw Normal View History

2018-03-16 21:09:41 +03:00
{-# LANGUAGE OverloadedLists, TypeApplications #-}
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
env <- evaluate "main.py"
2018-03-16 21:09:41 +03:00
let expectedEnv =
[ (qualifiedName ["a", "foo"], addr 0)
, (qualifiedName ["b", "c", "baz"], addr 1)
]
env `shouldBe` expectedEnv
it "imports with aliases" $ do
env <- evaluate "main1.py"
2018-03-16 21:09:41 +03:00
let expectedEnv =
[ (qualifiedName ["b", "foo"], addr 0)
, (qualifiedName ["e", "baz"], addr 1)
]
env `shouldBe` expectedEnv
it "imports using 'from' syntax" $ do
env <- evaluate "main2.py"
2018-03-16 21:09:41 +03:00
let expectedEnv =
[ (qualifiedName ["foo"], addr 0)
, (qualifiedName ["bar"], addr 1)
]
env `shouldBe` expectedEnv
where
addr = Address . Precise
fixtures = "test/fixtures/python/analysis/"
2018-03-15 17:23:50 +03:00
evaluate entry = snd . fst . fst . fst . fst <$>
evaluateFiles pythonParser
[ fixtures <> entry
, fixtures <> "a.py"
, fixtures <> "b/c.py"
]