2018-03-20 00:53:55 +03:00
|
|
|
{-# LANGUAGE OverloadedLists #-}
|
2018-03-13 20:26:28 +03:00
|
|
|
module Analysis.Go.Spec (spec) where
|
2018-03-12 23:52:50 +03:00
|
|
|
|
2018-05-10 17:07:11 +03:00
|
|
|
import Data.Abstract.Environment as Env
|
2018-05-07 00:37:44 +03:00
|
|
|
import Data.Abstract.Evaluatable (EvalError(..))
|
2018-04-21 17:22:09 +03:00
|
|
|
import qualified Language.Go.Assignment as Go
|
2018-04-24 02:47:13 +03:00
|
|
|
import qualified Data.Language as Language
|
2018-04-21 17:22:09 +03:00
|
|
|
|
2018-03-12 23:52:50 +03:00
|
|
|
import SpecHelpers
|
|
|
|
|
|
|
|
|
|
|
|
spec :: Spec
|
|
|
|
spec = parallel $ do
|
2018-04-02 21:18:58 +03:00
|
|
|
describe "evaluates Go" $ do
|
2018-03-12 23:52:50 +03:00
|
|
|
it "imports and wildcard imports" $ do
|
2018-04-03 00:54:08 +03:00
|
|
|
res <- snd <$> evaluate "main.go"
|
2018-05-10 17:07:11 +03:00
|
|
|
Env.names (environment res) `shouldBe` [ "Bar", "Rab", "foo", "main" ]
|
2018-04-03 00:54:08 +03:00
|
|
|
|
2018-05-10 17:07:11 +03:00
|
|
|
(derefQName (heap res) ("foo" :| []) (environment res) >>= deNamespace) `shouldBe` Just ("foo", ["New"])
|
2018-03-12 23:52:50 +03:00
|
|
|
|
|
|
|
it "imports with aliases (and side effects only)" $ do
|
2018-04-03 00:54:08 +03:00
|
|
|
res <- snd <$> evaluate "main1.go"
|
2018-05-10 17:07:11 +03:00
|
|
|
Env.names (environment res) `shouldBe` [ "f", "main" ]
|
2018-04-03 00:54:08 +03:00
|
|
|
|
2018-05-10 17:07:11 +03:00
|
|
|
(derefQName (heap res) ("f" :| []) (environment res) >>= deNamespace) `shouldBe` Just ("f", ["New"])
|
2018-03-12 23:52:50 +03:00
|
|
|
|
|
|
|
where
|
|
|
|
fixtures = "test/fixtures/go/analysis/"
|
2018-04-03 00:54:08 +03:00
|
|
|
evaluate entry = evalGoProject (fixtures <> entry)
|
2018-05-07 00:30:07 +03:00
|
|
|
evalGoProject path = testEvaluating <$> evaluateProject goParser Language.Go Nothing path
|