import Data.Functor ((<$>))
import Data.Int (Int)
import Data.Maybe (Maybe(..))
+import Data.Monoid (Monoid(..))
import Data.Ord (Ord(..))
import Data.Semigroup (Semigroup(..))
import Data.String (String)
import qualified Data.Text.Lazy as TL
import qualified Language.Symantic.Document.Term as Doc
+import qualified Language.Symantic.Document.Term.Dimension as Dim
import Language.Symantic.Document.Term ((<+>))
-- * Tests
hunits :: TestTree
hunits = testGroup "HUnit" $
[ hunitsTerm
+ , hunitsTermDimension
]
-infix 0 ==>
-(==>) :: Doc.Term -> TL.Text -> Assertion
-p ==> expected = got @?= expected
- where got = Doc.textTerm p
-
testList :: String -> [Assertion] -> TestTree
testList n as = testGroup n $ List.zipWith testCase (show <$> [1::Int ..]) as
, 4`wc` ["__", listHorV ["hello", "world"]] ==> "__[ hello\n , world\n ]"
, 11`wc` bs ["hello", "world"] ==> "hello world"
, 10`wc` bs ["hello", "world"] ==> "hello\nworld"
+ , 6`wc` bs ["hel", "lo", "wo", "rld"] ==> "hel lo\nwo rld"
+ , 6`wc` bs ["hel", "lo", "wo", "rld", "HEL", "LO", "WO", "RLD"] ==> "hel lo\nwo rld\nHEL LO\nWO RLD"
, 5`wc` bs ["hello", "world"] ==> "hello\nworld"
, 19`wc` fun (fun $ fun $ fun $ fun $ listHorV ["abcdefg", "abcdefg"])
==> "function(function(\n function(\n function(\n function(\n [ abcdefg\n , abcdefg\n ]\n )\n )\n )\n ))"
==> "function(\n function(\n function(\n function(\n function(\n [ abcdefgh\n , abcdefgh\n ]\n )\n )\n )\n )\n )"
]
]
+ where
+ (==>) :: Doc.Term -> TL.Text -> Assertion; infix 0 ==>
+ p ==> expected = got @?= expected
+ where got = Doc.textTerm p
+
+hunitsTermDimension :: TestTree
+hunitsTermDimension = testGroup "Term.Dimension"
+ [ testList "Textable"
+ [ Doc.newline ==> mempty
+ { Dim.dim_width = 0
+ , Dim.dim_height = 1
+ , Dim.dim_width_first = 0
+ , Dim.dim_width_last = 0
+ }
+ , Doc.newline <> Doc.newline ==> mempty
+ { Dim.dim_height = 2
+ }
+ , Doc.space ==> Dim.Dim 1 0 1 1
+ , Doc.newline <> Doc.space ==> mempty
+ { Dim.dim_width = 1
+ , Dim.dim_height = 1
+ , Dim.dim_width_first = 0
+ , Dim.dim_width_last = 1
+ }
+ , Doc.stringH "hello" ==> mempty
+ { Dim.dim_width = 5
+ , Dim.dim_height = 0
+ , Dim.dim_width_first = 5
+ , Dim.dim_width_last = 5
+ }
+ , "hello" ==> mempty
+ { Dim.dim_width = 5
+ , Dim.dim_height = 0
+ , Dim.dim_width_first = 5
+ , Dim.dim_width_last = 5
+ }
+ , Doc.newline <> "hello" ==> mempty
+ { Dim.dim_width = 5
+ , Dim.dim_height = 1
+ , Dim.dim_width_first = 0
+ , Dim.dim_width_last = 5
+ }
+ , "hel" <> Doc.newline ==> mempty
+ { Dim.dim_width = 3
+ , Dim.dim_height = 1
+ , Dim.dim_width_first = 3
+ , Dim.dim_width_last = 0
+ }
+ , ("hel" <> Doc.newline) <> "lo" ==> mempty
+ { Dim.dim_width = 3
+ , Dim.dim_height = 1
+ , Dim.dim_width_first = 3
+ , Dim.dim_width_last = 2
+ }
+ , Doc.catV @_ @[] ["hello", "world"] ==> mempty
+ { Dim.dim_width = 5
+ , Dim.dim_height = 1
+ , Dim.dim_width_first = 5
+ , Dim.dim_width_last = 5
+ }
+ , "hel\nlo" <> Doc.empty ==> Dim.Dim 3 1 3 2
+ , "hel\nlo " ==> Dim.Dim 3 1 3 3
+ , "lo" ==> Dim.Dim 2 0 2 2
+ , Doc.charH 'X' ==> Dim.Dim 1 0 1 1
+ , "lo"<>Doc.charH 'X' ==> Dim.Dim 3 0 3 3
+ , "lo"<>Doc.charH ' ' ==> Dim.Dim 3 0 3 3
+ , "lo"<>Doc.space ==> Dim.Dim 3 0 3 3
+ , (Doc.newline<>"lo")<>Doc.space ==> Dim.Dim 3 1 0 3
+ , (("hel"<>Doc.newline)<>"lo")<>Doc.space ==> Dim.Dim 3 1 3 3
+ , "hel\nlo" <> Doc.space ==> Dim.Dim 3 1 3 3
+ , (Dim.Dim 2 0 2 2 <> Dim.Dim 1 0 1 1) @?= Dim.Dim 3 0 3 3
+ ]
+ ]
+ where
+ (==>) :: Dim.Dimension -> Dim.Dim -> Assertion; infix 0 ==>
+ p ==> expected = got @?= expected
+ where got = Dim.dim p
be :: Doc.Breakable d => [d] -> d
be = Doc.foldWith Doc.breakableEmpty