/////+ ////- 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 }