;; This file is part of Beastie <https://purl.org/nxg/dist/beastie>
;; SPDX-FileCopyrightText: 2024 Norman Gray <https://nxg.me.uk>
;; SPDX-License-Identifier: BSD-2-Clause

(module "s7unit.scm" 'mdblock)

;(print-warning 'push #f)

(test-suite
 "markdown various"

 ;; basics: paragraphs, sectioning and lists
 (let ((md (parse-mdblock-string #"""
Heading 1
=========

Para 1.

Heading 2
---------
Para 2, line 1.
Para 2, line 2.

Para 3, line 1.
Para 3, line 2.
Para 3, line 3.

""")))
   (assert-equal md
                 '((h1 "Heading 1")
                   (p "Para 1.")
                   (h2 "Heading 2")
                   (p "Para 2, line 1. Para 2, line 2.")
                   (p "Para 3, line 1. Para 3, line 2. Para 3, line 3."))))

 (let ((md (parse-mdblock-string #"""

  * UL item 1.
  * UL item 2.
    Sentence 2.2.
  * UL item 3.
    Sentence 3.2.

    UL item 3. Para 2.

    UL item 3.
    Para 3.

Compact:
  * UL compact.
    UL compact, sentence 2.
  * UL compact 2.
UL compact 2, sentence 2, unindented.

New block.

1. OL item 1.

2. OL item 2.
     Sentence 2.2.

     And a further paragraph in item 2 (5-space indent).

3. OL item 3.
     Sentence 3.2.

1\. This is not a list
""")))
   (assert-equal md
                 '((ul
                    (li (p "UL item 1."))
                    (li (p "UL item 2. Sentence 2.2."))
                    (li (p "UL item 3. Sentence 3.2.")
                        (p "UL item 3. Para 2.")
                        (p "UL item 3. Para 3.")))
                   (p "Compact:")
                   (ul
                    (li "UL compact. UL compact, sentence 2.")
                    (li "UL compact 2. UL compact 2, sentence 2, unindented."))
                   (p "New block.")
                   (ol
                    (li (p "OL item 1."))
                    (li (p "OL item 2. Sentence 2.2.")
                        (p "And a further paragraph in item 2 (5-space indent)."))
                    (li (p "OL item 3. Sentence 3.2.")))
                   (p "1\\. This is not a list"))))

 (let ((md (parse-mdblock-string #"""
A simple _Markdown_ file
======================

Paragraph 1.
Second sentence.

----

That was a horizontal rule.

Another section  
---------------

Text preceding

    Indented text
    More indented text

# H1 line  

    Single pre

## H2 line (trailing hash) #

    Indented1
         Indented2

    Indented3

### H3 line

############### H6 line#######

Text, followed by not-a-heading

##  
""")))
   (assert-equal md
                 '((h1 "A simple _Markdown_ file")
                   (p "Paragraph 1. Second sentence.")
                   (hr)
                   (p "That was a horizontal rule.")
                   (h2 "Another section")
                   (p "Text preceding")
                   (blockquote "Indented text
More indented text
")
                   (h1 "H1 line")
                   (blockquote "Single pre
")
                   (h2 "H2 line (trailing hash)")
                   (blockquote "Indented1
     Indented2

Indented3
")
                   (h3 "H3 line")
                   (h6 "H6 line")
                   (p "Text, followed by not-a-heading")
                   (p "##  ")))))

(exit/failures)
