1
1
mirror of https://github.com/github/semantic.git synced 2024-12-14 08:25:32 +03:00
semantic/test/Analysis/PHP/Spec.hs

36 lines
1.4 KiB
Haskell
Raw Normal View History

module Analysis.PHP.Spec (spec) where
2018-05-28 22:44:48 +03:00
import Control.Abstract
import Data.Abstract.Environment as Env
2018-05-07 00:37:44 +03:00
import Data.Abstract.Evaluatable (EvalError(..))
2018-04-24 02:47:13 +03:00
import qualified Data.Language as Language
import qualified Language.PHP.Assignment as PHP
import SpecHelpers
spec :: Spec
spec = parallel $ do
2018-03-23 18:57:02 +03:00
describe "PHP" $ do
it "evaluates include and require" $ do
((Right [(res, env)], heap), _) <- evaluate ["main.php"]
res `shouldBe` unit
Env.names env `shouldBe` [ "bar", "foo" ]
2018-03-21 02:46:32 +03:00
2018-03-23 18:57:02 +03:00
it "evaluates include_once and require_once" $ do
((Right [(res, env)], heap), _) <- evaluate ["main_once.php"]
res `shouldBe` unit
Env.names env `shouldBe` [ "bar", "foo" ]
2018-03-23 18:57:02 +03:00
it "evaluates namespaces" $ do
((Right [(_, env)], heap), _) <- evaluate ["namespaces.php"]
Env.names env `shouldBe` [ "Foo", "NS1" ]
2018-06-21 20:22:58 +03:00
(derefQName heap ("NS1" :| []) env >>= deNamespace) `shouldBe` Just ("NS1", ["Sub1", "b", "c"])
(derefQName heap ("NS1" :| ["Sub1"]) env >>= deNamespace) `shouldBe` Just ("Sub1", ["Sub2"])
(derefQName heap ("NS1" :| ["Sub1", "Sub2"]) env >>= deNamespace) `shouldBe` Just ("Sub2", ["f"])
where
fixtures = "test/fixtures/php/analysis/"
evaluate = evalPHPProject . map (fixtures <>)
evalPHPProject = testEvaluating <=< evaluateProject (Proxy :: Proxy 'Language.PHP) phpParser Language.PHP