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

43 lines
1.3 KiB
Haskell
Raw Normal View History

2018-03-16 21:09:41 +03:00
{-# LANGUAGE OverloadedLists, TypeApplications #-}
module Analysis.Go.Spec (spec) where
2018-03-12 23:52:50 +03:00
import Data.Abstract.Value
import Data.Map
2018-03-13 20:59:06 +03:00
2018-03-12 23:52:50 +03:00
import SpecHelpers
spec :: Spec
spec = parallel $ do
describe "evalutes Go" $ do
it "imports and wildcard imports" $ do
env <- evaluate "main.go"
2018-03-16 21:09:41 +03:00
let expectedEnv =
2018-03-12 23:52:50 +03:00
[ (qualifiedName ["foo", "New"], addr 0)
, (qualifiedName ["Rab"], addr 1)
, (qualifiedName ["Bar"], addr 2)
, (qualifiedName ["main"], addr 3)
2018-03-12 23:52:50 +03:00
]
env `shouldBe` expectedEnv
2018-03-12 23:52:50 +03:00
it "imports with aliases (and side effects only)" $ do
env <- evaluate "main1.go"
2018-03-16 21:09:41 +03:00
let expectedEnv =
2018-03-12 23:52:50 +03:00
[ (qualifiedName ["f", "New"], addr 0)
, (qualifiedName ["main"], addr 3) -- addr 3 is due to side effects of
-- eval'ing `import _ "./bar"` which
-- used addr 1 & 2.
2018-03-12 23:52:50 +03:00
]
env `shouldBe` expectedEnv
2018-03-12 23:52:50 +03:00
where
addr = Address . Precise
fixtures = "test/fixtures/go/analysis/"
2018-03-15 17:23:50 +03:00
evaluate entry = snd . fst . fst . fst . fst <$>
evaluateFiles goParser
2018-03-12 23:52:50 +03:00
[ fixtures <> entry
, fixtures <> "foo/foo.go"
, fixtures <> "bar/bar.go"
, fixtures <> "bar/rab.go"
2018-03-12 23:52:50 +03:00
]