module Repr.Text.Test where import Test.Tasty import Test.Tasty.HUnit import qualified Data.Text as Text import Language.Symantic.Repr import qualified Expr.Lambda.Test as Lambda.Test import qualified Expr.Bool.Test as Bool.Test import qualified Expr.Maybe.Test as Maybe.Test import qualified Expr.Eq.Test as Eq.Test import qualified Expr.If.Test as If.Test import qualified Expr.List.Test as List.Test import qualified Expr.Functor.Test as Functor.Test import qualified Expr.Applicative.Test as Applicative.Test import qualified Expr.Foldable.Test as Foldable.Test tests :: TestTree tests = testGroup "Text" $ let (==>) expr expected = testCase (Text.unpack expected) $ (@?= expected) $ text_from_expr expr in [ testGroup "Bool" [ Bool.Test.e1 ==> "True && False" , Bool.Test.e2 ==> "True && False || True && True" , Bool.Test.e3 ==> "(True || False) && (True || True)" , Bool.Test.e4 ==> "True && !False" , Bool.Test.e5 ==> "True && !x" , Bool.Test.e6 ==> "xor x y" , Bool.Test.e7 ==> "xor (xor x y) z" , Bool.Test.e8 ==> "xor x (xor y True)" ] , testGroup "Lambda" [ Lambda.Test.e1 ==> "\\x0 -> (\\x1 -> (x0 || x1) && !(x0 && x1))" , Lambda.Test.e2 ==> "\\x0 -> (\\x1 -> x0 && !x1 || !x0 && x1)" , Lambda.Test.e3 ==> "let x0 = True in x0 && x0" , Lambda.Test.e4 ==> "let x0 = \\x1 -> x1 && x1 in x0 True" , Lambda.Test.e5 ==> "\\x0 -> (\\x1 -> x0 && x1)" , Lambda.Test.e6 ==> "(let x0 = True in x0) && False" , Lambda.Test.e7 ==> "\\x0 -> x0 True && True" , Lambda.Test.e8 ==> "\\x0 -> x0 (True && True)" ] , testGroup "Maybe" [ Maybe.Test.e1 ==> "maybe True (\\x0 -> !x0) (just True)" ] , testGroup "Eq" [ Eq.Test.e1 ==> "if True && True == True || False then True else False" , Eq.Test.e2 ==> "if True && True || False == True && (True || False) then True else False" , Eq.Test.e3 ==> "if !(True == False) == (True == True) then True else False" ] , testGroup "If" [ If.Test.e1 ==> "if True then False else True" , If.Test.e2 ==> "if True && True then False else True" ] , testGroup "List" [ List.Test.e1 ==> "list_filter (\\x0 -> if x0 % 2 == 0 then True else False) [1, 2, 3, 4, 5]" ] , testGroup "Functor" [ Functor.Test.e1 ==> "fmap (\\x0 -> x0 + 1) [1, 2, 3]" ] , testGroup "Applicative" [ Applicative.Test.e1 ==> "fmap (\\x0 -> (\\x1 -> x0 + x1)) (just 1) <*> just 2" ] , testGroup "Foldable" [ Foldable.Test.e1 ==> "foldMap (\\x0 -> [x0, x0]) [1, 2, 3]" ] ]