pyrites/haskell-experiments/test/Test/SimpleParserSpec.hs

31 lines
936 B
Haskell
Raw Normal View History

2026-01-14 12:36:24 +00:00
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedRecordDot #-}
{-# HLINT ignore "Use const" #-}
{-# HLINT ignore "Unused LANGUAGE pragma" #-}
{-# HLINT ignore "Avoid lambda" #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE NoFieldSelectors #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
{-# LANGUAGE TypeApplications #-}
module Test.SimpleParserSpec where
import Test.Hspec
import SimpleParser
spec :: Spec
spec = do
describe "evaluate expressions" $ do
it "arithmetic on literals" $ do
eval (Add (Literal 2) (Literal 3) ) `shouldBe` 5
eval (Subtract (Literal 2) (Literal 3) ) `shouldBe` -1
eval (Multiply (Literal 2) (Literal 3) ) `shouldBe` 6
eval (Divide (Literal 7) (Literal 3) ) `shouldBe` 2
2026-01-14 12:39:15 +00:00
eval (Negate (Literal 7) ) `shouldBe` -7
it "more complex arithmetic on literals" $ do
eval (Add (Negate (Literal 1)) (Divide (Literal 7) (Literal 3))) `shouldBe` 1
2026-01-14 12:36:24 +00:00