Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

447 run tests on all rule sets #465

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 26 additions & 17 deletions eo-phi-normalizer/test/Language/EO/Phi/DataizeSpec.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE RecordWildCards #-}

module Language.EO.Phi.DataizeSpec where
Expand All @@ -11,8 +12,10 @@ import Language.EO.Phi (printTree)
import Language.EO.Phi qualified as Phi
import Language.EO.Phi.Dataize (dataizeRecursively, defaultContext)
import Language.EO.Phi.Dependencies (deepMergePrograms)
import Language.EO.Phi.Rules.Common (equalObject)
import Language.EO.Phi.Rules.Common (NamedRule, equalObject)
import Language.EO.Phi.Rules.Fast (fastYegorInsideOutAsRule)
import Language.EO.Phi.Rules.Yaml (convertRuleNamed, parseRuleSetFromFile, rules)
import PyF (fmt)
import Test.EO.Phi (DataizationResult (Bytes, Object), DataizeTest (..), DataizeTestGroup (..), dataizationTests)

newtype ObjectOrBytes = ObjectOrBytes (Either Phi.Object Phi.Bytes)
Expand All @@ -39,22 +42,28 @@ spec :: Spec
spec = do
DataizeTestGroup{..} <- runIO (dataizationTests "test/eo/phi/dataization.yaml")
ruleset <- runIO $ parseRuleSetFromFile "test/eo/phi/rules/yegor.yaml"
let rules = map convertRuleNamed ruleset.rules
describe title $
forM_ tests $
\test -> do
deps <- runIO $ mapM getProgram test.dependencies
let mergedProgs = case deepMergePrograms (test.input : deps) of
Left err -> error ("Error merging programs: " ++ err)
Right prog -> prog
let ctx = defaultContext rules (progToObj mergedProgs)
let inputObj = progToObj test.input
let expectedResult = case test.output of
Object obj -> Left obj
Bytes bytes -> Right bytes
it test.name $ do
let dataizedResult = dataizeRecursively ctx inputObj
ObjectOrBytes dataizedResult `shouldBe` ObjectOrBytes expectedResult
let rulesFromYaml = map convertRuleNamed ruleset.rules
builtinRules = [fastYegorInsideOutAsRule]
testWithRules :: String -> [NamedRule] -> SpecWith ()
testWithRules source rules =
describe [fmt|With {source} rules|] $
forM_ tests $
\test -> do
deps <- runIO $ mapM getProgram test.dependencies
let mergedProgs = case deepMergePrograms (test.input : deps) of
Left err -> error ("Error merging programs: " ++ err)
Right prog -> prog
ctx = defaultContext rules (progToObj mergedProgs)
inputObj = progToObj test.input
expectedResult = case test.output of
Object obj -> Left obj
Bytes bytes -> Right bytes
dataizedResult = dataizeRecursively ctx inputObj
it test.name $ do
ObjectOrBytes dataizedResult `shouldBe` ObjectOrBytes expectedResult
describe title $ do
testWithRules "yegor.yaml" rulesFromYaml
testWithRules "built-in" builtinRules

progToObj :: Phi.Program -> Phi.Object
progToObj (Phi.Program bindings) = Phi.Formation bindings
22 changes: 15 additions & 7 deletions eo-phi-normalizer/test/Language/EO/Rules/PhiPaperSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TupleSections #-}
{-# OPTIONS_GHC -Wno-orphans #-}
Expand All @@ -24,9 +25,11 @@ import Data.Yaml qualified as Yaml
import GHC.Generics (Generic)
import Language.EO.Phi.Dataize (defaultContext)
import Language.EO.Phi.Rules.Common (ApplicationLimits (..), NamedRule, applyOneRule, defaultApplicationLimits, equalObject, intToBytes, objectSize)
import Language.EO.Phi.Rules.Fast (fastYegorInsideOutAsRule)
import Language.EO.Phi.Rules.Yaml (convertRuleNamed, parseRuleSetFromFile, rules)
import Language.EO.Phi.Syntax (printTree)
import Language.EO.Phi.Syntax.Abs as Phi
import PyF (fmt)
import Test.Hspec
import Test.QuickCheck

Expand Down Expand Up @@ -307,12 +310,17 @@ parseTests = Yaml.decodeFileThrow
spec :: Spec
spec = do
ruleset <- runIO $ parseRuleSetFromFile "./test/eo/phi/rules/yegor.yaml"
let rulesFromYaml = map convertRuleNamed (rules ruleset)
inputs <- runIO $ parseTests "./test/eo/phi/confluence.yaml"
let rulesFromYaml = map convertRuleNamed (rules ruleset)
builtinRules = [fastYegorInsideOutAsRule]
testWithRules :: String -> [NamedRule] -> SpecWith ()
testWithRules source rules = do
it [fmt|Are confluent with {source} rules (via QuickCheck)|] (confluent rules)
describe
"Are confluent (regression tests)"
$ forM_ (tests inputs)
$ \input -> do
it (printTree input) (input `shouldSatisfy` confluentOnObject rules)
describe "Yegor's rules" $ do
it "Are confluent (via QuickCheck)" (confluent rulesFromYaml)
describe
"Are confluent (regression tests)"
$ forM_ (tests inputs)
$ \input -> do
it (printTree input) (input `shouldSatisfy` confluentOnObject rulesFromYaml)
testWithRules "yegor.yaml" rulesFromYaml
testWithRules "built-in" builtinRules
Loading