1
1
mirror of https://github.com/github/semantic.git synced 2024-12-23 23:11:50 +03:00
semantic/test/Analysis/Go/Spec.hs

30 lines
1.1 KiB
Haskell
Raw Normal View History

module Analysis.Go.Spec (spec) where
2018-03-12 23:52:50 +03:00
import Data.Abstract.Environment as Env
2018-05-07 00:37:44 +03:00
import Data.Abstract.Evaluatable (EvalError(..))
import Data.Abstract.Value
2018-04-24 02:47:13 +03:00
import qualified Data.Language as Language
import qualified Language.Go.Assignment as Go
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-05-10 17:58:24 +03:00
((_, state), _) <- evaluate "main.go"
Env.names (environment state) `shouldBe` [ "Bar", "Rab", "foo", "main" ]
2018-04-03 00:54:08 +03:00
2018-05-10 17:58:24 +03:00
(derefQName (heap state) ("foo" :| []) (environment state) >>= deNamespace) `shouldBe` Just ("foo", ["New"])
2018-03-12 23:52:50 +03:00
it "imports with aliases (and side effects only)" $ do
2018-05-10 17:58:24 +03:00
((_, state), _) <- evaluate "main1.go"
Env.names (environment state) `shouldBe` [ "f", "main" ]
2018-04-03 00:54:08 +03:00
2018-05-10 17:58:24 +03:00
(derefQName (heap state) ("f" :| []) (environment state) >>= 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)
evalGoProject path = testEvaluating . runTermEvaluator @_ @_ @(Value Precise Go.Term) <$> evaluateProject goParser Language.Go Nothing path