1
1
mirror of https://github.com/github/semantic.git synced 2024-12-21 13:51:44 +03:00
semantic/test/Analysis/Go/Spec.hs

36 lines
1.4 KiB
Haskell
Raw Normal View History

2018-03-20 00:53:55 +03:00
{-# LANGUAGE OverloadedLists #-}
module Analysis.Go.Spec (spec) where
2018-03-12 23:52:50 +03:00
2018-04-21 17:22:09 +03:00
import Data.Abstract.Evaluatable (EvalError(..), runAnalysis)
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"
environment res `shouldBe` [ ("foo", addr 0)
, ("Bar", addr 2)
, ("Rab", addr 3)
, ("main", addr 4)
]
heapLookup (Address (Precise 0)) (heap res) `shouldBe` ns "foo" [ ("New", addr 1) ]
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"
environment res `shouldBe` [ ("f", addr 0)
, ("main", addr 4) -- addr 4 is due to side effects of eval'ing `import _ "./bar"` which used addr 2 & 3. f defines New which got addr 1.
]
heapLookup (Address (Precise 0)) (heap res) `shouldBe` ns "f" [ ("New", addr 1) ]
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-04-24 02:47:13 +03:00
evalGoProject path = runAnalysis @(TestEvaluating Go.Term) <$> evaluateProject goParser Language.Go Nothing path