]> Git — Sourcephile - comptalang.git/blob - cli/Hcompta/Repr/Text/Write/Test.hs
Gather into Writeable instances.
[comptalang.git] / cli / Hcompta / Repr / Text / Write / Test.hs
1 {-# LANGUAGE OverloadedStrings #-}
2
3 module Repr.Text.Write.Test where
4
5 import Data.Function (($))
6 import Data.Text.Lazy.Builder as Build
7 import qualified Data.Text.Lazy as Text
8 import Test.Tasty
9 import Test.Tasty.HUnit
10
11 import qualified Expr.Fun.Test as Fun
12 import qualified Expr.If.Test as If
13 import qualified Expr.Bool.Test as Bool
14 import Hcompta.Repr
15
16 tests :: TestTree
17 tests = testGroup "Write" $
18 let (==>) expr expected =
19 testCase (Text.unpack expected) $
20 Build.toLazyText (repr_text_write expr) @?=
21 expected
22 in
23 [ testGroup "Bool"
24 [ Bool.e1 ==> "True & False"
25 , Bool.e2 ==> "True & False | True & True"
26 , Bool.e3 ==> "(True | False) & (True | True)"
27 , Bool.e4 ==> "True & !False"
28 , Bool.e5 ==> "True & !x"
29 , Bool.e6 ==> "(x | y) & !(x & y)"
30 , Bool.e7 ==> "((x | y) & !(x & y) | z) & !(((x | y) & !(x & y)) & z)"
31 , Bool.e8 ==> "(x | (y | True) & !(y & True)) & !(x & ((y | True) & !(y & True)))"
32 ]
33 , testGroup "Fun"
34 [ Fun.e1 ==> "\\x0 -> (\\x1 -> (x0 | x1) & !(x0 & x1))"
35 , Fun.e2 ==> "\\x0 -> (\\x1 -> x0 & !x1 | !x0 & x1)"
36 , Fun.e3 ==> "let x0 = True in x0 & x0"
37 , Fun.e4 ==> "let x0 = \\x1 -> x1 & x1 in x0 True"
38 , Fun.e5 ==> "\\x0 -> (\\x1 -> x0 & x1)"
39 , Fun.e6 ==> "(let x0 = True in x0) & False"
40 , Fun.e7 ==> "\\x0 -> x0 True & False"
41 , Fun.e8 ==> "\\x0 -> x0 (True & False)"
42 ]
43 , testGroup "If"
44 [ If.e1 ==> "if True then False else True"
45 , If.e2 ==> "if True & True then False else True"
46 ]
47 ]
48