Skip to content

Commit

Permalink
Add test for terms generated from EO
Browse files Browse the repository at this point in the history
  • Loading branch information
fizruk committed Feb 6, 2024
1 parent bb21771 commit 4c7089a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
19 changes: 18 additions & 1 deletion eo-phi-normalizer/test/Language/EO/PhiSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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|])
Expand All @@ -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
9 changes: 9 additions & 0 deletions eo-phi-normalizer/test/eo/phi/from-eo/as-phi.yaml
Original file line number Diff line number Diff line change
@@ -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 ⟧ }

0 comments on commit 4c7089a

Please sign in to comment.