Parser.hs
1 {-# LANGUAGE OverloadedStrings #-} 2 module Test.Parser (parserSpecs) where 3 4 import Test.Hspec 5 import Halcyon.Frontend (parseTokens, CToken(..)) 6 import Halcyon.Core.Ast 7 8 parserSpecs :: Spec 9 parserSpecs = describe "Parser" $ do 10 it "parses minimal program" $ 11 parseTokens [KwInt, Identifier "main", LParen, KwVoid, RParen, 12 LBrace, KwReturn, Number 42, Semicolon, RBrace] 13 `shouldBe` Right (Program (Function "main" (Return (Constant 42)))) 14 15 it "parses unary negation" $ 16 parseTokens [KwInt, Identifier "main", LParen, KwVoid, RParen, 17 LBrace, KwReturn, Hyphen, Number 42, Semicolon, RBrace] 18 `shouldBe` Right (Program (Function "main" (Return (Unary Negate (Constant 42)))))