diff options
| author | 2025-02-02 20:47:24 -0500 | |
|---|---|---|
| committer | 2025-02-02 20:47:24 -0500 | |
| commit | 39c8aa098cd5aee196224dda8de5ad622c112ec6 (patch) | |
| tree | ffed0f79706b110f5a2abb375b476eeba3133382 /tests | |
| parent | thematic breaks (diff) | |
Change handling of paragraph breaks, compress tests
Although lazy lines are explicitly not supported in Market, a restricted
version of lazy lines, lazy paragraph breaks, should be. In list elements,
the following:
1. test
~~ test
~~ test
paragraph
(where `~` is a visible space) should parse as
((list-item "test\ntest\n\ntest\n") (paragraph "paragraph\n"))
This is currently the case, but the current algorithm only looks at the
current line to determine what line should be associated with the text.
This is an issue because figuring out which element a lazy paragraph
break should associate with requires arbitrary lookahead:
1. test
test
should be one element: on the other hand,
1. test
test
should be one element, multiple paragraph breaks, and another element.
Possible solutions:
1. Remove lazy paragraph breaks. I do not like this because it makes multi
paragraph lists depend on non-visible characters.
2. Abandon line-by-line parsing. Not good, would require the entire buffer.
3. Save state with continuations. Would be very inefficient.
4. Save state in the record. Would make the algorithm more complex.
5. When a line is found that does not continue the element, remove the paragraph
breaks from the element and put them into the parent node.
This is definitely possible, as the parent node is in scope of `continues`
in the algorithm. This would require storing data in a way that makes the
last elements easily accessible. Possible solutions:
1. Reversed list, turn into a queue on success. Would require a recursive
descent to close child nodes, although it would never revisit a closed
node.
2. Reversed list, as-is. Sounds error prone.
3. Doubly linked lists. Difficult to turn into regular lists, which is what
the rest of Scheme uses.
I will probably do 5.1.
Note: I believe a much simpler parser could be made with delimited, composable
continuations. If the location of a paragraph break cannot be located, then
a delimited continuation can be captured, and more lines can be captured until
the disambiguating line is found, and then the continuation can process the
paragraph breaks. The continuation allows for accumulation of state without
explicitly putting it in a structure.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/run.scm | 371 |
1 files changed, 89 insertions, 282 deletions
diff --git a/tests/run.scm b/tests/run.scm index 2fef24a..d903454 100644 --- a/tests/run.scm +++ b/tests/run.scm @@ -19,13 +19,14 @@ (load "../market/blocks.sld") (load "../market/default.sld") -(import (prefix (only (mcgoron srfi 64) factory) +(import (prefix (only (mcgoron srfi 64) factory set-verbosity!) mcgoron-test-) (srfi 64) (srfi 197) (srfi 117)) (import (market default) (market string) (market blocks)) (test-runner-factory mcgoron-test-factory) (test-runner-current (test-runner-create)) +(mcgoron-test-set-verbosity! '(fails group-stack)) ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Chained test predicates @@ -84,50 +85,34 @@ ;;; Paragraphs ;;; ;;;;;;;;;;;;;;;;;;;;;;; +(define (test-child-string name num expected lst) + (test-group name + (chain (test-child "xstring" xstring? num lst) + (xstring->string _) + (test-equal-then "text" expected _))) + lst) + +(define (test-paragraph-break name num lst) + (test-child-string name num "\n" lst)) + (test-group "paragraphs" (with-test-chain "single line" (test-parse->document "hello, world") (test-node-list "document children" 1 _) - (test-child "xstring" xstring? 0 _) - (xstring->string _) - (test-assert-then "string?" string? _) - (test-equal-then "text" - "hello, world\n" - _)) + (test-child-string "text" 0 "hello, world\n" _)) (with-test-chain "two lines" (test-parse->document "hello,") (test-parse->document "world" _) (test-node-list "document children" 1 _) - (test-child "xstring" xstring? 0 _) - (xstring->string _) - (test-equal-then "text" - "hello,\nworld\n" - _)) + (test-child-string "text" 0 "hello,\nworld\n" _)) (with-test-chain "two paragraphs" (test-parse->document "hello") (test-parse->document "" _) (test-parse->document "world" _) - (test-node-list "document children" 2 _) - (fork "first" - _ - (chain-lambda (test-child "first paragraph xstring?" - xstring? - 0 - _) - (xstring->string _) - (test-equal-then "first paragraph" - "hello\n" - _))) - (fork "second" - _ - (chain-lambda (test-child "second paragraph xstring?" - xstring? - 1 - _) - (xstring->string _) - (test-equal-then "first paragraph" - "world\n" - _))))) + (test-node-list "document children" 3 _) + (test-child-string "first" 0 "hello\n" _) + (test-paragraph-break "break" 1 _) + (test-child-string "second" 2 "world\n" _))) (test-group "block quotes" (with-test-chain "single line" @@ -135,74 +120,37 @@ (test-node-list "document node" 1 _) (test-child "block-quote?" block-quote? 0 _) (test-node-list "block children" 1 _) - (test-child "xstring?" xstring? 0 _) - (xstring->string _) - (test-equal-then "text" - "hello, world\n" - _)) + (test-child-string "text" 0 "hello, world\n" _)) (with-test-chain "two lines" (test-parse->document "> hello,") (test-parse->document "> world" _) (test-node-list "document node" 1 _) (test-child "block-quote?" block-quote? 0 _) (test-node-list "quote children" 1 _) - (test-child "xstring?" xstring? 0 _) - (xstring->string _) - (test-equal-then "text" - "hello,\nworld\n" - _)) + (test-child-string "text" 0 "hello,\nworld\n" _)) (with-test-chain "multiple paragraphs in block quote" (test-parse->document "> hello") (test-parse->document "> " _) (test-parse->document "> world" _) (test-node-list "document node" 1 _) (test-child "block-quote?" block-quote? 0 _) - (test-node-list "quote node" 2 _) - (fork - "first" - _ - (chain-lambda (test-child "first paragraph xstring?" - xstring? - 0 - _) - (xstring->string _) - (test-equal-then "first paragraph" - "hello\n" - _))) - (fork - "second" - _ - (chain-lambda (test-child "second paragraph xstring?" - xstring? - 1 - _) - (xstring->string _) - (test-equal-then "second paragraph" - "world\n" - _)))) + (test-node-list "quote node" 3 _) + (test-child-string "first" 0 "hello\n" _) + (test-paragraph-break "break" 1 _) + (test-child-string "second" 2 "world\n" _)) (with-test-chain "interrupted by paragraph break" (test-parse->document "> hello,") (test-parse->document "" _) (test-parse->document "world" _) - (test-node-list "document node" 2 _) + (test-node-list "document node" 3 _) (fork "block quote" _ (chain-lambda (test-child "block-quote?" block-quote? 0 _) (test-node-list "quote children" 1 _) - (test-child "quote xstring?" xstring? 0 _) - (xstring->string _) - (test-equal-then "quote text" - "hello,\n" - _))) - (fork - "paragraph" - _ - (chain-lambda (test-child "paragraph xstring?" xstring? 1 _) - (xstring->string _) - (test-equal-then "paragraph text" - "world\n" - _)))) + (test-child-string "quote" 0 "hello,\n" _))) + (test-paragraph-break "break" 1 _) + (test-child-string "paragraph" 2 "world\n" _)) (with-test-chain "interrupted" (test-parse->document "> hello, world") (test-parse->document "outside of a block quote" _) @@ -212,19 +160,8 @@ _ (chain-lambda (test-child "block-quote?" block-quote? 0 _) (test-node-list "quote children" 1 _) - (test-child "quote xstring?" xstring? 0 _) - (xstring->string _) - (test-equal-then "quote text" - "hello, world\n" - _))) - (fork - "paragraph" - _ - (chain-lambda (test-child "paragraph xstring?" xstring? 1 _) - (xstring->string _) - (test-equal-then "paragraph text" - "outside of a block quote\n" - _)))) + (test-child-string "quote" 0 "hello, world\n" _))) + (test-child-string "paragraph" 1 "outside of a block quote\n" _)) (with-test-chain "two nested with spaces" (test-parse->document "> > hello, world") (test-parse->document "> > continuing nested" _) @@ -237,19 +174,8 @@ _ (chain-lambda (test-child "nested quote" block-quote? 0 _) (test-node-list "nested quote children" 1 _) - (test-child "xstring?" xstring? 0 _) - (xstring->string _) - (test-equal-then "nested quote text" - "hello, world\ncontinuing nested\n" - _))) - (fork - "inside quote" - _ - (chain-lambda (test-child "paragraph in quote" xstring? 1 _) - (xstring->string _) - (test-equal-then "nested quote text" - "outside of the block quote\n" - _)))) + (test-child-string "quote" 0 "hello, world\ncontinuing nested\n" _))) + (test-child-string "inside quote" 1 "outside of the block quote\n" _)) (with-test-chain "two nested without spaces" (test-parse->document ">> hello, world") (test-parse->document ">> continuing nested" _) @@ -263,19 +189,8 @@ _ (chain-lambda (test-child "nested block quote" block-quote? 0 _) (test-node-list "nested block quote children" 1 _) - (test-child "xstring?" xstring? 0 _) - (xstring->string _) - (test-equal-then "nested block quote text" - "hello, world\ncontinuing nested\n" - _))) - (fork - "first level xstring" - _ - (chain-lambda (test-child "first level xstring?" xstring? 1 _) - (xstring->string _) - (test-equal-then "first level block quote text" - "at first level\ncontinuing first level\n" - _))))) + (test-child-string "nested" 0 "hello, world\ncontinuing nested\n" _))) + (test-child-string "first level" 1 "at first level\ncontinuing first level\n" _))) (test-group "atx headings" (with-test-chain "heading 1" @@ -287,18 +202,14 @@ atx-heading-indent _) (test-node-list "heading children" 1 _) - (test-child "xstring?" xstring? 0 _) - (xstring->string _) - (test-equal-then "text" "hello" _)) + (test-child-string "xstring?" 0 "hello" _)) (with-test-chain "heading 6" (test-parse->document "###### hello") (test-node-list "document children" 1 _) (test-child "atx-heading?" atx-heading? 0 _) (test-equal-then "indent" 6 atx-heading-indent _) (test-node-list "heading children" 1 _) - (test-child "xstring?" xstring? 0 _) - (xstring->string _) - (test-equal-then "text" "hello" _)) + (test-child-string "xstring?" 0 "hello" _)) (with-test-chain "heading followed by paragraph" (test-parse->document "## hello, ") (test-parse->document "world" _) @@ -310,24 +221,15 @@ (chain-lambda (test-child "atx-heading?" atx-heading? 0 _) (test-equal-then "indent" 2 atx-heading-indent _) (test-node-list "children" 1 _) - (test-child "xstring?" xstring? 0 _) - (xstring->string _) - (test-equal-then "text" "hello, " _))) - (fork - "paragraph" - _ - (chain-lambda (test-child "xstring?" xstring? 1 _) - (xstring->string _) - (test-equal-then "text" "world\n" _))) + (test-child-string "xstring?" 0 "hello, " _))) + (test-child-string "paragraph" 1 "world\n" _) (fork "atx heading 2" _ (chain-lambda (test-child "atx-heading?" atx-heading? 2 _) (test-equal-then "indent" 2 atx-heading-indent _) (test-node-list "children" 1 _) - (test-child "xstring?" xstring? 0 _) - (xstring->string _) - (test-equal-then "text" "another heading" _)))) + (test-child-string "xstring?" 0 "another heading" _)))) (with-test-chain "heading inside block quote" (test-parse->document "> # nested heading") (test-parse->document "> text inside quote" _) @@ -344,26 +246,15 @@ (chain-lambda (test-child "atx-heading?" atx-heading? 0 _) (test-equal-then "indent" 1 atx-heading-indent _) (test-node-list "children" 1 _) - (test-child "xstring?" xstring? 0 _) - (xstring->string _) - (test-equal-then "text" "nested heading" _))) - (fork - "paragraph" - _ - (chain-lambda (test-child "xstring?" xstring? 1 _) - (xstring->string _) - (test-equal-then "text" "text inside quote\n" _))))) + (test-child-string "xstring?" 0 "nested heading" _))) + (test-child-string "xstring?" 1 "text inside quote\n" _))) (fork "heading outside of quote" _ (chain-lambda (test-child "atx-heading?" atx-heading? 1 _) (test-equal-then "indent" 3 atx-heading-indent _) (test-node-list "children" 1 _) - (test-child "xstring?" xstring? 0 _) - (xstring->string _) - (test-equal-then "text" "outside of quote" _))))) - -;;; TODO: test of line break in code block + (test-child-string "xstring?" 0 "outside of quote" _))))) (test-group "code blocks" (define (test/string name prepend) @@ -372,9 +263,7 @@ (test-node-list "document children" 1 _) (test-child "code-block?" code-block? 0 _) (test-node-list "block children" 1 _) - (test-child "xstring?" xstring? 0 _) - (xstring->string _) - (test-equal-then "text" "(procedure? call/cc)\n" _))) + (test-child-string "xstring?" 0 "(procedure? call/cc)\n" _))) (test/string "single line, 4 spaces" " ") (test/string "single line, tab" "\t") (with-test-chain "multiple lines, mixing" @@ -383,17 +272,13 @@ (test-node-list "document children" 1 _) (test-child "code-block?" code-block? 0 _) (test-node-list "block children" 1 _) - (test-child "xstring?" xstring? 0 _) - (xstring->string _) - (test-equal-then "text" "(lambda (x)\n x)\n" _)) + (test-child-string "xstring?" 0 "(lambda (x)\n x)\n" _)) (with-test-chain "no quotes in code blocks" (test-parse->document " > not a block") (test-node-list "document children" 1 _) (test-child "code-block?" code-block? 0 _) (test-node-list "block children" 1 _) - (test-child "xstring?" xstring? 0 _) - (xstring->string _) - (test-equal-then "text" "> not a block\n" _)) + (test-child-string "xstring?" 0 "> not a block\n" _)) (with-test-chain "code block in quotes" (test-parse->document "> quoted code") (test-node-list "document children" 1 _) @@ -401,9 +286,19 @@ (test-node-list "quote children" 1 _) (test-child "code-block?" code-block? 0 _) (test-node-list "code block children" 1 _) - (test-child "xstring?" xstring? 0 _) - (xstring->string _) - (test-equal-then "text" "quoted code\n" _))) + (test-child-string "xstring?" 0 "quoted code\n" _)) + (with-test-chain "code block with empty lines" + (test-parse->document " code") + (test-parse->document " " _) + (test-parse->document " " _) + (test-parse->document " block" _) + (test-node-list "document children" 1 _) + (test-child "code block" code-block? 0 _) + (test-node-list "code block children" 4 _) + (test-child-string "first" 0 "code\n" _) + (test-paragraph-break "second" 1 _) + (test-paragraph-break "third" 2 _) + (test-child-string "fourth" 3 "block\n" _))) (test-group "unordered lists" (with-test-chain "one element" @@ -411,64 +306,34 @@ (test-node-list "document children" 1 _) (test-child "unordered-list-item?" unordered-list-item? 0 _) (test-node-list "list children" 1 _) - (test-child "xstring?" xstring? 0 _) - (xstring->string _) - (test-equal "text" "hello, world\n" _)) + (test-child-string "xstring?" 0 "hello, world\n" _)) (with-test-chain "one element continued" (test-parse->document "* hello,") (test-parse->document " world" _) (test-node-list "document children" 1 _) (test-child "list item" unordered-list-item? 0 _) (test-node-list "list children" 1 _) - (test-child "xstring?" xstring? 0 _) - (xstring->string _) - (test-equal "text" "hello,\nworld\n" _)) + (test-child-string "xstring?" 0 "hello,\nworld\n" _)) (with-test-chain "one element with indentation" (test-parse->document "* hello, world") (test-parse->document " " _) (test-parse->document " second paragraph" _) (test-node-list "document children" 1 _) (test-child "list item" unordered-list-item? 0 _) - (test-node-list "list children" 2 _) - (fork - "first paragraph" - _ - (chain-lambda (test-child "xstring?" xstring? 0 _) - (xstring->string _) - (test-equal-then "text" - "hello, world\n" - _))) - (fork - "second paragraph" - _ - (chain-lambda (test-child "xstring?" xstring? 1 _) - (xstring->string _) - (test-equal-then "text" - "second paragraph\n" - _)))) + (test-node-list "list children" 3 _) + (test-child-string "first" 0 "hello, world\n" _) + (test-paragraph-break "break" 1 _) + (test-child-string "second" 2 "second paragraph\n" _)) (with-test-chain "one element w/o indentation" (test-parse->document "* hello, world") (test-parse->document "" _) (test-parse->document " second paragraph" _) (test-node-list "document children" 1 _) (test-child "list item" unordered-list-item? 0 _) - (test-node-list "list children" 2 _) - (fork - "first paragraph" - _ - (chain-lambda (test-child "xstring?" xstring? 0 _) - (xstring->string _) - (test-equal-then "text" - "hello, world\n" - _))) - (fork - "second paragraph" - _ - (chain-lambda (test-child "xstring?" xstring? 1 _) - (xstring->string _) - (test-equal-then "text" - "second paragraph\n" - _)))) + (test-node-list "list children" 3 _) + (test-child-string "first" 0 "hello, world\n" _) + (test-paragraph-break "break" 1 _) + (test-child-string "first" 2 "second paragraph\n" _)) (with-test-chain "one element interrupted" (test-parse->document "* hello,") (test-parse->document "world" _) @@ -478,34 +343,21 @@ _ (chain-lambda (test-child "list item" unordered-list-item? 0 _) (test-node-list "items" 1 _) - (test-child "xstring?" xstring? 0 _) - (xstring->string _) - (test-equal-then "text" "hello,\n" _))) - (fork - "paragraph" - _ - (chain-lambda (test-child "xstring" xstring? 1 _) - (xstring->string _) - (test-equal-then "text" "world\n" _)))) + (test-child-string "xstring?" 0 "hello,\n" _))) + (test-child-string "paragraph" 1 "world\n" _)) (with-test-chain "one element interrupted with empty line" (test-parse->document "* hello,") (test-parse->document "" _) (test-parse->document "world" _) - (test-node-list "document children" 2 _) + (test-node-list "document children" 3 _) (fork "list item" _ (chain-lambda (test-child "list item" unordered-list-item? 0 _) (test-node-list "items" 1 _) - (test-child "xstring?" xstring? 0 _) - (xstring->string _) - (test-equal-then "text" "hello,\n" _))) - (fork - "paragraph" - _ - (chain-lambda (test-child "xstring" xstring? 1 _) - (xstring->string _) - (test-equal-then "text" "world\n" _)))) + (test-child-string "xstring?" 0 "hello,\n" _))) + (test-paragraph-break "break" 1 _) + (test-child-string "paragraph" 2 "world\n" _)) (with-test-chain "multiple list elements" (test-parse->document "* h") (test-parse->document " el" _) @@ -516,17 +368,13 @@ _ (chain-lambda (test-child "list item" unordered-list-item? 0 _) (test-node-list "items" 1 _) - (test-child "xstring?" xstring? 0 _) - (xstring->string _) - (test-equal-then "text" "h\nel\n" _))) + (test-child-string "xstring?" 0 "h\nel\n" _))) (fork "second list item" _ (chain-lambda (test-child "list item" unordered-list-item? 1 _) (test-node-list "items" 1 _) - (test-child "xstring?" xstring? 0 _) - (xstring->string _) - (test-equal-then "text" "lo\n" _)))) + (test-child-string "xstring?" 0 "lo\n" _)))) (with-test-chain "nested list elements" (test-parse->document "* hello") (test-parse->document " * world" _) @@ -537,35 +385,17 @@ (test-node-list "document children" 1 _) (test-child "list item" unordered-list-item? 0 _) (test-node-list "main item children" 3 _) - (fork - "first paragraph" - _ - (chain-lambda (test-child "xstring?" xstring? 0 _) - (xstring->string _) - (test-equal-then "text" "hello\n" _))) + (test-child-string "first" 0 "hello\n" _) (fork "nested list item" _ (chain-lambda (test-child "list item" unordered-list-item? 1 _) - (test-node-list "children" 2 _) - (fork - "first paragraph" - _ - (chain-lambda (test-child "xstring?" xstring? 0 _) - (xstring->string _) - (test-equal-then "text" "world\n" _))) - (fork - "second paragraph" - _ - (chain-lambda (test-child "xstring?" xstring? 1 _) - (xstring->string _) - (test-equal-then "text" "foo\n" _))))) - (fork - "paragraph" - _ - (chain-lambda (test-child "xstring?" xstring? 2 _) - (xstring->string _) - (test-equal-then "text" "bar\n" _))))) + (test-node-list "children" 4 _) + (test-child-string "first" 0 "world\n" _) + (test-paragraph-break "break 1" 1 _) + (test-paragraph-break "break 2" 2 _) + (test-child-string "first" 3 "foo\n" _))) + (test-child-string "paragraph" 2 "bar\n" _))) (test-group "thematic breaks" (define (test-single-thematic-break name data) @@ -579,20 +409,12 @@ (test-node-list "document-children" 1 _) (test-child "code block" code-block? 0 _) (test-node-list "block list" 1 _) - (test-child "xstring?" xstring? 0 _) - (xstring->string _) - (test-equal-then "text" - (string-append data "\n") - _))) + (test-child-string "xstring?" 0 (string-append data "\n") _))) (define (test-as-paragraph name data) (with-test-chain name (test-parse->document data) (test-node-list "document children" 1 _) - (test-child "xstring?" xstring? 0 _) - (xstring->string _) - (test-equal-then "text" - (string-append data "\n") - _))) + (test-child-string "xstring?" 0 (string-append data "\n") _))) (test-single-thematic-break "***" "***") (test-single-thematic-break " ***" " ***") (test-single-thematic-break " ***" " ***") @@ -634,9 +456,7 @@ _ (chain-lambda (test-child "unordered list?" unordered-list-item? 0 _) (test-node-list "children" 1 _) - (test-child "xstring?" xstring? 0 _) - (xstring->string _) - (test-equal-then "text" "hello\n" _))) + (test-child-string "xstring?" 0 "hello\n"))) (fork "thematic break" _ @@ -645,28 +465,15 @@ "third list item" _ (chain-lambda (test-child "unordered list?" unordered-list-item? 2 _) - (test-node-list "children" 1 _) - (test-child "xstring?" xstring? 0 _) - (xstring->string _) - (test-equal-then "text" "world\n" _)))) + (test-node-list "children" 1 "world\n" _)))) (with-test-chain "interrupt paragraph" (test-parse->document "hello") (test-parse->document "***" _) (test-parse->document "world" _) (test-node-list "document children" 3 _) - (fork - "hello" - _ - (chain-lambda (test-child "xstring?" xstring? 0 _) - (xstring->string _) - (test-equal-then "text" "hello\n" _))) + (test-child-string "string" 0 "hello\n" _) (fork "break" _ (chain-lambda (test-child "thematic break" thematic-break? 1 _))) - (fork - "world" - _ - (chain-lambda (test-child "xstring?" xstring? 2 _) - (xstring->string _) - (test-equal-then "text" "world\n" _))))) + (test-child-string "string" 2 "world\n" _))) |
