Pudu programming language
Menu
Package

@chrismichaelps / pudu-lang-mcp

Model Context Protocol server for Pudu language documentation and compiler tools

0.1.1Apache-2.01

InstallClose

ChapterTest.pudu

Pudu56 lines3.9 KB

GitHub ↗
1/** @Test.Domain.Docs.ChapterTest.Suite — sectioning, anchors, and the corpus */2module PuduLangMcp.Domain.Docs.ChapterTest34import Std.Io as Io5import Std.List as List6import Std.Option as Option7import Std.Test as Test8import PuduLangMcp.Domain.Docs.Chapter as Chapter9import PuduLangMcp.Generated.Docs as Docs1011/// A document for tests, in the docs group.12fn document(markdown: Str) -> Chapter.Chapter {13  Chapter.Chapter{group: "docs", slug: "sample", title: "Sample", markdown: markdown}14}1516/// Runs the suite.17fn main() -> Int {18  let sample = document("# Sample\n\nIntro text.\n\n## First part\n\nOne.\n\n```pudu\n## not a heading\n```\n\n## Second: part two!\n\nTwo.")19  let sections = Chapter.sectionsOf(&sample)20  let headings = sections.map(|held: Chapter.Section| held.heading)21  let flat = Chapter.sectionsOf(&document("# Sample\n\nOnly text."))22  let noIntro = Chapter.sectionsOf(&document("## Only\n\nText.")).map(|held: Chapter.Section| held.heading)23  let empty = Chapter.sectionsOf(&document("# Sample\n\n## Empty\n## Next\n\nText.")).map(|held: Chapter.Section| held.heading)24  let contents = Chapter.tableOfContents(&[document("# Sample\n\nIntro.\n\n## Part\n\nText.")])25  let groups = List.distinct(&Docs.CHAPTERS.map(|held: Chapter.Chapter| held.group))26  let checks = Test.suite("Domain.Docs.Chapter", &[27      Test.equals("text before the first heading is the introduction", &headings, &["Sample", "First part", "Second: part two!"]),28      Test.that("a heading inside a code fence stays in its section", Option.unwrapOr(List.get(&sections, 1), sections[0]).text.contains("## not a heading")),29      Test.equals("sections carry their document", &sections.map(|held: Chapter.Section| held.chapter), &["sample", "sample", "sample"]),30      Test.equals("a document with no heading is one section", &flat.length(), &1),31      Test.equals("an anchor joins lowercase words with dashes", &Chapter.anchorOf("Second: part two!"), &"second-part-two"),32      Test.equals("an anchor of punctuation alone is empty", &Chapter.anchorOf("?!"), &""),33      Test.equals("a document that starts with a section has no introduction", &noIntro, &["Only"]),34      Test.equals("a heading with no text is still a section", &empty, &["Empty", "Next"]),35      Test.equals("the contents list sections beneath their document only", &contents, &"docs/sample — Sample\n  Part (#part)"),36      Test.equals("an anchor keeps the ends of the letter and digit ranges", &Chapter.anchorOf("a z 0 9 `x\{ /y: @w[ _v"), &"a-z-0-9-x-y-w-v"),37      Test.equals("leading and trailing punctuation leaves no dash", &Chapter.anchorOf("-- Title --"), &"title"),38      Test.equals("digits stay in an anchor", &Chapter.anchorOf("HTTP/2 and TLS 1.3"), &"http-2-and-tls-1-3"),39      Test.present("a section is found by its anchor", &Chapter.sectionIn(&sample, "first-part")),40      Test.present("a section is found by its heading in any case", &Chapter.sectionIn(&sample, "FIRST PART")),41      Test.absent("an unknown section is not found", &Chapter.sectionIn(&sample, "third")),42      Test.present("a document is found by group and slug", &Chapter.find(&Docs.CHAPTERS, "docs", "errors")),43      Test.absent("the right slug in the wrong group is not found", &Chapter.find(&Docs.CHAPTERS, "pages", "errors")),44      Test.equals("the corpus holds every published group", &List.sorted(&groups), &["docs", "examples", "pages", "releases"]),45      Test.equals("the language guide has its chapters", &Chapter.inGroup(&Docs.CHAPTERS, "docs").length(), &24),46      Test.that("every document has a title", Docs.CHAPTERS.filter(|held: Chapter.Chapter| held.title.isEmpty()).isEmpty()),47      Test.that("the contents list every document", Chapter.tableOfContents(&Docs.CHAPTERS).contains("releases/0.1.1")),48      Test.that("the corpus keeps literal braces", Option.unwrapOr(Chapter.find(&Docs.CHAPTERS, "docs", "text"), sample).markdown.contains("\{"))49    ])50  let ran = Test.run(&checks)51  for failure in Test.failuresOf(&ran) {52    let _reported = Io.writeErrorLine(failure)53  }54  Test.report(&ran)55}56