2017-04-06 17:09:12 +03:00
|
|
|
module Language.Ruby.Syntax.Spec where
|
|
|
|
|
2017-04-06 20:36:54 +03:00
|
|
|
import Data.Functor.Union
|
|
|
|
import qualified Data.Syntax.Comment as Comment
|
|
|
|
import Language.Ruby.Syntax
|
2017-04-06 17:09:12 +03:00
|
|
|
import Prologue
|
|
|
|
import Test.Hspec
|
|
|
|
|
|
|
|
spec :: Spec
|
2017-04-06 20:36:54 +03:00
|
|
|
spec = do
|
|
|
|
describe "stepAssignment" $ do
|
2017-04-06 21:13:09 +03:00
|
|
|
it "matches nodes" $ do
|
2017-04-07 16:14:03 +03:00
|
|
|
stepAssignment comment [makeCommentAST "hello"] `shouldBe` Just ([], wrapU (Comment.Comment "hello") :: Program Syntax ())
|
2017-04-06 21:25:21 +03:00
|
|
|
|
|
|
|
it "attempts multiple alternatives" $ do
|
2017-04-07 16:14:03 +03:00
|
|
|
stepAssignment (if' <|> comment) [makeCommentAST "hello"] `shouldBe` Just ([], wrapU (Comment.Comment "hello") :: Program Syntax ())
|
2017-04-06 21:36:19 +03:00
|
|
|
|
|
|
|
it "matches in sequence" $ do
|
2017-04-07 16:14:03 +03:00
|
|
|
stepAssignment ((,) <$> comment <*> comment) [makeCommentAST "hello", makeCommentAST "world"] `shouldBe` Just ([], (wrapU (Comment.Comment "hello"), wrapU (Comment.Comment "world")) :: (Program Syntax (), Program Syntax ()))
|
|
|
|
|
|
|
|
makeCommentAST :: ByteString -> AST Grammar
|
|
|
|
makeCommentAST s = Rose (Node Comment s) []
|