1
1
mirror of https://github.com/github/semantic.git synced 2024-12-24 07:25:44 +03:00
semantic/test/Analysis/Ruby/Spec.hs

46 lines
1.3 KiB
Haskell
Raw Normal View History

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
env <- environment . snd <$> evaluate "main.rb"
2018-03-23 18:50:53 +03:00
let expectedEnv = [ (qualifiedName ["Object"], addr 0)
, (qualifiedName ["foo"], addr 3)]
env `shouldBe` expectedEnv
2018-03-14 02:19:26 +03:00
2018-03-16 01:09:07 +03:00
it "load" $ do
env <- environment . snd <$> 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"
fst res `shouldBe` Left "free variable: \"foo\""
environment (snd 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
res <- fst <$> 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
res <- fst <$> 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/"
evaluate entry = evaluateFilesWithPrelude rubyParser
2018-03-14 02:19:26 +03:00
[ fixtures <> entry
, fixtures <> "foo.rb"
]