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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
/////+
////- Name: SisuDoc Spine, Doc Reform [a part of]
//// - Description: documents, structuring, processing, publishing, search
//// - static content generator
////
//// - Author: Ralph Amissah
//// [ralph.amissah@gmail.com]
////
//// - Copyright: (C) 2015 (continuously updated, current 2026) Ralph Amissah, All Rights Reserved.
////
//// - License: AGPL 3 or later:
////
//// Spine (SiSU), a framework for document structuring, publishing and
//// search
////
//// Copyright (C) Ralph Amissah
////
//// This program is free software: you can redistribute it and/or modify it
//// under the terms of the GNU AFERO General Public License as published by the
//// Free Software Foundation, either version 3 of the License, or (at your
//// option) any later version.
////
//// This program 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
//// this program. If not, see [https://www.gnu.org/licenses/].
////
//// If you have Internet connection, the latest version of the AGPL should be
//// available at these locations:
//// [https://www.fsf.org/licensing/licenses/agpl.html]
//// [https://www.gnu.org/licenses/agpl.html]
////
//// - Spine (by Doc Reform, related to SiSU) uses standard:
//// - docReform markup syntax
//// - standard SiSU markup syntax with modified headers and minor modifications
//// - docReform object numbering
//// - standard SiSU object citation numbering & system
////
//// - Homepages:
//// [https://www.sisudoc.org]
//// [https://www.doc-reform.org]
////
//// - Git
//// [https://git.sisudoc.org/]
////
////+/
import gleam/dict
import gleam/list
import simplifile
import gleam/string
import gleeunit
import gleeunit/should
import ocda/dump
import ocda/load
import ocda/load_ssp
import ocda/model
pub fn main() {
gleeunit.main()
}
const minimal = "% SiSU Document Abstraction v2.0
% Source: example.sst
@source {
language: en
languages: en
digest: ABC
}
@meta {
title.main: An Example
}
@body {
[1] heading :A the_title
.part: frontmatter
.sha256: DEAD
| An Example
[2] para
.part: body
.parent: 1
| First line
|
| Third line, after a blank one
}
"
pub fn version_test() {
let doc = load_ssp.parse(minimal)
doc.format_version |> should.equal("2.0")
model.version_major(doc) |> should.equal("2")
doc.source_filename |> should.equal("example.sst")
}
pub fn preamble_test() {
let doc = load_ssp.parse(minimal)
model.meta(doc, "title.main") |> should.equal("An Example")
}
pub fn objects_test() {
let doc = load_ssp.parse(minimal)
let body = model.section(doc, "body")
body |> list.length |> should.equal(2)
}
/// The blank line in the middle of an object's text is kept, and so is the
/// count: three lines, not two.
pub fn blank_text_line_test() {
let doc = load_ssp.parse(minimal)
case model.section(doc, "body") {
[_, second] ->
second.text
|> should.equal("First line\n\nThird line, after a blank one")
_ -> should.fail()
}
}
/// A heading's identifier comes from its declaration line; an object whose
/// identifier is simply its ocn has it derived, because the text form does
/// not write what it can work out.
pub fn derived_identifier_test() {
let doc = load_ssp.parse(minimal)
case model.section(doc, "body") {
[first, second] -> {
first.identifier |> should.equal("the_title")
second.identifier |> should.equal("2")
}
_ -> should.fail()
}
}
pub fn source_of_test() {
load.source_of("a/b.ssp") |> should.equal(load.Ssp)
load.source_of("a/b.ocda.db") |> should.equal(load.OcdaDb)
load.source_of("a/b.sst") |> should.equal(load.Unknown)
}
/// The dump omits a field at its default, so a minimal document gives a
/// short dump and every line in it is a fact.
pub fn dump_test() {
let text = dump.document(load_ssp.parse(minimal))
text |> string.contains(contain: "version 2.0") |> should.be_true
text |> string.contains(contain: "meta title.main An Example") |> should.be_true
text |> string.contains(contain: "object body 0") |> should.be_true
text |> string.contains(contain: "level A") |> should.be_true
// a false boolean is not written at all
text |> string.contains(contain: "bullet") |> should.be_false
}
/// A property is read, which the fixture above had to be corrected to show:
/// a property line is `.name: value` at the start of the line, and an
/// indented one is a line of no known shape. The fixture indented them, so
/// every property in it was being counted as malformed and the tests around
/// it passed for the wrong reason.
pub fn property_test() {
let doc = load_ssp.parse(minimal)
case model.section(doc, "body") {
[first, second] -> {
first.part |> should.equal("frontmatter")
first.sha256 |> should.equal("DEAD")
second.parent_ocn |> should.equal(1)
}
_ -> should.fail()
}
// and nothing in the fixture is malformed any more
dict_size(doc.unknown.line) |> should.equal(0)
}
@external(erlang, "maps", "size")
fn dict_size(d: dict.Dict(a, b)) -> Int
/// What a path is, including the two archive forms.
pub fn pod_source_test() {
load.source_of("a/b.sisupod") |> should.equal(load.Pod)
load.source_of("a/b.zip") |> should.equal(load.Pod)
}
/// A zstd-wrapped archive is refused, and the refusal says why rather than
/// claiming the file is malformed. This is the one place the D and Gleam
/// libraries differ in what they accept, and it is a packaging limit: the
/// only zstd on the BEAM is a NIF that fetches zstd in its own build.
pub fn zstd_refusal_test() {
let path = "test/fixture-zstd-frame.sisupod"
let assert Ok(_) = simplifile.write_bits(path, )
let assert Error(message) = load.load(path, "", False)
message |> string.contains(contain: "zstd") |> should.be_true
message |> string.contains(contain: "zstd -d") |> should.be_true
let _ = simplifile.delete(path)
Nil
}
|