summaryrefslogtreecommitdiffhomepage
path: root/org/gleam-test.org
diff options
context:
space:
mode:
authorRalph Amissah <ralph.amissah@gmail.com>2026-10-01 17:23:00 -0400
committerRalph Amissah <ralph.amissah@gmail.com>2026-10-01 17:26:10 -0400
commit987828d4fd07cb390d6c61e91cd29bec79d444eb (patch)
tree67b008c99d20a43e59798c4923f4659c8aa6d57c /org/gleam-test.org
parentREADME: the reader, in each language, and what writing it found (diff)
gleam sisudoc-ocda-libclaude-org
Diffstat (limited to 'org/gleam-test.org')
-rw-r--r--org/gleam-test.org209
1 files changed, 209 insertions, 0 deletions
diff --git a/org/gleam-test.org b/org/gleam-test.org
new file mode 100644
index 0000000..402c6e0
--- /dev/null
+++ b/org/gleam-test.org
@@ -0,0 +1,209 @@
+-*- mode: org -*-
+#+TITLE: gleam lib
+#+DESCRIPTION: gleam lib
+#+FILETAGS: :spine:build:tools:
+#+AUTHOR: Ralph Amissah
+#+EMAIL: [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]]
+#+COPYRIGHT: Copyright (C) 2015 (continuously updated, current 2026) Ralph Amissah
+#+LANGUAGE: en
+#+STARTUP: content hideblocks hidestars noindent entitiespretty
+#+PROPERTY: header-args+ :eval never-export :exports code
+#+PROPERTY: header-args+ :noweb yes :padline no
+#+PROPERTY: header-args+ :results silent :cache no
+#+PROPERTY: header-args+ :mkdirp yes
+#+OPTIONS: H:3 num:nil toc:t \n:t ::t |:t ^:nil -:t f:t *:t
+- magic single double-quote → " ← FIX changes hilighting behavior (occuring
+ after it) in org document. INVESTIGATE (org-mode CONFIG?) FIND & FIX
+
+* gleam :gleam:
+** gleam
+*** tangle
+
+#+HEADER: :tangle ../gleam/test/ocda_lib_test.gleam
+#+HEADER: :noweb yes
+#+BEGIN_SRC org
+////<<doc_header_including_copyright_and_license>>
+<<test>>
+#+END_SRC
+
+*** gleam source
+
+#+NAME: test
+#+HEADER: :no-expand
+#+BEGIN_SRC gleam
+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, <<0x28, 0xB5, 0x2F, 0xFD, 0>>)
+ 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
+}
+#+END_SRC
+
+* org includes
+** project version
+
+#+NAME: spine_version
+#+HEADER: :noweb yes
+#+BEGIN_SRC emacs-lisp
+<<./sisudoc_spine_version_info_and_doc_header_including_copyright_and_license.org:spine_project_version()>>
+#+END_SRC
+
+** year
+
+#+NAME: year
+#+HEADER: :noweb yes
+#+BEGIN_SRC emacs-lisp
+<<./sisudoc_spine_version_info_and_doc_header_including_copyright_and_license.org:year()>>
+#+END_SRC
+
+** document header including copyright & license
+
+#+NAME: doc_header_including_copyright_and_license
+#+HEADER: :noweb yes
+#+BEGIN_SRC emacs-lisp
+<<./sisudoc_spine_version_info_and_doc_header_including_copyright_and_license.org:spine_doc_header_including_copyright_and_license()>>
+#+END_SRC
+
+* __END__