blob: 2340dc0ceb4f0dd5b2d3ae035d2c77ce3cd3bbb2 (
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
127
128
129
130
131
132
133
|
;;; Exercise Gemtext reader. -*- Scheme -*-
;;;
;;; Copyright © 2022 Arun Isaac <arunisaac@systemreboot.net>
;;;
;;;
;;; This file is part of Skribilo.
;;;
;;; Skribilo is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation, either version 3 of the License, or
;;; (at your option) any later version.
;;;
;;; Skribilo is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with Skribilo. If not, see <http://www.gnu.org/licenses/>.
(define-module (tests gemtext)
#:use-module (srfi srfi-64)
#:use-module (ice-9 match)
#:use-module (skribilo reader))
(define make-gemtext-reader
(reader:make (lookup-reader 'gemtext)))
(define-syntax-rule (match? exp pattern)
(match exp
(pattern #t)
(_ #f)))
(test-begin "gemtext")
(test-assert "basic gemtext document"
(match? (call-with-input-string "# Heading
* Mercury
* Gemini
* Apollo
## Subheading
### Subsubheading
> I contend that text-based websites should not exceed in size the major works of Russian literature.
# Links
=>https://example.com A cool website
=>gopher://example.com An even cooler gopherhole
=> gemini://example.com A supremely cool Gemini capsule
=> sftp://example.com
```
This is a preformatted block.
```
```alt
This is a preformatted block with \"alt text\".
```"
(make-gemtext-reader))
`(document
(section #:title "Heading" #:number #f
(itemize (item "Mercury")
(item "Gemini")
(item "Apollo"))
(subsection #:title "Subheading" #:number #f
(subsubsection #:title "Subsubheading" #:number #f
(blockquote "> I contend that text-based websites should not exceed in size the major works of Russian literature."))))
(section #:title "Links" #:number #f
(itemize (item (ref #:url "https://example.com" #:text "A cool website"))
(item (ref #:url "gopher://example.com" #:text "An even cooler gopherhole"))
(item (ref #:url "gemini://example.com" #:text "A supremely cool Gemini capsule"))
(item (ref #:url "sftp://example.com")))
(pre "This is a preformatted block.\n")
(pre "This is a preformatted block with \"alt text\".\n")))))
(test-assert "do not join short lines into paragraph"
(match? (call-with-input-string "Foo
Bar"
(make-gemtext-reader))
`(document
(paragraph "Foo")
(paragraph "Bar"))))
(test-assert "join short lines into paragraphs"
(match? (call-with-input-string "Foo
Bar"
(make-gemtext-reader #:join-lines? #t))
`(document
(paragraph "Foo Bar"))))
(test-assert "do not number sections"
(match? (call-with-input-string "# Foo
## Bar"
(make-gemtext-reader))
`(document
(section #:title "Foo" #:number #f
(subsection #:title "Bar" #:number #f)))))
(test-assert "number sections"
(match? (call-with-input-string "# Foo
## Bar"
(make-gemtext-reader #:section-numbers? #t))
`(document
(section #:title "Foo" #:number #t
(subsection #:title "Bar" #:number #t)))))
(test-assert "break up links separated by blank lines into separate lists"
(match? (call-with-input-string "=>https://example.com A cool website
=>gopher://example.com An even cooler gopherhole
=> gemini://example.com A supremely cool Gemini capsule
=> sftp://example.com"
(make-gemtext-reader))
`(document
(itemize (item (ref #:url "https://example.com" #:text "A cool website"))
(item (ref #:url "gopher://example.com" #:text "An even cooler gopherhole")))
(itemize (item (ref #:url "gemini://example.com" #:text "A supremely cool Gemini capsule"))
(item (ref #:url "sftp://example.com"))))))
(test-assert "ignore blank lines that have a non-zero number of whitespace characters"
(match? (call-with-input-string "Foo
Bar"
(make-gemtext-reader))
`(document
(paragraph "Foo")
(paragraph "Bar"))))
(test-end "gemtext")
|