{-# LANGUAGE OverloadedStrings #-} module Repr.Text.Write.Test where import Data.Function (($)) import Data.Text.Lazy.Builder as Build import qualified Data.Text.Lazy as Text import Test.Tasty import Test.Tasty.HUnit import qualified Expr.Fun.Test as Fun import qualified Expr.If.Test as If import qualified Expr.Bool.Test as Bool import Hcompta.Repr tests :: TestTree tests = testGroup "Write" $ let (==>) expr expected = testCase (Text.unpack expected) $ Build.toLazyText (repr_text_write expr) @?= expected in [ testGroup "Bool" [ Bool.e1 ==> "True & False" , Bool.e2 ==> "True & False | True & True" , Bool.e3 ==> "(True | False) & (True | True)" , Bool.e4 ==> "True & !False" , Bool.e5 ==> "True & !x" , Bool.e6 ==> "(x | y) & !(x & y)" , Bool.e7 ==> "((x | y) & !(x & y) | z) & !(((x | y) & !(x & y)) & z)" , Bool.e8 ==> "(x | (y | True) & !(y & True)) & !(x & ((y | True) & !(y & True)))" ] , testGroup "Fun" [ Fun.e1 ==> "\\x0 -> (\\x1 -> (x0 | x1) & !(x0 & x1))" , Fun.e2 ==> "\\x0 -> (\\x1 -> x0 & !x1 | !x0 & x1)" , Fun.e3 ==> "let x0 = True in x0 & x0" , Fun.e4 ==> "let x0 = \\x1 -> x1 & x1 in x0 True" , Fun.e5 ==> "\\x0 -> (\\x1 -> x0 & x1)" , Fun.e6 ==> "(let x0 = True in x0) & False" , Fun.e7 ==> "\\x0 -> x0 True & False" , Fun.e8 ==> "\\x0 -> x0 (True & False)" ] , testGroup "If" [ If.e1 ==> "if True then False else True" , If.e2 ==> "if True & True then False else True" ] ]