From 2e66b03baa41ff751d6303d53091189cda6880ee Mon Sep 17 00:00:00 2001 From: Nathan McCarty Date: Thu, 27 Feb 2025 04:41:09 -0500 Subject: [PATCH] Paragraph testing --- src/SSG/Djot/Block.idr | 12 +++++++++++- src/SSG/Djot/Lines.idr | 6 +++++- src/SSG/Djot/Render.idr | 1 + test/Main.idr | 1 + test/djotToHtml/001-paragraph/Main.idr | 18 ++++++++++++++++++ test/djotToHtml/001-paragraph/expected | 12 ++++++++++++ test/djotToHtml/001-paragraph/pack.toml | 5 +++++ test/djotToHtml/001-paragraph/run | 6 ++++++ test/djotToHtml/001-paragraph/test.dj | 12 ++++++++++++ test/djotToHtml/001-paragraph/test.ipkg | 9 +++++++++ 10 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 test/djotToHtml/001-paragraph/Main.idr create mode 100644 test/djotToHtml/001-paragraph/expected create mode 100644 test/djotToHtml/001-paragraph/pack.toml create mode 100644 test/djotToHtml/001-paragraph/run create mode 100644 test/djotToHtml/001-paragraph/test.dj create mode 100644 test/djotToHtml/001-paragraph/test.ipkg diff --git a/src/SSG/Djot/Block.idr b/src/SSG/Djot/Block.idr index 057c7ea..d2b0677 100644 --- a/src/SSG/Djot/Block.idr +++ b/src/SSG/Djot/Block.idr @@ -127,4 +127,14 @@ golden input ref = do -- @@test Paragraph Smoke smokeParagraph : IO Bool -smokeParagraph = golden "Hello World!" [Paragraph [Text "Hello World!"]] +smokeParagraph = + golden + "Hello World!" + [Paragraph [Text "Hello World!"]] + +-- @@test Two Paragraph Smoke +smokeTwoParagraph : IO Bool +smokeTwoParagraph = + golden + "Hello World!\n\nHello Alice!" + [Paragraph [Text "Hello World!"], Paragraph [Text "Hello Alice!"]] diff --git a/src/SSG/Djot/Lines.idr b/src/SSG/Djot/Lines.idr index a445b39..4108762 100644 --- a/src/SSG/Djot/Lines.idr +++ b/src/SSG/Djot/Lines.idr @@ -47,7 +47,11 @@ slurp predicate = do if predicate line then do _ <- take - slurp predicate + Just next <- peek + | _ => pure [] + if predicate next + then slurp predicate + else pure [] else do Just x <- take | _ => pure [] diff --git a/src/SSG/Djot/Render.idr b/src/SSG/Djot/Render.idr index 73cf01b..a2a0092 100644 --- a/src/SSG/Djot/Render.idr +++ b/src/SSG/Djot/Render.idr @@ -30,6 +30,7 @@ renderBlock (Paragraph content) = renderBlocks xs = dMap' (\_, x => renderBlock x) xs ||| Render a complete html document from a list of block level elements +export renderDocument : {types : _} -> DList _ Block types -> Html "html" renderDocument xs = Normal "html" ["lang" =$ "en"] [ diff --git a/test/Main.idr b/test/Main.idr index b8ffd00..04cd676 100644 --- a/test/Main.idr +++ b/test/Main.idr @@ -5,4 +5,5 @@ import Test.Golden.RunnerHelper main : IO () main = goldenRunner [ "Hedgehog Tests" `atDir` "hedgehog" + , "Djot -> HTML Tests" `atDir` "djotToHtml" ] diff --git a/test/djotToHtml/001-paragraph/Main.idr b/test/djotToHtml/001-paragraph/Main.idr new file mode 100644 index 0000000..64b3cdf --- /dev/null +++ b/test/djotToHtml/001-paragraph/Main.idr @@ -0,0 +1,18 @@ +module Main + +import SSG.Djot +import SSG.HTML + +import System +import System.File + +main : IO () +main = do + Right contents <- readFile "./test.dj" + | Left err => do + printLn err + exitFailure + let (_ ** blocks) = block contents + let html = renderDocument blocks + let output = render html + putStrLn output diff --git a/test/djotToHtml/001-paragraph/expected b/test/djotToHtml/001-paragraph/expected new file mode 100644 index 0000000..d83d19b --- /dev/null +++ b/test/djotToHtml/001-paragraph/expected @@ -0,0 +1,12 @@ + + + +

Hello World!

+

Hello Alice!

+

A Multi-line +Paragraph

+

Two line breaks

+

A multiline paragraph + with some indentation

+ + diff --git a/test/djotToHtml/001-paragraph/pack.toml b/test/djotToHtml/001-paragraph/pack.toml new file mode 100644 index 0000000..d2e5465 --- /dev/null +++ b/test/djotToHtml/001-paragraph/pack.toml @@ -0,0 +1,5 @@ +[custom.all.SSG] +type = "local" +path = "../../.." +ipkg = "SSG.ipkg" +test = "test/test.ipkg" diff --git a/test/djotToHtml/001-paragraph/run b/test/djotToHtml/001-paragraph/run new file mode 100644 index 0000000..6b5ab53 --- /dev/null +++ b/test/djotToHtml/001-paragraph/run @@ -0,0 +1,6 @@ +rm -rf build/ + +flock "$1" pack -q install-deps test.ipkg +pack -q run test.ipkg + +rm -rf build/ diff --git a/test/djotToHtml/001-paragraph/test.dj b/test/djotToHtml/001-paragraph/test.dj new file mode 100644 index 0000000..d4ab1bf --- /dev/null +++ b/test/djotToHtml/001-paragraph/test.dj @@ -0,0 +1,12 @@ +Hello World! + +Hello Alice! + +A Multi-line +Paragraph + + +Two line breaks + +A multiline paragraph + with some indentation diff --git a/test/djotToHtml/001-paragraph/test.ipkg b/test/djotToHtml/001-paragraph/test.ipkg new file mode 100644 index 0000000..e727cbf --- /dev/null +++ b/test/djotToHtml/001-paragraph/test.ipkg @@ -0,0 +1,9 @@ +package a-test + +depends = SSG + , hedgehog + , eff + +main = Main + +executable = test