2018-03-16 23:58:15 +03:00
|
|
|
{-# LANGUAGE OverloadedLists #-}
|
|
|
|
|
2018-03-14 02:19:26 +03:00
|
|
|
module Analysis.Ruby.Spec (spec) where
|
|
|
|
|
|
|
|
import Data.Abstract.Value
|
|
|
|
import Data.Map
|
|
|
|
|
|
|
|
import SpecHelpers
|
|
|
|
|
|
|
|
|
|
|
|
spec :: Spec
|
|
|
|
spec = parallel $ do
|
|
|
|
describe "evalutes Ruby" $ do
|
2018-03-16 01:08:03 +03:00
|
|
|
it "require_relative" $ do
|
2018-03-23 20:11:29 +03:00
|
|
|
env <- findEnv <$> evaluate "main.rb"
|
2018-03-23 18:50:53 +03:00
|
|
|
let expectedEnv = [ (qualifiedName ["Object"], addr 0)
|
|
|
|
, (qualifiedName ["foo"], addr 3)]
|
2018-03-15 22:29:08 +03:00
|
|
|
env `shouldBe` expectedEnv
|
2018-03-14 02:19:26 +03:00
|
|
|
|
2018-03-16 01:09:07 +03:00
|
|
|
it "load" $ do
|
2018-03-23 20:11:29 +03:00
|
|
|
env <- findEnv <$> evaluate "load.rb"
|
2018-03-23 18:50:53 +03:00
|
|
|
let expectedEnv = [ (qualifiedName ["Object"], addr 0)
|
|
|
|
, (qualifiedName ["foo"], addr 3) ]
|
2018-03-16 01:09:07 +03:00
|
|
|
env `shouldBe` expectedEnv
|
|
|
|
|
|
|
|
it "load wrap" $ do
|
2018-03-23 20:11:29 +03:00
|
|
|
res <- evaluate "load-wrap.rb"
|
2018-03-23 21:25:02 +03:00
|
|
|
findValue res `shouldBe` Left "free variable: \"foo\""
|
2018-03-24 00:56:26 +03:00
|
|
|
findEnv res `shouldBe` [(qualifiedName ["Object"], addr 0)]
|
2018-03-16 01:09:07 +03:00
|
|
|
|
2018-03-22 19:31:53 +03:00
|
|
|
it "subclass" $ do
|
2018-03-24 00:56:26 +03:00
|
|
|
res <- findValue <$> evaluate "subclass.rb"
|
2018-03-26 17:08:54 +03:00
|
|
|
res `shouldBe` Right (Right (Right (injValue (String "\"<bar>\""))))
|
2018-03-22 19:31:53 +03:00
|
|
|
|
2018-03-22 20:02:39 +03:00
|
|
|
it "has prelude" $ do
|
2018-03-24 00:56:26 +03:00
|
|
|
res <- findValue <$> evaluate "preluded.rb"
|
2018-03-26 17:08:54 +03:00
|
|
|
res `shouldBe` Right (Right (Right (injValue (String "\"<foo>\""))))
|
2018-03-22 19:31:53 +03:00
|
|
|
|
2018-03-14 02:19:26 +03:00
|
|
|
where
|
|
|
|
addr = Address . Precise
|
|
|
|
fixtures = "test/fixtures/ruby/analysis/"
|
2018-03-24 00:56:26 +03:00
|
|
|
evaluate entry = evaluateFilesWithPrelude rubyParser
|
2018-03-14 02:19:26 +03:00
|
|
|
[ fixtures <> entry
|
|
|
|
, fixtures <> "foo.rb"
|
|
|
|
]
|