diff --git a/eo-phi-normalizer/test/Language/EO/PhiSpec.hs b/eo-phi-normalizer/test/Language/EO/PhiSpec.hs index 503540606..2df5e9b2a 100644 --- a/eo-phi-normalizer/test/Language/EO/PhiSpec.hs +++ b/eo-phi-normalizer/test/Language/EO/PhiSpec.hs @@ -8,6 +8,8 @@ module Language.EO.PhiSpec where import Control.Monad (forM_) +import Data.Char (isSpace) +import Data.List (dropWhileEnd) import Data.String.Interpolate (i) import Language.EO.Phi import Language.EO.Phi.Rules.Common (Context (..), Rule) @@ -24,7 +26,7 @@ applyRule rule = \case spec :: Spec spec = do - describe "Pre-defined rules unit tests" $ + describe "Pre-defined rules" $ forM_ ([(1, rule1), (6, rule6)] :: [(Int, Rule)]) $ \(idx, rule) -> do PhiTestGroup{..} <- runIO (fileTests [i|test/eo/phi/rule-#{idx}.yaml|]) @@ -33,3 +35,18 @@ spec = do \PhiTest{..} -> it name $ applyRule (rule (Context [])) input `shouldBe` [normalized] + describe "Programs translated from EO" $ do + phiTests <- runIO (allPhiTests "test/eo/phi/from-eo/") + forM_ phiTests $ \PhiTestGroup{..} -> + describe title $ + forM_ tests $ + \PhiTest{..} -> do + describe "normalize" $ + it name $ + normalize input `shouldBe` normalized + describe "pretty-print" $ + it name $ + printTree input `shouldBe` trim prettified + +trim :: String -> String +trim = dropWhileEnd isSpace diff --git a/eo-phi-normalizer/test/eo/phi/from-eo/as-phi.yaml b/eo-phi-normalizer/test/eo/phi/from-eo/as-phi.yaml new file mode 100644 index 000000000..1469533f9 --- /dev/null +++ b/eo-phi-normalizer/test/eo/phi/from-eo/as-phi.yaml @@ -0,0 +1,9 @@ +title: Processing terms generated from EO +tests: + - name: "A program that prints itself" + input: | + {org ↦ ⟦eolang ↦ ⟦prints-itself ↦ ⟦φ ↦ Φ.org.eolang.as-phi(α0 ↦ ξ).length.gt(α0 ↦ Φ.org.eolang.int(α0 ↦ Φ.org.eolang.bytes(Δ ⤍ 00-00-00-00-00-00-00-00)))⟧, prints-itself-to-console ↦ ⟦x ↦ Φ.org.eolang.int(α0 ↦ Φ.org.eolang.bytes(Δ ⤍ 00-00-00-00-00-00-00-2A)), φ ↦ Φ.org.eolang.io.stdout(α0 ↦ Φ.org.eolang.as-phi(α0 ↦ ξ))⟧, λ ⤍ Package⟧, λ ⤍ Package⟧} + normalized: | + { ν ↦ ⟦ Δ ⤍ 04- ⟧, org ↦ ⟦ ν ↦ ⟦ Δ ⤍ 03- ⟧, eolang ↦ ⟦ ν ↦ ⟦ Δ ⤍ 02- ⟧, prints-itself ↦ ⟦ ν ↦ ⟦ Δ ⤍ 00- ⟧, φ ↦ Φ.org.eolang.as-phi (α0 ↦ ξ).length.gt (α0 ↦ Φ.org.eolang.int (α0 ↦ Φ.org.eolang.bytes (Δ ⤍ 00-00-00-00-00-00-00-00))) ⟧, prints-itself-to-console ↦ ⟦ ν ↦ ⟦ Δ ⤍ 01- ⟧, x ↦ Φ.org.eolang.int (α0 ↦ Φ.org.eolang.bytes (Δ ⤍ 00-00-00-00-00-00-00-2A)), φ ↦ Φ.org.eolang.io.stdout (α0 ↦ Φ.org.eolang.as-phi (α0 ↦ ξ)) ⟧, λ ⤍ Package ⟧, λ ⤍ Package ⟧ } + prettified: | + { org ↦ ⟦ eolang ↦ ⟦ prints-itself ↦ ⟦ φ ↦ Φ.org.eolang.as-phi (α0 ↦ ξ).length.gt (α0 ↦ Φ.org.eolang.int (α0 ↦ Φ.org.eolang.bytes (Δ ⤍ 00-00-00-00-00-00-00-00))) ⟧, prints-itself-to-console ↦ ⟦ x ↦ Φ.org.eolang.int (α0 ↦ Φ.org.eolang.bytes (Δ ⤍ 00-00-00-00-00-00-00-2A)), φ ↦ Φ.org.eolang.io.stdout (α0 ↦ Φ.org.eolang.as-phi (α0 ↦ ξ)) ⟧, λ ⤍ Package ⟧, λ ⤍ Package ⟧ }