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

DecodeTest.pudu

Pudu32 lines2.1 KB

GitHub ↗
1/** @Test.Domain.Reference.DecodeTest.Suite — compiler reference output decoding */2module PuduLangMcp.Domain.Reference.DecodeTest34import Std.Io as Io5import Std.Test as Test6import PuduLangMcp.Domain.Reference.Decode as Decode7import PuduLangMcp.Domain.Reference.Entry as Entry89/// Runs the suite.10fn main() -> Int {11  let api = "\{\"version\":\"0.1.1\",\"exports\":[\{\"module\":\"Std.Io\",\"name\":\"read\"\}]\}"12  let doc = "\{\"entries\":[\{\"name\":\"read\",\"kind\":\"fn\",\"module\":\"Std.Io\",\"signature\":\"Str -> Result[Str, Str]\",\"doc\":[\"A file's text.\",\"Second line.\"]\},\{\"name\":\"helper\",\"kind\":\"fn\",\"module\":\"Std.Io\",\"signature\":\"Int\",\"doc\":[]\},\{\"name\":\"read\",\"kind\":\"fn\",\"module\":\"Std.Io\",\"signature\":\"Str -> Result[Str, Str]\",\"doc\":[\"A file's text.\",\"Second line.\"]\}]\}"13  let exports = match Decode.exportsOf(api) { case Ok(names) => names case Err(_) => setOf([]) }14  let entries = match Decode.entriesOf(doc, &exports) { case Ok(found) => found case Err(_) => [] }15  let checks = Test.suite("Domain.Reference.Decode", &[16      Test.that("exports are qualified names", exports.contains("Std.Io.read")),17      Test.equals("only exported declarations are kept, each once", &entries.length(), &1),18      Test.equals("documentation lines are joined", &entries.map(|held: Entry.Entry| held.doc), &["A file's text.\nSecond line."]),19      Test.equals("the signature is kept", &entries.map(|held: Entry.Entry| held.signature), &["Str -> Result[Str, Str]"]),20      Test.errored("api output that is not JSON is refused", &Decode.exportsOf("not json")),21      Test.errored("api output without exports is refused", &Decode.exportsOf("\{\}")),22      Test.errored("doc output that is not JSON is refused", &Decode.entriesOf("\{\"entries\":[", &exports)),23      Test.errored("doc output without entries is refused", &Decode.entriesOf("\{\"other\":1\}", &exports)),24      Test.equals("nothing exported keeps nothing", &match Decode.entriesOf(doc, &setOf([])) { case Ok(found) => found.length() case Err(_) => -1 }, &0)25    ])26  let ran = Test.run(&checks)27  for failure in Test.failuresOf(&ran) {28    let _reported = Io.writeErrorLine(failure)29  }30  Test.report(&ran)31}32