blob: cd5acbafac88bf3f479b57acaa7a471504f35516 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
(import scheme
(chicken base)
(chicken load)
(chicken pathname)
(chicken port)
(chicken process-context)
test)
(define test-dir (or (get-environment-variable "TESTS")
"tests"))
;;; Setup
(import (jimmy emit)
(jimmy read)
#;(jimmy wrap))
(test-begin)
;;; Reading
(define test-file (make-pathname (list test-dir) "test" "gmi"))
(define expected-doc
'(((meta) ("title" "a" "test" "document")
("date" "2024-05-13T03:02:45Z")
("uuid" "b3daebf1-440b-4828-a4d9-9089c7bd7c61"))
((hdr1) ("a" "test" "document" "of" "some" "kind"))
((para) ("here" "is" "a" "test" "document.")
("it" "has" "paragraphs")
(link "example.com" "with" "links!")
("and" "other" "things."))
((hdr2) ("a" "code" "example"))
((verb) ("for (a=1;a<=4;a++) {") ("\tprintf(\"%d\\n\", a);") ("}"))
((hdr3) ("other" "examples"))
((quot) ("a" "blockquote" "is" "a" "quote") ("that" "is" "blocky."))
((list) ("list" "1") ("list" "2") ("list" "3"))
((link) ("example.com" "link" "list" "1")
("example.com" "link" "list" "2")
("example.com" "link" "list" "3"))
((para) ("ok," "now" "for" "another" "test:")
("will" "*strong*" "in-line" "text" "be" "converted?")
("as" "well" "as" "`code`," "_emph_" "and" "such?")
("what" "if" "*i" "_nest_" "them*")
("what" "if" "*i" "_nest" "them*" "wrong_" "?")
("what" "about" "*breaking" "them")
("over" "two" "lines?*"))))
(define actual-doc (with-input-from-file test-file parse))
(test "read" expected-doc actual-doc)
(define doc expected-doc)
;;; Emitting
(test-group "gemini"
(define expected-gmi
(string-append "# a test document of some kind\n\n"
"here is a test document. it has paragraphs \n"
"=> example.com with links!\n"
"and other things.\n\n"
"## a code example\n\n"
"```\nfor (a=1;a<=4;a++) {\n"
"\tprintf(\"%d\\n\", a);"
"\n}\n```\n\n"
"### other examples\n\n"
"> a blockquote is a quote that is blocky.\n\n"
"* list 1\n"
"* list 2\n"
"* list 3\n\n"
"=> example.com link list 1\n"
"=> example.com link list 2\n"
"=> example.com link list 3\n\n"
"ok, now for another test: "
"will *strong* in-line text be converted? "
"as well as `code`, _emph_ and such? "
"what if *i _nest_ them* what if *i _nest them* wrong_ ? "
"what about *breaking them over two lines?*\n\n"))
(define actual-gmi (with-output-to-string (lambda () (emit doc))))
(test "emit" expected-gmi actual-gmi))
;;; HTML
(test-group "html"
(import (jimmy html))
(define expected-html
(string-append "<h1>a test document of some kind</h1>\n"
"<p>\n"
" here is a test document.\n"
" it has paragraphs\n"
" <a href=\"example.com\">with links!</a>\n"
" and other things.\n"
"</p>\n"
"<h2>a code example</h2>\n"
"<pre><code>for (a=1;a<=4;a++) {\n"
"\tprintf(\"%d\\n\", a);\n"
"}\n"
"</code></pre>\n"
"<h3>other examples</h3>\n"
"<blockquote>\n"
" a blockquote is a quote\n"
" that is blocky.\n"
"</blockquote>\n"
"<ul>\n"
" <li>list 1</li>\n"
" <li>list 2</li>\n"
" <li>list 3</li>\n"
"</ul>\n"
"<ul>\n"
" <li><a href=\"example.com\">link list 1</a></li>\n"
" <li><a href=\"example.com\">link list 2</a></li>\n"
" <li><a href=\"example.com\">link list 3</a></li>\n"
"</ul>\n"
"<p>\n"
" ok, now for another test:\n"
" will <b>strong</b> in-line text be converted?\n"
" as well as <code>code</code>, <i>emph</i> and such?\n"
" what if <b>i <i>nest</i> them</b>\n"
" what if <b>i <i>nest them</b> wrong</i> ?\n"
" what about *breaking them\n"
" over two lines?*\n"
"</p>\n"))
(define actual-html (with-output-to-string (lambda () (emit doc))))
(test "emit html" expected-html actual-html))
(test-end)
(test-exit)
|