Skip to content

Commit

Permalink
[fix] TypeDefinition tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RenzoMaggiori committed Jan 7, 2025
1 parent d5ce9e5 commit 59e535c
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions test/Ast/Parser/TypeDefinitionSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Ast.Parser.TypeDefinitionSpec (spec) where

import qualified Ast.Parser.Env as E
import qualified Ast.Parser.TypeDefinition as P
import qualified Ast.Types as AT
import qualified Control.Monad.State as S
import Test.Hspec
import qualified Text.Megaparsec as M
Expand All @@ -13,18 +14,18 @@ spec = do

describe "Struct Types" $ do
it "parses struct { name -> int }" $ do
parseWithEnv "test :: struct { name -> int }" `shouldBe` Right ()
parseWithEnv "test :: struct { name -> int }" `shouldBe` Right (AT.TStruct {AT.structName = "test", AT.fields = [("name", AT.TInt 32)]})

it "parses struct with multiple fields" $ do
parseWithEnv "vec :: struct { x -> float y -> float }" `shouldBe` Right ()
parseWithEnv "vec :: struct { x -> float y -> float }" `shouldBe` Right (AT.TStruct {AT.structName = "vec", AT.fields = [("x", AT.TFloat), ("y", AT.TFloat)]})

describe "Union Types" $ do
it "parses union { name -> int }" $ do
parseWithEnv "test :: union { name -> int }" `shouldBe` Right ()
parseWithEnv "test :: union { name -> int }" `shouldBe` Right (AT.TUnion {AT.unionName = "test", AT.variants = [("name", AT.TInt 32)]})

it "parses union with multiple fields" $ do
parseWithEnv "vec :: union { x -> float y -> float }" `shouldBe` Right ()
parseWithEnv "vec :: union { x -> float y -> float }" `shouldBe` Right (AT.TUnion {AT.unionName = "vec", AT.variants = [("x", AT.TFloat), ("y", AT.TFloat)]})

describe "Typedefs" $ do
it "parses typedef alias" $ do
parseWithEnv "Alias :: int" `shouldBe` Right ()
parseWithEnv "Alias :: int" `shouldBe` Right (AT.TTypedef "Alias" (AT.TInt 32))

0 comments on commit 59e535c

Please # to comment.