1
1
mirror of https://github.com/github/semantic.git synced 2024-12-12 14:45:40 +03:00
semantic/test/Analysis/PHP/Spec.hs
Rob Rix 6b780d297d Revert "These are probably integers."
This reverts commit d2a74b2a4ca1472976abfccc09601c60840c1761.
2018-05-28 16:06:25 -04:00

36 lines
1.4 KiB
Haskell

module Analysis.PHP.Spec (spec) where
import Control.Abstract
import Data.Abstract.Environment as Env
import Data.Abstract.Evaluatable (EvalError(..))
import qualified Data.Language as Language
import qualified Language.PHP.Assignment as PHP
import SpecHelpers
spec :: Spec
spec = parallel $ do
describe "PHP" $ do
it "evaluates include and require" $ do
((res, state), _) <- evaluate "main.php"
res `shouldBe` Right [unit]
Env.names (environment state) `shouldBe` [ "bar", "foo" ]
it "evaluates include_once and require_once" $ do
((res, state), _) <- evaluate "main_once.php"
res `shouldBe` Right [unit]
Env.names (environment state) `shouldBe` [ "bar", "foo" ]
it "evaluates namespaces" $ do
((_, state), _) <- evaluate "namespaces.php"
Env.names (environment state) `shouldBe` [ "Foo", "NS1" ]
(derefQName (heap state) ("NS1" :| []) (environment state) >>= deNamespace) `shouldBe` Just ("NS1", ["Sub1", "b", "c"])
(derefQName (heap state) ("NS1" :| ["Sub1"]) (environment state) >>= deNamespace) `shouldBe` Just ("Sub1", ["Sub2"])
(derefQName (heap state) ("NS1" :| ["Sub1", "Sub2"]) (environment state) >>= deNamespace) `shouldBe` Just ("Sub2", ["f"])
where
fixtures = "test/fixtures/php/analysis/"
evaluate entry = evalPHPProject (fixtures <> entry)
evalPHPProject path = testEvaluating <$> evaluateProject phpParser Language.PHP Nothing path