2019-10-30 20:16:17 +03:00
|
|
|
{-# LANGUAGE DataKinds, ImplicitParams, OverloadedStrings, TypeApplications #-}
|
2019-06-11 01:53:20 +03:00
|
|
|
{-# OPTIONS_GHC -O0 #-}
|
2018-03-13 20:26:28 +03:00
|
|
|
module Analysis.Go.Spec (spec) where
|
2018-03-12 23:52:50 +03:00
|
|
|
|
2018-06-26 00:38:52 +03:00
|
|
|
import qualified Data.Abstract.ModuleTable as ModuleTable
|
2018-04-24 02:47:13 +03:00
|
|
|
import qualified Data.Language as Language
|
2019-10-23 17:34:36 +03:00
|
|
|
import qualified Language.Go.Term as Go
|
|
|
|
import Source.Loc
|
2019-06-16 14:00:47 +03:00
|
|
|
import SpecHelpers
|
2018-03-12 23:52:50 +03:00
|
|
|
|
|
|
|
|
2019-06-12 20:53:59 +03:00
|
|
|
spec :: (?session :: TaskSession) => Spec
|
2019-06-20 00:22:09 +03:00
|
|
|
spec = do
|
2018-06-25 18:55:54 +03:00
|
|
|
describe "Go" $ do
|
2018-03-12 23:52:50 +03:00
|
|
|
it "imports and wildcard imports" $ do
|
2018-11-29 20:31:42 +03:00
|
|
|
(scopeGraph, (heap, res)) <- evaluate ["main.go", "foo/foo.go", "bar/bar.go", "bar/rab.go"]
|
2018-06-26 00:38:52 +03:00
|
|
|
case ModuleTable.lookup "main.go" <$> res of
|
2018-12-11 21:07:45 +03:00
|
|
|
Right (Just (Module _ (scopeAndFrame, _))) -> do
|
2019-06-16 18:14:03 +03:00
|
|
|
SpecHelpers.lookupDeclaration "foo" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
2018-12-04 19:24:01 +03:00
|
|
|
SpecHelpers.lookupMembers "foo" Import scopeAndFrame heap scopeGraph `shouldBe` Just ["New"]
|
2019-06-16 18:14:03 +03:00
|
|
|
SpecHelpers.lookupDeclaration "main" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
|
|
|
SpecHelpers.lookupDeclaration "Bar" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
|
|
|
SpecHelpers.lookupDeclaration "Rab" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
2018-06-26 00:38:52 +03:00
|
|
|
other -> expectationFailure (show other)
|
2018-03-12 23:52:50 +03:00
|
|
|
|
|
|
|
it "imports with aliases (and side effects only)" $ do
|
2018-11-29 20:31:42 +03:00
|
|
|
(scopeGraph, (heap, res)) <- evaluate ["main1.go", "foo/foo.go", "bar/bar.go", "bar/rab.go"]
|
2018-06-26 00:38:52 +03:00
|
|
|
case ModuleTable.lookup "main1.go" <$> res of
|
2018-12-11 21:07:45 +03:00
|
|
|
Right (Just (Module _ (scopeAndFrame, _))) -> do
|
2019-06-16 18:14:03 +03:00
|
|
|
SpecHelpers.lookupDeclaration "f" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
|
|
|
SpecHelpers.lookupDeclaration "main" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
2018-11-09 02:22:35 +03:00
|
|
|
-- (lookupDeclaration "f" heap >>= deNamespace heap) `shouldBe` Just ("f", ["New"])
|
2018-06-26 00:38:52 +03:00
|
|
|
other -> expectationFailure (show other)
|
2018-03-12 23:52:50 +03:00
|
|
|
|
|
|
|
where
|
|
|
|
fixtures = "test/fixtures/go/analysis/"
|
2019-10-23 17:34:36 +03:00
|
|
|
evaluate = evaluateProject @'Language.Go @(Go.Term Loc) ?session Proxy . map (fixtures <>)
|